DIY可视化实现仿抖音短视频代码生成器

这篇文章介绍了如何使用DIY工具创建一个兼容uniapp和微信小程序的高性能短视频展示器,具有丝滑切换、无限数据加载和流畅滑动功能,同时支持在线定制界面和API请求。
摘要由CSDN通过智能技术生成

DIY可视化实现仿抖音短视频代码生成器,仿抖音短视频兼容uniapp、微信小程序 丝滑切换视频效果,无限数据加载不卡顿,高性能滑动不卡顿超流畅,观看视频丝滑切换,页面内容自定义,无限数据加载不卡顿。

在线设计请求远程数据源,绑定数据源、视频源、标题等。所有界面上的元素都支持在线自定义。

在线请求API

<template>
	<view class="container container21094">
		<view class="flex diygw-col-24">
			<swiper :current="swipersIndex" @animationfinish="playVideoFunction" class="swiper" @change="changeSwipers" indicator-color="rgba(51, 51, 51, 0.39)" indicator-active-color="rgba(64, 64, 64, 0.93)" interval="3000" vertical="true" circular="true" style="height: 100vh">
				<swiper-item v-for="(item, index) in datas.rows" :key="index" class="diygw-swiper-item">
					<view class="diygw-swiper-item-wrap">
						<view class="flex diygw-col-24">
							<video ref="refVideo" :id="'video' + index" :controls="false" :show-center-play-btn="true" :show-play-btn="false" :show-fullscreen-btn="false" :src="item.src" style="width: 100%; height: 100vh" object-fit="contain" :title="item.title" poster=""></video>
						</view>
						<view class="flex flex-wrap diygw-col-24 flex-direction-column flex-clz">
							<view class="diygw-col-24 text-clz">
								{{ item.title }}
							</view>
							<view class="diygw-col-24">
								{{ item.remark }}
							</view>
						</view>
						<view class="flex flex-wrap diygw-col-0 flex-direction-column flex1-clz">
							<view class="flex flex-wrap diygw-col-24 flex-direction-column items-center flex2-clz">
								<image :src="item.avatar" class="image8-size diygw-image diygw-col-0 image8-clz" mode="widthFix"></image>
							</view>
							<view class="flex flex-wrap diygw-col-24 flex-direction-column items-center flex5-clz" @tap="navigateTo" data-type="tip" data-tip="触发收藏">
								<text class="flex icon3 diygw-col-0 diy-icon-star"></text>
								<view class="diygw-col-0">
									{{ item.star }}
								</view>
							</view>
							<view class="flex flex-wrap diygw-col-24 flex-direction-column items-center flex3-clz" @tap="navigateTo" data-type="tip" data-tip="触发消息">
								<text class="flex icon1 diygw-col-0 diy-icon-message"></text>
								<view class="diygw-col-0">
									{{ item.comment }}
								</view>
							</view>
							<view class="flex flex-wrap diygw-col-24 flex-direction-column items-center flex4-clz" @tap="navigateTo" data-type="tip" data-tip="触发分享">
								<text class="flex icon2 diygw-col-0 diy-icon-share"></text>
								<view class="diygw-col-0">
									{{ item.share }}
								</view>
							</view>
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="clearfix"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//用户全局信息
				userInfo: {},
				//页面传参
				globalOption: {},
				//自定义全局变量
				globalData: {},
				datas: {
					code: 0,
					msg: '',
					rows: [
						{
							title: '',
							remark: '',
							share: '',
							comment: '',
							star: '',
							src: '',
							avatar: ''
						}
					]
				},
				showVideo: false,
				swipersIndex: 0
			};
		},
		onShow() {
			this.setCurrentPage(this);
		},
		onLoad(option) {
			this.setCurrentPage(this);
			if (option) {
				this.setData({
					globalOption: this.getOption(option)
				});
			}

			this.init();
		},
		methods: {
			async init() {
				await this.datasApi();
			},
			// 获取视频接口 API请求方法
			async datasApi(param) {
				let thiz = this;
				param = param || {};

				//请求地址及请求数据,可以在加载前执行上面增加自己的代码逻辑
				let http_url = 'https://php.diygw.com/video.php';
				let http_data = {};
				let http_header = {};

				let datas = await this.$http.post(http_url, http_data, http_header, 'json');

				this.datas = datas;
				this.showVideo = true;
				this.$nextTick(() => {
					this.playVideoFunction({});
				});
			},

			// 播放视频 自定义方法
			async playVideoFunction(param) {
				let thiz = this;
				let swipersIndex = this.swipersIndex;
				if (param.detail) {
					swipersIndex = param.detail.current;
				}
				let currentId = 'video' + swipersIndex; // 获取当前视频id
				this.videoContent = uni.createVideoContext(currentId, thiz).play();
				// 获取视频列表
				let rows = this.datas.rows;
				rows.forEach((item, index) => {
					// 获取json对象并遍历, 停止非当前视频
					if (item.src != null && item.src != '') {
						let temp = 'video' + index;
						if (temp != currentId) {
							// 暂停其余视频
							uni.createVideoContext(temp, thiz).pause(); //暂停视频播放事件
						}
					}
				});
			},
			changeSwipers(evt) {
				let swipersIndex = evt.detail.current;
				this.setData({ swipersIndex });
			}
		}
	};
</script>

<style lang="scss" scoped>
	.flex-clz {
		padding-top: 20rpx;
		color: #ffffff;
		left: 0rpx;
		bottom: 0rpx;
		padding-left: 20rpx;
		padding-bottom: 20rpx;
		position: absolute;
		padding-right: 20rpx;
	}
	.text-clz {
		font-weight: bold;
		font-size: 28rpx !important;
	}
	.flex1-clz {
		padding-top: 20rpx;
		color: #ffffff;
		bottom: 200rpx;
		padding-left: 20rpx;
		padding-bottom: 20rpx;
		position: absolute;
		right: 0rpx;
		padding-right: 20rpx;
	}
	.flex2-clz {
		margin-left: 10rpx;
		width: calc(100% - 10rpx - 10rpx) !important;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-right: 10rpx;
	}
	.image8-clz {
		border-bottom-left-radius: 120rpx;
		overflow: hidden;
		border-top-left-radius: 120rpx;
		border-top-right-radius: 120rpx;
		border-bottom-right-radius: 120rpx;
	}
	.image8-size {
		height: 96rpx !important;
		width: 96rpx !important;
	}
	.flex5-clz {
		margin-left: 10rpx;
		width: calc(100% - 10rpx - 10rpx) !important;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-right: 10rpx;
	}
	.icon3 {
		font-size: 56rpx;
	}
	.flex3-clz {
		margin-left: 10rpx;
		width: calc(100% - 10rpx - 10rpx) !important;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-right: 10rpx;
	}
	.icon1 {
		font-size: 56rpx;
	}
	.flex4-clz {
		margin-left: 10rpx;
		width: calc(100% - 10rpx - 10rpx) !important;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-right: 10rpx;
	}
	.icon2 {
		font-size: 56rpx;
	}
	.container21094 {
		padding-left: 0px;
		padding-right: 0px;
		background-color: #000000;
	}
</style>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值