Browse Source

优化首页视频播放逻辑

pull/19/head
zyronon 4 years ago
parent
commit
67059981d7
  1. 125
      src/pages/home/Index2.vue
  2. 20
      src/pages/home/SlideListVirtual.vue

125
src/pages/home/Index2.vue

@ -1,20 +1,14 @@
<template> <template>
<div id="home-index"> <div id="home-index">
<SlideListVirtual direction="column" <SlideListVirtual
:virtual="false" ref="slideList"
:list="videos" direction="column"
:renderSlide="render" :virtual="true"
v-model:active-index="videoActiveIndex" :list="videos"
@end="end" :renderSlide="render"
v-model:active-index="videoActiveIndex"
@end="end"
> >
<SlideItem v-for="(item,index) of videos">
<Video1
v-model:video="videos[index]"
@showComments="isCommenting = !isCommenting"
@showShare="isSharing = !isSharing"
@goUserInfo="baseActiveIndex = 1"
></Video1>
</SlideItem>
</SlideListVirtual> </SlideListVirtual>
<Comment v-model:is-commenting="isCommenting"/> <Comment v-model:is-commenting="isCommenting"/>
<Share v-model:is-sharing="isSharing" ref="share"/> <Share v-model:is-sharing="isSharing" ref="share"/>
@ -302,16 +296,17 @@ export default {
}) })
// if (newVal >= this.videos.length - 3) { // if (newVal >= this.videos.length - 3) {
if (false) { if (false) {
[{ [
videoUrl: mp40, {
// videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ', videoUrl: mp40,
videoPoster: src1Bg, // videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ',
isLoved: true, videoPoster: src1Bg,
loves: 1234, isLoved: true,
comments: 666, loves: 1234,
shared: 999, comments: 666,
duration: 99 shared: 999,
}, duration: 99
},
{ {
videoUrl: mp41, videoUrl: mp41,
// videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ', // videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ',
@ -381,49 +376,51 @@ export default {
shared: 999, shared: 999,
duration: 99 duration: 99
}, },
{ // {
videoUrl: mp41, // videoUrl: mp41,
// videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ', // // videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ',
videoPoster: src1Bg, // videoPoster: src1Bg,
isLoved: true, // isLoved: true,
loves: 1234, // loves: 1234,
comments: 666, // comments: 666,
shared: 999, // shared: 999,
duration: 99 // duration: 99
}, // },
{ // {
videoUrl: mp42, // videoUrl: mp42,
// videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ', // // videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ',
videoPoster: src1Bg, // videoPoster: src1Bg,
isLoved: false, // isLoved: false,
loves: 1234, // loves: 1234,
comments: 666, // comments: 666,
shared: 999, // shared: 999,
duration: 99 // duration: 99
}, // },
{ // {
videoUrl: mp43, // videoUrl: mp43,
// videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ', // // videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ',
videoPoster: src1Bg, // videoPoster: src1Bg,
isLoved: false, // isLoved: false,
loves: 1234, // loves: 1234,
comments: 666, // comments: 666,
shared: 999, // shared: 999,
duration: 99 // duration: 99
}, // },
{ // {
videoUrl: mp44, // videoUrl: mp44,
// videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ', // // videoUrl: 'http://babylife.qiniudn.com/FtRVyPQHHocjVYjeJSrcwDkApTLQ',
videoPoster: src1Bg, // videoPoster: src1Bg,
isLoved: false, // isLoved: false,
loves: 1234, // loves: 1234,
comments: 666, // comments: 666,
shared: 999, // shared: 999,
duration: 99 // duration: 99
}, // },
].map(v => { ].map(v => {
this.videos.push(v) this.videos.push(v)
}) })
this.$refs.slideList.checkChildren()
console.log('ok') console.log('ok')
}, 1000) }, 1000)
} }

20
src/pages/home/SlideListVirtual.vue

@ -72,8 +72,24 @@ export default {
}, },
watchList: { watchList: {
handler(newVal, oldVal) { handler(newVal, oldVal) {
console.log(newVal) console.log(this.currentSlideItemIndex)
console.log(oldVal) let endLength = newVal.length
if (newVal.length - oldVal.length > (this.defaultVirtualItemTotal - 1) / 2) {
endLength = oldVal.length + (this.defaultVirtualItemTotal - 1) / 2
}
let that = this
newVal.slice(oldVal.length, endLength).map((item, index) => {
this.slideList.appendChild(this.getInsEl(item, oldVal.length + index))
this.appInsMap.get($("#base-slide-list .base-slide-item:first").data('index')).unmount()
// $("#base-slide-list .base-slide-item:first").remove()
$(".base-slide-item").each(function () {
$(this).css('top',
((endLength - oldVal.length) > 1 ?
(that.currentSlideItemIndex - 2) :
(that.currentSlideItemIndex - 3)) *
that.wrapperHeight)
})
})
}, },
deep: true deep: true
} }

Loading…
Cancel
Save