提交 da9ae769 编写于 作者: 雪洛's avatar 雪洛

Revert "fix: 修正不符合vue规范的用法"

This reverts commit a52ecdbb.
上级 a52ecdbb
<template> <template>
<view class="page"> <view class="page">
<view @click="back" class="nav-back"> <view @click="back" class="nav-back">
<image class="back-img" src="/static/template/scroll-fold-nav/back.png" mode="widthFix"></image> <image class="back-img" src="/static/template/scroll-fold-nav/back.png" mode="widthFix"></image>
</view> </view>
<swiper class="swiper" :current="current" :circular="index != 0" :vertical="true" @change="onSwiperChange" @transition="onTransition"> <swiper class="swiper" :current="current" :circular="index != 0" :vertical="true" @change="onSwiperChange" @transition="onTransition">
<swiper-item class="swiper-item" v-for="(item,i) in visibleList" :key="i"> <swiper-item class="swiper-item" v-for="(item,i) in visibleList" :key="i">
<video @click="changeState(i)" ref="video" class="video-box" objectFit="cover" :id="'video-'+i" <video @click="changeState(i)" ref="video" class="video-box" objectFit="cover" :id="'video-'+i"
@loadstart="onLoadstart(i)" :src="item.src" :poster="item.poster_src" @loadstart="onLoadstart(i)" :src="item.src" :poster="item.poster_src"
:autoplay="false" :show-center-play-btn="false" :autoplay="false" :show-center-play-btn="false"
:loop="true" @play="onPlay(i)" @pause="onPause(i)" :loop="true" @play="onPlay(i)" @pause="onPause(i)"
></video> ></video>
<view class="video-cover" @click="changeState(i)"> <view class="video-cover" @click="changeState(i)">
<image v-if="state[i] === 'pause'" class="play-btn" src="/static/template/swiper-vertical-video/play.png" mode="widthFix"></image> <image v-if="state[i] === 'pause'" class="play-btn" src="/static/template/swiper-vertical-video/play.png" mode="widthFix"></image>
</view> </view>
<view class="video-info" v-if="0"> <view class="video-info" v-if="0">
<text class="video-info-text">容器:第 {{i}} 个</text> <text class="video-info-text">容器:第 {{i}} 个</text>
<text class="video-info-text">内容:{{item.content}}</text> <text class="video-info-text">内容:{{item.content}}</text>
</view> </view>
</swiper-item> </swiper-item>
</swiper> </swiper>
<view class="debug-info" v-if="0"> <view class="debug-info" v-if="0">
<text class="status-text">debug-info 播放状态:</text> <text class="status-text">debug-info 播放状态:</text>
<text class="status-text" v-for="(value,index) in state">第{{index+1}}个:{{ value }}</text> <text class="status-text" v-for="(value,index) in state">第{{index+1}}个:{{ value }}</text>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
type ListItem = { _id : string, content : string, src : string, poster_src : string } type ListItem = { _id : string, content : string, src : string, poster_src : string }
let page : number = 0, let page : number = 0,
currentPageIsShow : boolean = true; currentPageIsShow : boolean = true;
export default { export default {
components: {}, components: {},
data() { data() {
return { return {
$videoContextMap:new Map<string, VideoContext>(), $videoContextMap:new Map<string, VideoContext>(),
list: [] as ListItem[], list: [] as ListItem[],
visibleList: [] as ListItem[],// 提高性能 可见的只有3个 visibleList: [] as ListItem[],// 提高性能 可见的只有3个
current: 0 as number, current: 0 as number,
index: 0, index: 0,
state: ["unPlay", "unPlay", "unPlay"] as string[] state: ["unPlay", "unPlay", "unPlay"] as string[]
} }
}, },
created() { beforeCreate() {
this.list = this.getData() this.list = this.getData()
this.visibleList = this.list.slice(0, 3) this.visibleList = this.list.slice(0, 3)
}, },
watch: { watch: {
current(current : number, oldCurrent : number) { current(current : number, oldCurrent : number) {
let changeNumber = current - oldCurrent let changeNumber = current - oldCurrent
if (changeNumber == 1 || changeNumber == -2) { if (changeNumber == 1 || changeNumber == -2) {
// console.error('向右'); // console.error('向右');
this.index++ this.index++
} else { } else {
// console.error('向左'); // console.error('向左');
this.index-- this.index--
} }
// //翻页(3项为一页) // //翻页(3项为一页)
if (Math.abs(changeNumber) == 2) { if (Math.abs(changeNumber) == 2) {
// console.log('翻页'); // console.log('翻页');
page = Math.floor(this.index / 3); page = Math.floor(this.index / 3);
// console.log(this.index); // console.log(this.index);
// console.log('page',page); // console.log('page',page);
// console.log('slice',3*page,3*page+3); // console.log('slice',3*page,3*page+3);
if (this.list.length < 3 * page + 3) { if (this.list.length < 3 * page + 3) {
let list : ListItem[] = this.getData() let list : ListItem[] = this.getData()
this.list.push(...list) this.list.push(...list)
} }
let visibleList = this.list.slice(3 * page, 3 * page + 3) let visibleList = this.list.slice(3 * page, 3 * page + 3)
// 换数据 // 换数据
this.visibleList = visibleList this.visibleList = visibleList
} }
this.state.forEach((val : string, index : number) => { this.state.forEach((val : string, index : number) => {
if (index === current) { if (index === current) {
this.doPlay(current) this.doPlay(current)
} else { } else {
// 除了选中的其他已经播放的都需要停止 // 除了选中的其他已经播放的都需要停止
this.doStop(index) this.doStop(index)
console.log('index:' + index + '已被执行停止'); console.log('index:' + index + '已被执行停止');
} }
}) })
} }
}, },
onReady() { onReady() {
// 一启动完成,就播放第一个 // 一启动完成,就播放第一个
this.doPlay(0) this.doPlay(0)
}, },
onShow(){ onShow(){
...@@ -98,30 +98,30 @@ ...@@ -98,30 +98,30 @@
}, },
onUnload() { onUnload() {
this.doPause(this.current) this.doPause(this.current)
}, },
methods: { methods: {
changeState(index : number) { changeState(index : number) {
if (this.state[index] === 'play') { if (this.state[index] === 'play') {
this.doPause(index) this.doPause(index)
} else { } else {
this.doPlay(this.current) this.doPlay(this.current)
} }
}, },
onLoadstart(index : number) { onLoadstart(index : number) {
console.error("onLoadstart video" + index ); console.error("onLoadstart video" + index );
}, },
getVideoContext(index : number) : VideoContext{ getVideoContext(index : number) : VideoContext{
let videoContext : VideoContext | null = this.$data.$videoContextMap.get('video-'+index) let videoContext : VideoContext | null = this.$videoContextMap.get('video-'+index)
if(videoContext == null){ if(videoContext == null){
videoContext = uni.createVideoContext('video-'+index, this) as VideoContext videoContext = uni.createVideoContext('video-'+index, this) as VideoContext
this.$data.$videoContextMap.set('video-'+index,videoContext) this.$videoContextMap.set('video-'+index,videoContext)
} }
return videoContext return videoContext
}, },
doPlay(index : number) { doPlay(index : number) {
console.log("doPlay video" + index ); console.log("doPlay video" + index );
this.getVideoContext(index).play() this.getVideoContext(index).play()
}, },
doStop(index : number) { doStop(index : number) {
console.log("doStop video-" + index); console.log("doStop video-" + index);
this.getVideoContext(index).stop(); this.getVideoContext(index).stop();
...@@ -133,51 +133,51 @@ ...@@ -133,51 +133,51 @@
doPause(index : number) { doPause(index : number) {
this.getVideoContext(index).pause() this.getVideoContext(index).pause()
console.log("doPause video-" + index); console.log("doPause video-" + index);
}, },
onPause(index : number) { onPause(index : number) {
this.state[index] = 'pause' this.state[index] = 'pause'
console.log('onPause', index); console.log('onPause', index);
}, },
onPlay(index : number) { onPlay(index : number) {
if(this.current != index || !currentPageIsShow){ if(this.current != index || !currentPageIsShow){
this.onPause(index) this.onPause(index)
}else{ }else{
this.state[index] = 'play' this.state[index] = 'play'
console.log('onPlay', index); console.log('onPlay', index);
} }
}, },
getData() : ListItem[] { getData() : ListItem[] {
let videoUrlList = [ let videoUrlList = [
'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/video/swiper-vertical-video/uts.mp4', 'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/video/swiper-vertical-video/uts.mp4',
'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/video/swiper-vertical-video/uni-ai.mp4', 'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/video/swiper-vertical-video/uni-ai.mp4',
'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/video/swiper-vertical-video/uni-verify.mp4' 'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/video/swiper-vertical-video/uni-verify.mp4'
] as string[] ] as string[]
let posterSrcList = [ let posterSrcList = [
'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/images/swiper-vertical-video-poster/uni-uts.jpg', 'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/images/swiper-vertical-video-poster/uni-uts.jpg',
'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/images/swiper-vertical-video-poster/uni-ai.jpg', 'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/images/swiper-vertical-video-poster/uni-ai.jpg',
'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/images/swiper-vertical-video-poster/uni-verify.jpg' 'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/images/swiper-vertical-video-poster/uni-verify.jpg'
] as string[] ] as string[]
let list = [] as ListItem[]; let list = [] as ListItem[];
for (let i = 0; i < 6; i++) { for (let i = 0; i < 6; i++) {
let index = this.list.length + i; let index = this.list.length + i;
let listItem : ListItem = { let listItem : ListItem = {
"_id": "a00" + index, "_id": "a00" + index,
"content": "这是第" + index + "条数据,url地址" + videoUrlList[i % 3], "content": "这是第" + index + "条数据,url地址" + videoUrlList[i % 3],
"src": videoUrlList[i % 3], "src": videoUrlList[i % 3],
"poster_src": posterSrcList[i % 3] "poster_src": posterSrcList[i % 3]
} }
list.push(listItem) list.push(listItem)
} }
return list return list
}, },
onSwiperChange(e : SwiperChangeEvent) { onSwiperChange(e : SwiperChangeEvent) {
// console.error('SwiperChangeEvent',e.detail.current); // console.error('SwiperChangeEvent',e.detail.current);
this.current = e.detail.current; this.current = e.detail.current;
}, },
onTransition(/*e : SwiperTransitionEvent*/) { onTransition(/*e : SwiperTransitionEvent*/) {
// console.log('onTransition e.detail.dx', e.detail.dx); // console.log('onTransition e.detail.dx', e.detail.dx);
}, },
back() { back() {
uni.navigateBack({ uni.navigateBack({
...@@ -191,58 +191,58 @@ ...@@ -191,58 +191,58 @@
console.log('navigateBack complete', result.errMsg) console.log('navigateBack complete', result.errMsg)
} }
}) })
} }
} }
} }
</script> </script>
<style> <style>
.page { .page {
width: 750rpx; width: 750rpx;
flex: 1; flex: 1;
} }
.swiper, .swiper,
.swiper-item, .swiper-item,
.video-box, .video-box,
.video-cover { .video-cover {
width:750rpx; width:750rpx;
flex: 1; flex: 1;
height: 100%; height: 100%;
} }
.swiper-item { .swiper-item {
position: relative; position: relative;
} }
.video-box { .video-box {
width: 750rpx; width: 750rpx;
} }
.video-cover { .video-cover {
position: absolute; position: absolute;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
align-content: center; align-content: center;
} }
.play-btn { .play-btn {
width: 80rpx; width: 80rpx;
height: 80rpx; height: 80rpx;
} }
.video-info { .video-info {
position: absolute; position: absolute;
bottom: 0; bottom: 0;
padding: 15px; padding: 15px;
} }
.video-info-text { .video-info-text {
font-size: 14px; font-size: 14px;
color: red; color: red;
line-height: 20px; line-height: 20px;
} }
.debug-info{ .debug-info{
position: fixed; position: fixed;
top:15px; top:15px;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册