1 |
- "use strict";const s=require("../../common/vendor.js"),b=require("../../api/list.js"),g=require("../../api/live.js");require("../../api/order.js");const V=require("../../api/home.js"),h=require("../../common/assets.js");var M="wss://live.test.ylrztop.com/ws/live-api/app/webSocket",v=!1;const U={data(){return{livePlayerInstances:{},livePlayerStates:{},liveRetryCounts:{},maxLiveRetry:3,timer:null,isShowRed:!1,lastSwiperChangeTime:0,swiperChangeThrottle:300,lastClickTime:0,clickDelay:300,connectingLiveId:null,swiperDuration:0,videoRetryCounts:{},socketInstances:{},currentSwiperIndex:0,list:[],preloading:!1,liveUserTotal:null,viewPageSize:10,viewPageNum:1,viewLoading:!1,viewNoMoreData:!1,scrollHeight:0,scrollTimer:null,socketInstance:null,reconnectCount:0,maxReconnectAttempts:3,isManualClose:!1,showRed:!0,searchTimer:null,reconnectTimer:null,isCollect:!1,showPurchasePrompt:!1,purchasePromptTimer:null,prevOrderCount:0,videoUrl:null,showType:1,boxHeight:300,liveViewers:[],likeName:0,hlsPlayer:null,livingUrl:"",products:{},store:{},orderUser:{},userType:0,timestamp:"",liveId:null,userinfo:"",talkdisabled:!1,autoplay:!1,showadd:!1,scrollIntoView:"",videoContext:"",livedata:{}}},onLoad(e){this.initTime(),e.liveId&&(this.liveId=e.liveId),this.userinfo=JSON.parse(s.index.getStorageSync("userInfo")),this.initLiveList(e),this.getliveUser(!1);const t=s.index.getWindowInfo().platform;["mp-weixin","mp-alipay","mp-baidu","mp-toutiao"].includes(t)&&(s.index.showShareMenu?s.index.showShareMenu({withShareTicket:!0,success:()=>{console.log("分享菜单显示成功")},fail:i=>{console.error("分享菜单显示失败:",i)}}):console.warn("当前平台不支持 uni.showShareMenu")),this.getCurrentActivities(e.liveId)},onReady(){},onShareAppMessage(){return{title:this.livedata.liveName,path:"/pages/home/living",imageUrl:this.products.image,success(e){console.log("分享成功",e)},fail(e){console.error("分享失败",e)}}},computed:{filteredViewers(){if(this.liveViewers)return this.liveViewers.slice(0,3)}},onHide(){const e=this.list[this.currentSwiperIndex];e&&(e.livingUrl?this.pauseLive(e):e.videoUrl&&this.pauseVideo(e),this.clearTimeTimer(e)),this.closeAllWebSockets()},onUnload(){Object.values(this.livePlayerInstances).forEach(e=>{try{e.stop()}catch(t){console.error("销毁 live-player 失败",t)}}),this.livePlayerInstances={},this.livePlayerStates={},this.liveRetryCounts={},this.list.forEach(e=>{if(this.clearTimeTimer(e),e.videoUrl){const t=s.index.createVideoContext(`myVideo_${e.liveId}`,this);t==null||t.pause()}}),this.closeAllWebSockets(),this.removeAllEventListeners(),this.clearAllTimers(),this.hlsPlayer&&(this.hlsPlayer.destroy(),this.hlsPlayer=null)},watch:{"orderUser.count":{handler(e,t){e!==this.prevOrderCount&&(this.prevOrderCount=e,this.showPurchaseMessage())},immediate:!0}},methods:{onLivePlayerStateChange(e){const t=this.getLiveIdFromPlayerId(e.currentTarget.id),i=e.detail.code;this.livePlayerStates[t]=i;const l=this.list.find(o=>o.liveId===t);if(l)switch(i){case 1:console.log(`直播间${t}:正在连接直播流`);break;case 2:console.log(`直播间${t}:直播已开始`),this.liveRetryCounts[t]=0;break;case 5:console.error(`直播间${t}:直播播放错误,状态码=${i}`),this.handleLivePlayerError(l);break;case 6:s.index.showToast({title:"直播缓冲中...",icon:"none",duration:1e3});break}},livePlayerError(e){const t=this.getLiveIdFromPlayerId(e.currentTarget.id),i=this.list.find(l=>l.liveId===t);i&&this.handleLivePlayerError(i)},handleLivePlayerError(e){const t=e.liveId;if(this.liveRetryCounts[t]===void 0&&(this.liveRetryCounts[t]=0),this.liveRetryCounts[t]>=this.maxLiveRetry){s.index.showToast({title:`直播连接失败,请检查网络(已重试${this.maxLiveRetry}次)`,icon:"none",duration:3e3});return}this.liveRetryCounts[t]++;const i=1e3*Math.pow(2,this.liveRetryCounts[t]-1);setTimeout(()=>{console.log(`直播间${t}:第${this.liveRetryCounts[t]}次重连`),this.playLive(e)},i)},playLive(e){if(!e||!e.livingUrl)return;const t=`myLivePlayer_${e.liveId}`;new Promise(l=>{const o=s.index.createLivePlayerContext(t,this);if(o)this.livePlayerInstances[e.liveId]=o,l(o);else{let n=0;const d=setInterval(()=>{const r=s.index.createLivePlayerContext(t,this);(r||n>=3)&&(clearInterval(d),l(r)),n++},100)}}).then(l=>{l&&l.play({success:()=>{console.log(`直播间${e.liveId}:直播播放指令已发送`)},fail:o=>{console.error(`直播间${e.liveId}:播放指令失败`,o)}})})},pauseLive(e){if(!e)return;const t=this.livePlayerInstances[e.liveId];t&&t.pause({success:()=>{console.log(`直播间${e.liveId}:直播已暂停`)},fail:i=>{console.error(`直播间${e.liveId}:暂停失败`,i)}})},getLiveIdFromPlayerId(e){return e.replace("myLivePlayer_","")},onLiveFullScreenChange(e){const t=e.detail.fullScreen,i=this.getLiveIdFromPlayerId(e.currentTarget.id);console.log(`直播间${i}:${t?"进入":"退出"}全屏`),this.isLiveFullScreen=t},getCurrentActivities(e){e.liveId&&g.currentActivities(e.liveId).then(t=>{t.code==200?(console.log("红包 卡片 抽奖res>>>",t),this.$set(e,"goodsCard",t.goods),this.$set(e,"redInfo",t.red[0]),this.isShowRed=!0,this.$set(e,"lottery",t.lottery)):s.index.showToast({title:t.msg,icon:"none"})},t=>{})},calculateTimeDiff(e){if(!e.startTime){e.totalTime="00小时00分钟00秒";return}const t=e.startTime.replace(/-/g,"/").replace(" "," "),i=new Date(e.startTime),l=new Date;if(isNaN(i.getTime())){console.warn(`iOS 时间解析失败,原始时间:${e.startTime},转换后:${t}`),e.totalTime="00小时00分钟00秒";return}const o=Math.max(0,l-i),n=Math.floor(o/1e3),d=this.padZero(Math.floor(n/3600)),r=this.padZero(Math.floor(n%3600/60)),u=this.padZero(n%60);this.$set(e,"totalTime",`${d}:${r}:${u}`)},padZero(e){return e<10?`0${e}`:e},startTimeTimer(e){e.timeTimer&&clearInterval(e.timeTimer),this.calculateTimeDiff(e),e.timeTimer=setInterval(()=>{this.calculateTimeDiff(e)},1e3)},clearTimeTimer(e){e.timeTimer&&(clearInterval(e.timeTimer),e.timeTimer=null)},toggleViewerList(){const e=Date.now();e-this.lastClickTime>this.clickDelay&&(this.showadd=!this.showadd,this.lastClickTime=e)},resetUserListParams(){this.viewPageNum=1,this.viewNoMoreData=!1,this.liveViewers=[]},closeAllWebSockets(){this.isManualClose=!0,Object.keys(this.socketInstances).forEach(e=>{try{this.socketInstances[e]&&this.socketInstances[e].instance&&(this.socketInstances[e].instance.close({code:1e3,reason:"页面关闭"}),console.log(`直播间 ${e} WebSocket 已关闭`))}catch(t){console.error(`关闭直播间 ${e} WebSocket 时出错:`,t)}}),this.socketInstances={},v=!1},removeAllEventListeners(){s.index.$off("initSocket"),s.index.$off("sendMsg"),s.index.$off("closeWebSocket"),s.index.$off("refreshOrder")},clearAllTimers(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null),this.pingpangTimes&&(clearInterval(this.pingpangTimes),this.pingpangTimes=null),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null),this.scrollTimer&&(clearTimeout(this.scrollTimer),this.scrollTimer=null),this.searchTimer&&(clearTimeout(this.searchTimer),this.searchTimer=null),this.purchasePromptTimer&&(clearTimeout(this.purchasePromptTimer),this.purchasePromptTimer=null)},async initCurrentLiveData(){const e=this.list[this.currentSwiperIndex];if(e){e.loading=!0;try{await this.initSocket(e),await Promise.allSettled([this.getLiveMsg(e),this.getCurrentActivities(e),this.getliveViewData(e),this.getliving(e)]),e.loaded=!0,this.startTimeTimer(e)}catch(t){console.error("初始化直播间数据失败:",t)}finally{e.loading=!1}}},async initLiveList(e){try{if(await this.getList(),this.list.length===0){console.error("直播间列表为空,无法初始化");return}if(e.liveId){const i=this.list.findIndex(l=>l.liveId==e.liveId);this.currentSwiperIndex=i!==-1?i:0}else this.currentSwiperIndex=0;setTimeout(()=>{this.swiperDuration=300},100);const t=this.list[this.currentSwiperIndex];t&&(this.liveId=t.liveId,this.resetUserListParams(),this.preloadNearbyLives(!1),await this.initCurrentLiveData(),this.getliveUser(!1),setTimeout(()=>{this.playVideo(t)},500))}catch(t){console.error("初始化失败:",t)}},async onSwiperChange(e){const t=Date.now(),i=e.detail.current,l=this.currentSwiperIndex;if(i===l||t-this.lastSwiperChangeTime<this.swiperChangeThrottle)return;this.lastSwiperChangeTime=t;const o=this.list[l];o&&(o.livingUrl?(this.pauseLive(o),delete this.livePlayerInstances[o.liveId],delete this.livePlayerStates[o.liveId],delete this.liveRetryCounts[o.liveId]):o.videoUrl&&this.pauseVideo(o),this.clearTimeTimer(o),this.socketInstances[o.liveId]&&this.closeWebSocket(o.liveId)),this.currentSwiperIndex=i;const n=this.list[i];n&&(this.liveId=n.liveId,this.resetUserListParams(),await this.initCurrentLiveData(),this.getliveUser(!1),setTimeout(()=>{n.livingUrl?this.playLive(n):n.videoUrl&&this.playVideo(n)},100))},async getList(){const e={page:1,page_size:20};try{const t=await b.liveList(e);t.code===200?(this.list=t.rows.map(i=>({...i,talklist:[],loading:!1,loaded:!1,shopping:!1,inputInfo:"",showWelcomeMessage:!1,redInfo:{},goodsCard:{},totalTime:"00小时00分钟00秒",timeTimer:null,startTime:i.startTime?i.startTime.replace(/-/g,"/"):""})),console.log("直播间列表加载成功,数量:",this.list.length)):(s.index.showToast({title:t.msg,icon:"none"}),this.list=[])}catch(t){console.error("获取直播间列表失败:",t),this.list=[]}},playVideo(e){if(e)try{const t=`myVideo_${e.liveId}`,i=s.index.createVideoContext(t,this);i&&i.pause(()=>{i.play()})}catch(t){console.error("播放视频失败:",t)}},pauseVideo(e){if(e)try{const t=`myVideo_${e.liveId}`,i=s.index.createVideoContext(t,this);i&&i.pause()}catch(t){console.error("暂停视频失败:",t)}},async preloadNearbyLives(e=!1){this.preloading=!0;const t=this.currentSwiperIndex,i=[];e=!1,t>0&&i.push(t-1),t<this.list.length-1&&i.push(t+1);for(const l of i){const o=this.list[l];if(!(!o||o.loaded||o.loading)){o.loading=!0;try{await Promise.all([this.getliving(o),this.getLiveMsg(o),this.getCurrentActivities(o),this.getliveViewData(o)]),o.loaded=!0}catch(n){console.error(`预加载直播间 ${l} 失败:`,n),o.loaded=!1}finally{o.loading=!1}}}this.preloading=!1},openViews(){this.$nextTick(()=>{s.index.createSelectorQuery().in(this).select(".view-box").boundingClientRect(t=>{t&&(this.scrollHeight=t.height-80-120)}).exec()})},resetLiveData(){const e={userinfo:this.userinfo,list:this.list,currentSwiperIndex:this.currentSwiperIndex};this.liveUserTotal=null,this.liveViewers=[],this.livingUrl="",this.videoUrl=null,this.products={},this.store={},this.orderUser={},this.talklist=[],this.livedata={},this.shopping=!1,this.inputInfo="",Object.assign(this,e)},async getliveUser(e=!1){const t=this.liveId;if(t){this.viewLoading=!0;try{const i=await g.watchUserList(t,this.viewPageSize,this.viewPageNum,!1);if(i.code===200){if(this.liveId!==t)return;if(this.liveUserTotal=i.total,i.rows.length===0){this.viewNoMoreData=!0;return}this.liveViewers=e?[...this.liveViewers,...i.rows]:i.rows,this.viewPageNum++}}catch(i){console.error("获取观众列表失败:",i)}finally{this.viewLoading=!1}}},handleScrollToLower(){this.scrollTimer&&clearTimeout(this.scrollTimer),this.scrollTimer=setTimeout(()=>{this.getliveUser(!0)},1e3)},async getLiveMsg(e){if(!e||!e.liveId){console.error("getLiveMsg 错误:无效的 liveItem",{liveItem:e,currentIndex:this.currentSwiperIndex,listLength:this.list.length});return}try{const t=await g.liveMsg(e.liveId,30,1);if(t.code==200){const i=[...t.rows].reverse();this.$set(e,"talklist",i),this.$nextTick(()=>{this.$set(e,"scrollIntoView",`list_${i.length-1}`)})}}catch(t){console.error("获取聊天记录失败:",t)}},onRed(e){var i;if(!e.liveId||!((i=e.redInfo)!=null&&i.redId))return;let t={liveId:e.liveId,userId:this.userinfo.userId,redId:e.redInfo.redId};g.liveRed(t).then(l=>{this.isShowRed=!1,l.code==200?(console.log(this.isShowRed),console.log("点了this.liveId",liveItem.redInfo),s.index.showToast({title:l.msg,icon:"none"})):s.index.showToast({title:l.msg,icon:"none"})},l=>{})},handleSearchInput(){clearTimeout(this.searchTimer),this.searchTimer=setTimeout(()=>{this.queryCollect()},500)},showPurchaseMessage(){this.purchasePromptTimer&&clearTimeout(this.purchasePromptTimer),this.showPurchasePrompt=!0,this.purchasePromptTimer=setTimeout(()=>{this.showPurchasePrompt=!1},2e3)},truncateString(e,t){return e.length>t?e.slice(0,t)+"...":e},goStore(e){if(console.log("带过去storeId",e),!e.storeId){s.index.showToast({title:"当前直播间暂未开通店铺",icon:"none"});return}s.index.navigateTo({url:"/pages_shop/store?liveId="+e.liveId+"&storeId="+e.storeId})},goOrderList(){s.index.navigateTo({url:"/pages_shop/order"})},initHlsPlayer(){if(s.Hls.isSupported()&&this.livingUrl){const e=document.getElementById("myVideo");e&&(this.hlsPlayer=new s.Hls,this.hlsPlayer.loadSource(this.livingUrl),this.hlsPlayer.attachMedia(e),this.hlsPlayer.on(s.Hls.Events.MANIFEST_PARSED,()=>{e.play()}))}},videoError(e,t){if(!(!t||t.liveId!==this.liveId)){if(this.videoRetryCounts[t.liveId]===void 0&&(this.videoRetryCounts[t.liveId]=0),this.videoRetryCounts[t.liveId]>=3){console.error(`直播间 ${t.liveId} 视频加载失败,停止重试`),s.index.showToast({title:"视频加载失败,请检查网络",icon:"none",duration:2e3});return}this.videoRetryCounts[t.liveId]++,setTimeout(()=>{t.liveId===this.liveId&&(console.log(`第${this.videoRetryCounts[t.liveId]}次重试播放视频`),this.playVideo(t))},2e3)}},async getliving(e){if(!(!e||!e.liveId)){e.liveId;try{const t=await V.getlive({id:e.liveId});if(t.code!==200){s.index.showToast({title:t.msg,icon:"none"});return}t.data.liveType===2?(this.$set(e,"videoUrl",t.data.videoUrl),this.$set(e,"livingUrl",""),this.$set(e,"placeholderText","说点什么...")):t.data.liveType===1?(this.$set(e,"livingUrl",t.data.flvHlsUrl),this.$set(e,"videoUrl",""),this.$set(e,"placeholderText","说点什么...")):(this.$set(e,"livingUrl",""),this.$set(e,"videoUrl",""));const i=this.currentSwiperIndex===this.list.findIndex(l=>l.liveId===e.liveId);this.$set(e,"autoplay",i&&t.data.liveType!==0),this.$set(e,"showType",t.data.showType),this.$set(e,"storeId",t.storeId),this.queryCollect()}catch(t){console.error("获取直播信息失败:",t),s.index.showToast({title:"获取直播信息失败",icon:"none"})}}},setupVideoPlayback(e,t){if(!e.livingUrl)return;const i=`myVideo_${e.liveId}`,l=s.index.createVideoContext(i,this);t.liveType===1?l.seek(t.nowDuration||0):l.play()},maskString(e,t="*"){return e?String(e).split("").map((l,o)=>o===0?l:t).join(""):""},getPureDecimal(e,t=6){const i=Math.abs(e).toFixed(t).split(".")[1];return(i==null?void 0:i.replace(/0+$/,""))||""},goBack(){const e=this.list[this.currentSwiperIndex];e&&this.pauseVideo(e),this.closeWebSocket(),getCurrentPages().length>1?s.index.navigateBack():s.index.reLaunch({url:"/pages/list/index"})},async getliveOrder(){const e=this.liveId;if(e)try{const t=await g.liveOrderUser(e);if(t.code===200){const i=this.list[this.currentSwiperIndex];i&&(this.$set(i,"orderUser",t),this.orderUser=t)}}catch(t){console.error("获取正在购买用户失败:",t)}},getLiveinformation(){this.liveId&&g.getLiveInfo(this.liveId).then(e=>{e.code==200?(console.log("获取直播间信息接口>>>>",e),this.livingUrl=e.livingUrl):s.index.showToast({title:e.msg,icon:"none"})},e=>{})},async onLike(e){if(!(!e||!e.liveId))try{const t=await g.liveDataLike(e.liveId);t!=null&&t.like?e.liveViewData.like++:s.index.showToast({title:t.msg,icon:"none"})}catch(t){console.error("点赞失败:",t)}},async getliveViewData(e){if(!(!e||!e.liveId))try{const t=await g.getLiveViewData(e.liveId);t.code==200&&this.$set(e,"liveViewData",t)}catch(t){console.error("获取直播间数据失败:",t),this.$set(e,"liveViewData",{like:0,watchCount:0})}},goShop(e,t){const i=this.list[this.currentSwiperIndex];!i||!i.liveId||s.index.navigateTo({url:"/pages_shop/goods?productId="+e+"&liveId="+i.liveId+"&goodsId="+t+"&storeId="+i.storeId})},async queryCollect(){const e=this.list[this.currentSwiperIndex];if(!e||!e.liveId)return;const{storeId:t}=e;if(t)try{const i=await g.store(e.storeId,e.inputInfo,e.liveId);i.code===200&&(this.$set(e,"products",i.data.goodsList),this.$set(e,"store",i.data),this.products=i.data.goodsList,this.store=i.data)}catch(i){console.error("获取小黄车商品失败:",i)}},onStoreCollect(e){console.log("店铺收藏",e),e.storeId&&g.collectStore(e.storeId).then(t=>{t.code==200?(s.index.showToast({title:t.msg,icon:"none"}),e.store.isFavorite=!e.store.isFavorite):s.index.showToast({title:t.msg,icon:"none"})},t=>{})},onGoodsCollect(e){console.log("商品收藏",e),!(!e||e.length===0||!e.goodsId)&&g.collectGoods(e.goodsId).then(t=>{t.code==200?(s.index.showToast({title:t.msg,icon:"none"}),e.isFavorite=!e.isFavorite):s.index.showToast({title:t.msg,icon:"none"})},t=>{})},initTime(){const e=new Date;this.timestamp=e.getTime()},openShop(){},openViews(){this.$nextTick(()=>{s.index.createSelectorQuery().in(this).select(".view-box").boundingClientRect(t=>{t&&(this.scrollHeight=t.height-80-120)}).exec()})},openCart(e){if(!e.storeId){s.index.showToast({title:"当前直播间暂未开通店铺",icon:"none"});return}e.shopping=!0},close(){this.showadd=!1},closeShop(){const e=this.list[this.currentSwiperIndex];e&&this.$set(e,"shopping",!1)},closeRed(){this.showRed=!this.showRed},getEWechatSdk(){},closeWebSocket(e=null){if(this.isManualClose=!0,clearInterval(this.pingpangTimes),clearInterval(this.reconnectTimer),e){if(this.socketInstances[e]&&this.socketInstances[e].instance)try{this.socketInstances[e].instance.close(),console.log(`直播间 ${e} WebSocket 已安全关闭`)}catch(t){console.error(`关闭直播间 ${e} WebSocket 时出错:`,t)}delete this.socketInstances[e]}else Object.keys(this.socketInstances).forEach(t=>{if(this.socketInstances[t]&&this.socketInstances[t].instance)try{this.socketInstances[t].instance.close(),console.log(`直播间 ${t} WebSocket 已安全关闭`)}catch(i){console.error(`关闭直播间 ${t} WebSocket 时出错:`,i)}}),this.socketInstances={};v=!1},reConnect(){var e=this;try{s.index.closeSocket()}catch{}setTimeout(function(){e.initSocket()},1e4)},startHeartbeat(e){clearInterval(this.pingpangTimes),this.pingpangTimes=setInterval(()=>{const t=this.socketInstances[e];if(!t||!t.isOpen||!t.instance)return;const i={cmd:"ping",timestamp:Date.now()};try{t.instance.send({data:JSON.stringify(i)})}catch(l){console.error("心跳发送失败:",l),this.scheduleReconnect(e)}},3e4)},async initSocket(e){const t=this.list[this.currentSwiperIndex];if(!t||t.liveId!==e.liveId){console.log(`拒绝为非活跃直播间 ${e.liveId} 建立WebSocket`);return}if(!e||!e.liveId)return;const i=e.liveId;if(this.connectingLiveId===i||this.socketInstances[i]&&this.socketInstances[i].isOpen){console.log(`直播间 ${i} 的WebSocket已经连接或正在连接,跳过初始化`);return}if(this.currentSwiperIndex!==this.list.findIndex(n=>n.liveId===i)){console.log(`不初始化非当前直播间 ${i} 的WebSocket`);return}if(this.socketInstances[i]&&this.closeWebSocket(i),this.connectingLiveId=i,this.reconnectCount>=this.maxReconnectAttempts){this.connectingLiveId=null;return}this.isManualClose=!1;const l=setTimeout(()=>{var n;(n=this.socketInstances[i])!=null&&n.isOpen||(console.error(`WebSocket连接超时: ${i}`),this.scheduleReconnect(i))},1e4),o=s.CryptoJS.HmacSHA256(`${i}${this.userinfo.userId}${this.userType}${this.timestamp}`,this.timestamp.toString()).toString(s.CryptoJS.enc.Hex);this.socketInstances[i]={instance:null,isOpen:!1};try{const n=s.index.connectSocket({url:`${M}?userId=${this.userinfo.userId}&liveId=${i}&userType=${this.userType}×tamp=${this.timestamp}&signature=${o}`,success:()=>{console.log("WebSocket API 调用成功,正在建立连接...")},fail:d=>{console.error("WebSocket 连接失败:",d),this.connectingLiveId=null,this.scheduleReconnect(i)}});n.onOpen(d=>{console.log("WebSocket 连接已成功建立",d),this.socketInstances[i].instance=n,this.socketInstances[i].isOpen=!0,clearTimeout(l),v=!0,this.connectingLiveId=null,this.reconnectCount=0,this.startHeartbeat(i)}),n.onMessage(d=>{const r=this.list.find(u=>u.liveId===i);r&&this.handleSocketMessage(d,r)}),n.onError(d=>{clearTimeout(l),console.error("WebSocket 连接错误:",d),this.connectingLiveId=null,this.scheduleReconnect(i)}),n.onClose(()=>{console.log(`WebSocket 连接已关闭: ${i}`),this.connectingLiveId=null})}catch(n){console.error("创建 WebSocket 异常:",n),this.connectingLiveId=null,this.scheduleReconnect(i)}},handleSocketMessage(e,t){let i=JSON.parse(e.data);const l=i.data;if(i.code==200){const o={...l,cmd:l.cmd||"",ts:Date.now()};if(l.cmd=="sendMsg")this.$set(t,"talklist",[...t.talklist||[],o]),this.$nextTick(()=>{const n=t.talklist.length-1;this.$set(t,"scrollIntoView",`list_${n}`)});else if(l.cmd=="red")this.$set(t,"redInfo",JSON.parse(l.data)),this.isShowRed=!0,this.timer=setInterval(()=>{this.isShowRed=!0},t.redInfo.duration*1e3);else if(l.cmd=="entry"||l.cmd=="out")this.$set(t,"talklist",[...t.talklist,o]),this.$set(t,"showWelcomeMessage",!1),this.$set(t,"showWelcomeMessage",!0),this.getliveUser(!1),t.welcomeTimer&&clearTimeout(t.welcomeTimer),t.welcomeTimer=setTimeout(()=>{this.$set(t,"showWelcomeMessage",!1)},1e3);else if(l.cmd=="Integral"){let n={msg:l.msg,status:!0};this.$set(t,"integral",n)}else l.cmd=="blockUser"?s.index.removeStorage({key:"AppToken",success:()=>{s.index.reLaunch({url:"/pages/auth/login"})}}):l.cmd=="goods"&&this.$set(t,"goodsCard",JSON.parse(l.data))}else s.index.showToast({title:i.msg,icon:"none"})},scheduleReconnect(e){if(this.isManualClose||this.reconnectCount>=this.maxReconnectAttempts)return;this.reconnectCount++;const t=Math.min(3e3*this.reconnectCount,3e4);clearInterval(this.reconnectTimer),this.reconnectTimer=setTimeout(()=>{const i=this.list.find(l=>l.liveId===e)||{liveId:e};this.initSocket(i)},t)},sendMsg(e){if(!e||!e.liveId||e.isSending)return;e.isSending=!0,setTimeout(()=>{e.isSending=!1},800);const t=(e.value||"").trim();if(!t){s.index.showToast({title:"不能发送空消息",icon:"none"});return}const i=e.liveId,l=this.socketInstances[i];if(this.$set(e,"value",""),!l||!l.instance||!l.isOpen){this.initSocket(e),s.index.showToast({title:"连接未建立,正在重连",icon:"none"});return}const o={liveId:i,userId:this.userinfo.userId,userType:0,cmd:"sendMsg",msg:t,nickName:this.userinfo.nickName,avatar:this.userinfo.avatar};try{l.instance.send({data:JSON.stringify(o),success:()=>{},fail:n=>{console.error("发送失败:",n),s.index.showToast({title:"发送失败,请重试",icon:"none"}),this.$set(e,"value",t)}})}catch(n){console.error("socket send 异常",n),this.$set(e,"value",t)}}}};if(!Array){const e=s.resolveComponent("u-avatar"),t=s.resolveComponent("u-input"),i=s.resolveComponent("u-popup");(e+t+i)()}const $=()=>"../../uni_modules/uview-plus/components/u-avatar/u-avatar.js",R=()=>"../../uni_modules/uview-plus/components/u-input/u-input.js",D=()=>"../../uni_modules/uview-plus/components/u-popup/u-popup.js";Math||($+R+D)();function N(e,t,i,l,o,n){var d;return{a:s.f(o.list,(r,u,f)=>{var w,y,T,S,k,x,m,C,I,L,P;return s.e({a:s.o((...a)=>n.goBack&&n.goBack(...a),r.liveId),b:"471975a0-0-"+f,c:s.p({src:r.liveImgUrl||e.$img.logo,size:"32"}),d:s.t(r.liveName?n.truncateString(r.liveName,8):"未命名"),e:s.f(n.filteredViewers,(a,c,p)=>({a:c,b:a.avatar||e.$img.logo})),f:s.o((...a)=>n.toggleViewerList&&n.toggleViewerList(...a),r.liveId),g:s.o(a=>n.onLike(r),r.liveId),h:s.t(((w=r.liveViewData)==null?void 0:w.like)||0),i:s.n(r.showType==1?"siderow-group":"side-group"),j:((y=r.redInfo)==null?void 0:y.redStatus)==1&&o.isShowRed},((T=r.redInfo)==null?void 0:T.redStatus)==1&&o.isShowRed?{k:s.o(a=>n.onRed(r),r.liveId),l:h._imports_3}:{},o.showPurchasePrompt&&((S=o.orderUser)!=null&&S.count)?{m:h._imports_5,n:s.t(o.orderUser.userName?n.maskString(o.orderUser.userName):""),o:s.t(o.orderUser.count||0)}:{},{p:o.currentSwiperIndex===u&&r.livingUrl},o.currentSwiperIndex===u&&r.livingUrl?{q:"myLivePlayer_"+r.liveId,r:s.n(r.showType==1?"video_row":"videotop"),s:r.livingUrl,t:o.currentSwiperIndex===u,v:s.o((...a)=>n.livePlayerError&&n.livePlayerError(...a),r.liveId),w:s.o((...a)=>n.onLivePlayerStateChange&&n.onLivePlayerStateChange(...a),r.liveId),x:s.o((...a)=>n.onLiveFullScreenChange&&n.onLiveFullScreenChange(...a),r.liveId)}:{},{y:o.currentSwiperIndex===u&&r.videoUrl},o.currentSwiperIndex===u&&r.videoUrl?{z:s.n(r.showType==1?"video_row":"videotop"),A:r.videoUrl,B:o.currentSwiperIndex===u,C:s.o((...a)=>n.videoError&&n.videoError(...a),r.liveId)}:{},{D:r.videoUrl},r.videoUrl?{E:s.t(r.totalTime)}:{},{F:s.f(r.talklist,(a,c,p)=>({a:s.t(a.msg),b:c,c:a.cmd=="announcement"})),G:s.t(r.messageContent),H:s.f(r.talklist,(a,c,p)=>({a:s.t(a.nickName),b:s.t(a.msg),c,d:`list_${c}`,e:a.cmd!="red"&&a.cmd!="out"&&a.cmd!="entry"})),I:r.showWelcomeMessage},r.showWelcomeMessage?{J:s.f(r.talklist,(a,c,p)=>({a:s.t(a.nickName),b:s.t(a.msg),c,d:a.cmd=="entry"||a.cmd=="out"})),K:s.t(r.messageContent)}:{},{L:r.scrollIntoView,M:"471975a0-1-"+f,N:s.o(a=>r.value=a,r.liveId),O:s.p({placeholder:r.placeholderText,border:"none",customStyle:"font-size:24rpx;",shape:"circle",color:"#fff",placeholderStyle:"color:#e7e7e7",modelValue:r.value}),P:s.o(a=>n.sendMsg(r),r.liveId),Q:s.o(a=>n.openCart(r),r.liveId),R:s.o(a=>r.goodsCard.isShow=!1,r.liveId),S:(k=r.goodsCard)==null?void 0:k.imgUrl,T:s.t((x=r.goodsCard)==null?void 0:x.price),U:s.t((m=r.goodsCard)==null?void 0:m.otPrice),V:s.t((C=r.goodsCard)==null?void 0:C.productName),W:s.o(a=>{var c,p;return n.goShop((c=r.goodsCard)==null?void 0:c.productId,(p=r.goodsCard)==null?void 0:p.goodsId)},r.liveId),X:s.o(a=>{var c;return!((c=r.goodsCard)!=null&&c.isShow)},r.liveId),Y:"471975a0-2-"+f,Z:s.p({show:(I=r.goodsCard)==null?void 0:I.isShow,round:"20rpx",mode:"center",bgColor:"#ffffff"}),aa:s.t((L=r.integral)==null?void 0:L.msg),ab:s.o(a=>r.integral.status=e.flase,r.liveId),ac:s.o(a=>{var c;return!((c=r.integral)!=null&&c.status)},r.liveId),ad:"471975a0-3-"+f,ae:s.p({show:(P=r.integral)==null?void 0:P.status,round:"20rpx",mode:"center",bgColor:"#ffffff"}),af:s.f(o.liveViewers,(a,c,p)=>({a:s.t(c+1),b:c===0?"#FF3B30":c===1?"#FF9500":c===2?"#FFCC00":"#8E8E93",c:c<3?"bold":"normal",d:"471975a0-5-"+f+"-"+p+","+("471975a0-4-"+f),e:s.p({src:a.avatar||e.$img.logo,size:"32"}),f:s.t(a.nickName||"未命名"),g:c}))},o.viewNoMoreData&&o.liveViewers.length>0?{}:{},{ag:s.o((...a)=>n.handleScrollToLower&&n.handleScrollToLower(...a),r.liveId),ah:s.o(n.close,r.liveId),ai:s.o(n.openViews,r.liveId),aj:"471975a0-4-"+f,ak:"471975a0-7-"+f+","+("471975a0-6-"+f),al:s.o([a=>r.inputInfo=a.detail.value,(...a)=>n.handleSearchInput&&n.handleSearchInput(...a)],r.liveId),am:r.inputInfo},o.store.isFavorite?{an:s.o(a=>n.onStoreCollect(r),r.liveId),ao:h._imports_11}:{ap:s.o(a=>n.onStoreCollect(r),r.liveId),aq:h._imports_12},{ar:s.o(a=>n.goOrderList(r),r.liveId),as:s.f(o.products,(a,c,p)=>s.e({a:a.imgUrl,b:s.t(c+1),c:s.t(a.productName),d:s.t(a.sales),e:s.t(Math.trunc(a.price)),f:s.t(n.getPureDecimal(a.price)?n.getPureDecimal(a.price):"00"),g:a.isFavorite},a.isFavorite?{h:s.o(_=>n.onGoodsCollect(a),c),i:h._imports_11}:{j:s.o(_=>n.onGoodsCollect(a),c),k:h._imports_12},{l:a.status==1},a.status==1?{m:s.o(_=>n.goShop(a.productId,a.goodsId),c)}:a.status==0?{}:{},{n:a.status==0,o:c})),at:s.o(n.closeShop,r.liveId),av:s.o(n.openShop,r.liveId),aw:"471975a0-6-"+f,ax:s.p({show:r.shopping,round:"20rpx",bgColor:"f3f5f9"}),ay:o.currentSwiperIndex===u?1:"",az:r.liveId})}),b:h._imports_0$2,c:s.t(o.liveUserTotal||0),d:h._imports_2,e:h._imports_4,f:o.showPurchasePrompt&&((d=o.orderUser)==null?void 0:d.count),g:h._imports_6,h:h._imports_6$1,i:h._imports_7,j:h._imports_8,k:o.viewNoMoreData&&o.liveViewers.length>0,l:o.scrollHeight+"px",m:s.p({show:o.showadd,round:"20rpx",bgColor:"#ffffff"}),n:s.p({src:o.store.logoUrl,size:"36"}),o:h._imports_1$2,p:o.store.isFavorite,q:h._imports_10,r:o.boxHeight+"px",s:o.currentSwiperIndex,t:s.o((...r)=>n.onSwiperChange&&n.onSwiperChange(...r)),v:o.swiperDuration}}const W=s._export_sfc(U,[["render",N],["__scopeId","data-v-471975a0"]]);U.__runtimeHooks=2;wx.createPage(W);
|