Commit 78d18fac authored by ziyu's avatar ziyu

feat: 解决视频懒加载

parent b86b4ff9
......@@ -16,8 +16,21 @@ function getClass (status) {
console.log(status)
return cls[index]
};
function showVideo(item,current,index,loadMedia) {
if(item.showType && item.showType.value ==2) {
if(loadMedia.indexOf(index) !== -1) {
return true
}
if(current === index) {
loadMedia.push(index);
return true
} else {
return false;
}
}
}
module.exports = {
computClass:computClass,
getClass:getClass
getClass:getClass,
showVideo:showVideo
}
import wepy from '@wepy/core';
import Notify from '../components/vant/notify/notify';
const env = 'test'; // 每次上线手动切换成 prod/test
const env = 'prod'; // 每次上线手动切换成 prod/test
let baseUrl = 'https://api-luckii.q-gp.com';
if (env === 'test') {
baseUrl = 'https://luckii-qa.liangkebang.net';
......
......@@ -65,6 +65,7 @@
width: 100%;
}
</style>
<wxs module="video" src="../../common/common.wxs"></wxs>
<template>
<view class="container">
<swiper
......@@ -74,6 +75,7 @@
vertical
current="0"
bindanimationfinish="bindanimationfinish"
bindchange="moveSwiper"
>
<swiper-item :class="{'image-item': item.showType && item.showType.value === 1}" v-for="(item, idx) in curQueue" :key="item.id">
<view class="video-wrapper">
......@@ -84,19 +86,20 @@
show-center-play-btn="{{false}}"
enable-progress-gesture="{{false}}"
controls="{{false}}"
src="{{item.videoUrl}}"
src="{{video.showVideo(item,currentIndex,idx,loadMedia)?item.videoUrl:null}}"
data-id="{{item.id}}"
object-fit="{{item.objectFit || 'contain'}}"
data-index="{{idx}}"
binderror="onError"
bindtimeupdate="onTimeUpdate"
@tap="videoTap"
v-if="item.showType && item.showType.value === 2"
custom-cache="{{false}}"
object-fit="contain"
wx:if="{{item.showType && item.showType.value ==2}}"
>
<video-loading v-if="item.time === 0" :snapshot="item.videoSnapUrl"/>
<video-pause :pause="pause"></video-pause>
</video>
<image v-if="item.showType && item.showType.value === 1" lazy-load class="images" :src="item.photoUrl" mode="widthFix" bindload="imageLoad(item.id)">
<image wx:if="{{item.showType && item.showType.value ==1}}" lazy-load class="images" :src="item.photoUrl" mode="widthFix" bindload="imageLoad(item.id)">
<image-loading v-if="item.time === 0"/>
</image>
<view class="rightcont" v-show="item.id > 0">
......@@ -131,6 +134,8 @@
data: {
pause: false,
curQueue: [],
currentIndex:0,
loadMedia:[],
},
watch: {
videoList () {
......@@ -154,6 +159,12 @@
this.curQueue = [...this.curQueue];
this.updateAwardsInfo(videoCurrent);
},
moveSwiper(e) {
if (e.$wx.detail.source === 'touch') {
let current = e.$wx.detail.current;
this.currentIndex = current;
}
},
async getProgress(id) {
if (id <= 0) return;
let detail = await getAwardsDetail({ prizeId: id });
......@@ -222,6 +233,9 @@
if (index !== current) {
ctx && ctx.pause();
} else {
this.loadMedia.push(index);
//将视频重置到最开始的位置并播放
ctx && ctx.seek(0);
ctx && ctx.play();
}
});
......
......@@ -57,7 +57,6 @@
share: '/static/images/share@2x.png',
lottery: '/static/images/lottery@2x.png'
};
let isFirst = true;
let addGoldTimer = null;
wepy.component({
store,
......@@ -74,6 +73,7 @@
lotteryUrl: '/static/images/lottery@2x.png',
containerStyle: '',
flyAnimation: false,
isFirst:true,
},
props: {
title: '',
......@@ -144,8 +144,8 @@
if (v) {
this.addCount = 0;
}
if (isFirst) {
isFirst = false;
if (this.isFirst) {
this.isFirst = false;
return;
}
setTimeout(() => {
......@@ -153,11 +153,11 @@
}, 1500);
},
sign(v) {
if (isFirst) {
if (this.isFirst) {
this.signComplete = false;
this.flyAnimation = false;
this.addsunshine = false;
isFirst = false;
this.isFirst = false;
return;
}
if (v) {
......
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