Commit 6e4d57c7 authored by 郭志伟's avatar 郭志伟

perf: video-swiper切换优化

parent 1e47e363
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
<view class="container"> <view class="container">
<swiper <swiper
class="video-swiper" class="video-swiper"
duration="600" duration="300"
circular="{{circular}}" circular="{{circular}}"
vertical vertical
current="1" current="1"
bindchange="moveSwiper" bindchange="moveSwiper">
bindanimationfinish="animationfinish">
<swiper-item wx:for="{{curQueue}}" wx:key="index"> <swiper-item wx:for="{{curQueue}}" wx:key="index">
<view class="video-swiper"> <view class="video-swiper">
<video <video
...@@ -45,13 +44,15 @@ ...@@ -45,13 +44,15 @@
</view> </view>
</swiper-item> </swiper-item>
</swiper> </swiper>
<van-popup show="{{showPopup}}" close-on-click-overlay="{{false}}" overlay-style="background-color:transparent"></van-popup>
</view> </view>
</template> </template>
<script> <script>
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import { getProbability } from '../../common/raffleProbability'; import { getProbability } from '../../common/raffleProbability';
import { getAwardsDetail, getPrizeList } from '../../common/api.js'; import { getAwardsDetail, getPrizeList } from '../../common/api.js';
let playTimer = null;
wepy.component({ wepy.component({
props: { props: {
videoList: { videoList: {
...@@ -77,7 +78,6 @@ ...@@ -77,7 +78,6 @@
_videoContexts: [], _videoContexts: [],
currentIndex: 1, currentIndex: 1,
videoPause: false, videoPause: false,
showPopup: false,
videoLoading: true videoLoading: true
}, },
watch: { watch: {
...@@ -147,11 +147,6 @@ ...@@ -147,11 +147,6 @@
this.videoPause = false; this.videoPause = false;
this.videoLoading = true; this.videoLoading = true;
if (e.$wx.detail.source === 'touch') { if (e.$wx.detail.source === 'touch') {
// 增加一个透明遮罩层,控制用户滑动速度,500ms内只能滑动一次,解决用户滑动过快,不触发animationfinish的bug
this.showPopup = true;
setTimeout(() => {
this.showPopup = false;
}, 500);
const current = e.$wx.detail.current; const current = e.$wx.detail.current;
this.currentIndex = current; this.currentIndex = current;
// 如果next中如果就剩下4个了,请求下一页 // 如果next中如果就剩下4个了,请求下一页
...@@ -160,6 +155,7 @@ ...@@ -160,6 +155,7 @@
this._videoListChanged(data); this._videoListChanged(data);
}); });
} }
this.animationfinish(e);
} }
}, },
animationfinish (e) { animationfinish (e) {
...@@ -221,18 +217,23 @@ ...@@ -221,18 +217,23 @@
this.circular = circular; this.circular = circular;
}, },
playCurrent (current) { playCurrent (current) {
this.curQueue[current] && this.getProgress(this.curQueue[current].id); this.$nextTick(() => {
// 滑动到当前元素时,其他video都暂停,只播放当前video if (playTimer) clearTimeout(500);
this._videoContexts.forEach(function (ctx, index) { playTimer = setTimeout(() => {
if (ctx) { this.curQueue[current] && this.getProgress(this.curQueue[current].id);
if (index !== current) { // 滑动到当前元素时,其他video都暂停,只播放当前video
ctx.pause(); this._videoContexts.forEach(function (ctx, index) {
} else { if (ctx) {
ctx.play(); if (index !== current) {
} ctx.pause();
} } else {
ctx.play();
}
}
});
this.updateAwardsInfo(current);
}, 500);
}); });
this.updateAwardsInfo(current);
}, },
videoTap(e) { videoTap(e) {
const current = e.currentTarget.dataset.index; const current = e.currentTarget.dataset.index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment