"use strict";const s=require("../../common/vendor.js"),c=require("../../api/list.js"),d=require("../../uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js"),u={mixins:[d.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,t){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 t=`myVideo_${e.liveId}`,n=s.index.createIntersectionObserver(this);n.relativeToViewport({top:100,bottom:100}).observe(`#${t}`,r=>{r.intersectionRatio>0?this.playVideo(e):this.pauseVideo(e)}),this.$set(e,"_observer",n)},playVideo(e){if(e._isPlaying||e._error)return;const t=`myVideo_${e.liveId}`,n=e.liveType==1;s.index.createSelectorQuery().in(this).select(`#${t}`).fields({context:!0}).exec(r=>{if(r&&r[0]&&r[0].context){const o=r[0].context;try{if(n)o.play();else{const i=()=>{o.play().then(()=>{console.log("录播视频播放成功:",e.liveId),this.$set(e,"_isPlaying",!0),this.$set(e,"_videoContext",o)}).catch(l=>{console.error("录播视频播放失败:",l),this.$set(e,"_error",!0)})};o.duration>0?i():o.onloadedmetadata=i}this.$set(e,"_isPlaying",!0),this.$set(e,"_videoContext",o)}catch(i){console.error(`播放失败 ${t}:`,i),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 t=e.num;let r={pageSize:e.size,pageNum:t};c.liveList(r).then(o=>{if(o.code==200){let i=o.rows||[],l=o.total||0;i=i.map(a=>({...a,_error:!1,_isPlaying:!1})),t===1&&(this.list=[]),this.list=this.list.concat(i),this.$nextTick(()=>{this.initAllVideoObservers()}),e.endBySize(i.length,l)}else e.endErr(),s.index.showToast({title:o.msg,icon:"none"})}).catch(o=>{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,t,n,r,o,i){return{a:s.f(o.list,(l,a,v)=>s.e({a:l.liveImgUrl},l.liveImgUrl?{b:l.liveImgUrl}:{},{c:s.t(l.liveName),d:s.o(g=>i.goLive(l),a),e:a})),b:s.sr("mescrollRef","7bd28468-0"),c:s.o(i.mescrollInit),d:s.o(i.downCallback),e:s.o(i.upCallback),f:s.p({bottom:"0",down:o.downOption,up:o.upOption})}}const h=s._export_sfc(u,[["render",p],["__scopeId","data-v-7bd28468"]]);wx.createPage(h);