index.js 3.3 KB

1
  1. "use strict";const s=require("../../common/vendor.js"),d=require("../../api/list.js"),u=require("../../uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js"),v={mixins:[u.MescrollMixin],data(){return{list:[],downOption:{offset:80,use:!0,auto:!1},upOption:{use:!0,auto:!0,page:{num:0,size:10}},mescroll:null,observer:null}},onLoad(){s.index.getStorageSync("AppToken")||s.index.navigateTo({url:"/pages/auth/login"})},onUnload(){this.cleanupAllVideos()},methods:{onVideoError(e,r){this.$set(e,"_error",!0),this.pauseVideo(e)},onVideoLoaded(e){console.log("视频元数据加载完成:",e.liveId),this.$set(e,"_error",!1)},initAllVideoObservers(){this.cleanupAllVideos(),setTimeout(()=>{this.list.forEach(e=>{e.liveId&&this.initVideoObserver(e)})},300)},initVideoObserver(e){const r=`myVideo_${e.liveId}`,a=s.index.createIntersectionObserver(this);a.relativeToViewport({top:100,bottom:100}).observe(`#${r}`,t=>{t.intersectionRatio>0?this.playVideo(e):this.pauseVideo(e)}),this.$set(e,"_observer",a)},playVideo(e){if(e._isPlaying||e._error)return;const r=`myVideo_${e.liveId}`,a=e.liveType==1;s.index.createSelectorQuery().in(this).select(`#${r}`).fields({context:!0}).exec(t=>{if(t&&t[0]&&t[0].context){const i=t[0].context;try{if(a)i.play();else{const l=()=>{i.play().then(()=>{console.log("录播视频播放成功:",e.liveId),this.$set(e,"_isPlaying",!0),this.$set(e,"_videoContext",i)}).catch(o=>{console.error("录播视频播放失败:",o),this.$set(e,"_error",!0)})};i.duration>0?l():i.onloadedmetadata=l}this.$set(e,"_isPlaying",!0),this.$set(e,"_videoContext",i)}catch(l){console.error(`播放失败 ${r}:`,l),this.$set(e,"_error",!0)}}})},pauseVideo(e){e._isPlaying&&(e._videoContext&&e._videoContext.pause(),this.$set(e,"_isPlaying",!1))},cleanupAllVideos(){this.list.forEach(e=>{this.pauseVideo(e),e._observer&&(e._observer.disconnect(),this.$set(e,"_observer",null))})},mescrollInit(e){this.mescroll=e},downCallback(e){this.cleanupAllVideos(),this.list=[],e.resetUpScroll()},upCallback(e){const r=e.num;let t={pageSize:e.size,page:r};d.liveList(t).then(i=>{if(i.code==200){let l=i.rows||[];console.log("curPageData在这里>>>>",l);let o=i.total||0;l=l.map(n=>({...n,_error:!1,_isPlaying:!1})),r===1&&(this.list=[]),this.list=this.list.concat(l),console.log("list在这里>>>>",list),this.$nextTick(()=>{this.initAllVideoObservers()}),e.endBySize(l.length,o)}else e.endErr(),s.index.showToast({title:i.msg,icon:"none"})}).catch(i=>{e.endErr()})},goLive(e){s.index.navigateTo({url:`/pages/home/living?liveId=${e.liveId}&immediate=true`})}}};Array||s.resolveComponent("mescroll-body")();const _=()=>"../../uni_modules/mescroll-uni/components/mescroll-body/mescroll-body.js";Math||_();function p(e,r,a,t,i,l){return{a:s.f(i.list,(o,n,g)=>s.e({a:o.liveImgUrl},o.liveImgUrl?{b:o.liveImgUrl}:{},{c:o.liveType==1&&o.flvHlsUrl},o.liveType==1&&o.flvHlsUrl?{d:"myVideo_"+o.liveId,e:o.flvHlsUrl,f:s.o(c=>l.onVideoError(o,c),n)}:{},{g:o.liveType==2&&o.videoUrl},o.liveType==2&&o.videoUrl?{h:"myVideo_"+o.liveId,i:o.videoUrl,j:s.o(c=>l.onVideoError(o,c),n),k:s.o(c=>l.onVideoLoaded(o),n)}:{},{l:s.t(o.liveName),m:s.o(c=>l.goLive(o),n),n})),b:s.sr("mescrollRef","7bd28468-0"),c:s.o(l.mescrollInit),d:s.o(l.downCallback),e:s.o(l.upCallback),f:s.p({bottom:"0",down:i.downOption,up:i.upOption})}}const h=s._export_sfc(v,[["render",p],["__scopeId","data-v-7bd28468"]]);wx.createPage(h);