"use strict"; const common_vendor = require("../../common/vendor.js"); const api_live = require("../../api/live.js"); require("../../api/order.js"); const api_home = require("../../api/home.js"); const common_assets = require("../../common/assets.js"); var wsUrl = "ws://live.test.ylrztop.com/prod-api/app/webSocket"; var pingpangTimes = null; var isSocketOpen = false; var socket = null; const _sfc_main = { data() { return { boxHeight: 300, //小黄车高度 isFollow: true, liveViewData: {}, liveViewers: [], //观众 likeName: 0, hlsPlayer: null, // HLS播放器实例, livingUrl: "", products: {}, store: {}, orderUser: {}, //正在购买 userType: 0, timestamp: "", liveId: null, // userId: uni.getStorageSync("userInfo.userId"), livedata: {}, codeimg: "", placeholderText: "说点什么...", isZoom: false, //点赞按钮控制是否放大 userinfo: "", //用户信息 // path: 'http://192.168.10.166/dev-api', //余红奇 // path: 'http://v56c9b8e.natappfree.cc', //余红奇 path: "live.test.ylrztop.com/prod-api", //余红奇 // path: 'http://192.168.10.170/dev-api', //陈果 value: "", talkdisabled: false, //输入框是否禁用 autoplay: false, //视频自动播放 showadd: false, talklist: [], scrollIntoView: "", bufferRate: 0, //视频缓冲时间 playDuration: 0, //视频播放时间 videoContext: "", thistime: common_vendor.index.$u.timeFormat(/* @__PURE__ */ new Date(), "yyyy-mm-dd hh:MM:ss"), upDown: true, //是否视频显示隐藏 isLongPress: false, // 是否长按 timeout: null, // 计时器 showWelcomeMessage: false, isSubmit: false, messageContent: "", showziliao: false, isScreen: true, showAnswer: false, //展示答题 Answerlistall: {}, //所有题目 answerlist: {}, //当前题目 answerfrist: 0, //当前选择 checkboxValue: [], //多选数据 checkboxFormValue: "", //多选数据 allAnswerLists: [], // 新增:存储所有题目列表 showAnswerred: false, //展示红包答题 answerbtn: false, //答题按钮弹窗 redallAnswerLists: [], //储存所有红包答题列表 redanswerAll: [], //红包当前题目 redanswerList: [], //红包答题列表 redanswertips: [], //红包答题提示 shopping: false, //小黄车弹窗 scrollTop: 0, //弹幕 old: { scrollTop: 0 }, liveData: {} //直播间点赞、关注、在线人数数据 // shopList: [{ // title: '史士昊老师四神汤健脾消食疗法', // details: '看它来喘口气,小小震撼,', // people: '45708 ' // },{ // title: '史士昊老师四神汤健脾消食疗法', // details: '看它来喘口气,小小震撼,', // people: '45708 ' // }], // chatList: [{ // lable: '达人', // name: '锅巴', // txt: '中医调节身体确实' // }, // { // lable: '', // name: '从芯开始', // txt: '来了' // } // { // lable: '', // name: '北京的帅小伙:', // txt: '来了来了,上茶' // }, // { // lable: '', // name: '萍萍', // txt: '来了' // } // ] }; }, onLoad(options) { if (options.liveId) { this.liveId = options.liveId; console.log("接收到的liveId:", this.liveId); } }, computed: { filteredViewers() { return this.liveViewers.slice(0, 3); } }, // computed: { // userId() { // return this.$store.state.user.userId // } // }, mounted() { this.getliveViewData(); this.intervalId = setInterval(() => { this.getliveViewData(); }, 60 * 1e3); this.getliveOrder(); this.getliveStore(); this.getliveUser(); this.initTime(); this.initSocket(); var that = this; common_vendor.index.$on("initSocket", () => { that.initSocket(); }); common_vendor.index.$on("sendMsg", (item) => { that.sendMsg(item); }); common_vendor.index.$on("closeWebSocket", () => { that.closeWebSocket(); }); this.getEWechatSdk(); this.getliving(); this.gettalklist(); this.userinfo = JSON.parse(common_vendor.index.getStorageSync("userInfo")); }, onReady: function(res) { this.videoContext = common_vendor.index.createVideoContext("myVideo"); }, onUnload() { if (this.hlsPlayer) { this.hlsPlayer.destroy(); this.hlsPlayer = null; } }, methods: { goStore() { common_vendor.index.navigateTo({ url: "/pages_shop/store?liveId=" + this.liveId }); }, // 去订单列表 goOrderList() { common_vendor.index.navigateTo({ url: "/pages_shop/order" }); }, // 初始化HLS播放器 initHlsPlayer() { if (common_vendor.Hls.isSupported() && this.livingUrl) { const video = document.getElementById("myVideo"); if (video) { this.hlsPlayer = new common_vendor.Hls(); this.hlsPlayer.loadSource(this.livingUrl); this.hlsPlayer.attachMedia(video); this.hlsPlayer.on(common_vendor.Hls.Events.MANIFEST_PARSED, () => { video.play(); }); } } }, // 视频错误处理 videoError(e) { console.error("视频播放错误:", e.detail.errMsg); if (this.livingUrl) { setTimeout(() => { this.videoContext.play(); }, 2e3); } }, getliving() { const param = { id: this.liveId }; api_home.getlive(param).then((res) => { if (res.code == 200) { this.livedata = res.data; this.livingUrl = res.data.livingUrl; if (this.livingUrl && this.livingUrl.indexOf(".m3u8") > -1) { this.$nextTick(() => { if (this.videoContext) { this.videoContext.play(); } }); } else { if (this.livedata.liveType == 1) { this.autoplay = true; this.livingUrl = res.videoUrl; this.videoContext.seek(this.livedata.nowDuration); } else if (this.livedata.liveType == 2) { this.autoplay = true; this.getLiveinformation(); } else { this.autoplay = false; this.placeholderText = "直播开始才能发言讨论"; this.talkdisabled = true; } } } else { common_vendor.index.showToast({ title: res.msg, icon: "none", duration: 2e3 }); } }); }, maskString(str, maskChar = "*") { if (!str) return ""; const strVal = String(str); return strVal.split("").map((char, index) => index === 0 ? char : maskChar).join(""); }, getPureDecimal(num, precision = 6) { const decimalPart = Math.abs(num).toFixed(precision).split(".")[1]; return (decimalPart == null ? void 0 : decimalPart.replace(/0+$/, "")) || ""; }, // 返回上一个页面并关闭WebSocket goBack() { common_vendor.index.navigateBack(); closeWebSocket(); }, // // 收藏商品 // collectProducts(){ // }, //直播间点赞、关注、在线人数数据 getliveViewData() { api_live.getLiveViewData(this.liveId).then( (res) => { if (res.code == 200) { this.liveViewData = res; } else { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } }, (rej) => { } ); }, //正在购买 getliveOrder() { api_live.liveOrderUser(this.liveId).then( (res) => { if (res.code == 200) { console.log("正在购买>>>>", res); this.orderUser = res; } else { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } }, (rej) => { } ); }, //小黄车 店铺展示 getliveStore() { let data = { pageSize: 10, page: 1 }; api_live.liveStore(this.liveId, data).then( (res) => { if (res.code == 200) { console.log("小黄车 店铺展示>>>>", res); this.products = res.data; } else { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } }, (rej) => { } ); }, // 获取直播间信息接口 getLiveinformation() { api_live.getLiveInfo(this.liveId).then( (res) => { if (res.code == 200) { console.log("获取直播间信息接口>>>>", res); this.livingUrl = res.livingUrl; } else { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } }, (rej) => { } ); }, // 获取直播间用户 getliveUser() { api_live.getRecentLiveViewers(this.liveId).then( (res) => { if (res.code == 200) { console.log("获取直播间用户>>>>", res); this.liveViewers = res.recentLiveViewers; } else { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } }, (rej) => { } ); }, // 点赞 onLike() { api_live.liveDataLike(this.liveId).then( (res) => { if (res.code == 200) { if (typeof res.msg === "number" || typeof res.msg === "string" && /^\d+$/.test(res.msg.trim())) { this.liveData++; } else { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } } else { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } }, (rej) => { } ); }, // 去购买,跳商品详情 goShop(item) { console.log("去购买,跳商品详情", item); common_vendor.index.navigateTo({ url: "/pages_shop/goods?productId=" + item + "&liveId=" + this.liveId }); }, // 收藏 onCollect(item) { console.log("item>>>", item.productId); common_vendor.index.setStorageSync("storeId", storeId); let data = { liveId: this.liveId, productId: item.productId, storeId: this.store.storeId }; api_live.collectStore(data).then( (res) => { if (res.code == 200) { console.log("收藏lcollectStore>>>>", res); } else { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } }, (rej) => { } ); }, // 关注 onFollow() { api_live.follow(this.liveId).then( (res) => { this.isFollow = !this.isFollow; common_vendor.index.showToast({ title: res.msg, icon: "none" }); }, (rej) => { } ); }, initTime() { const now = /* @__PURE__ */ new Date(); this.timestamp = now.getTime(); }, // initWebSocket() { // const liveWS = new LiveWS('ws://your-server.com', 123, 456); // // 从 URL 中解析 timestamp // const urlParams = new URL(liveWS.url).searchParams; // this.timestamp = urlParams.get('timestamp'); // // console.log('Timestamp:', timestamp); // }, // 弹幕滚动 lowerChat: function(e) { console.log(e); }, scroll: function(e) { console.log(e); this.old.scrollTop = e.detail.scrollTop; }, loadmore() { }, // 弹幕 scrollchat() { }, noredanswer() { if (this.Answerlistall > 0) { this.showAnswer = !this.this.showAnswer; } else { common_vendor.index.showToast({ title: "暂无题目", icon: "none" }); } }, redbagAnswer() { this.showAnswerred = !this.showAnswerred; this.answerbtn = !this.answerbtn; }, submitAnswers() { if (this.isSubmit) return; this.isSubmit = true; const data = { questionId: this.answerlist.id, answer: this.checkboxFormValue }; api_home.submitAnswer(data).then((res) => { if (res.code == 200) { common_vendor.index.showToast({ title: res.msg, icon: "none" }); } if (this.answerfrist < this.Answerlistall - 1) { this.answerfrist++; this.answerlist = this.allAnswerLists[this.answerfrist]; this.answerlist.content = JSON.parse(this.answerlist.content); } else { common_vendor.index.showToast({ title: "已是最后一题", icon: "none" }); this.showAnswer = false; } this.checkboxValue = []; this.checkboxFormValue = ""; common_vendor.index.showToast({ title: res.msg, icon: "none" }); }).finally((e) => { this.isSubmit = false; }); }, handleCheckboxSelect(value) { const index = this.checkboxValue.indexOf(value); console.log(value); if (this.answerlist.type == 1) { this.checkboxValue = [value]; this.checkboxFormValue = this.checkboxValue.join(","); this.submitAnswers(); console.log(this.checkboxValue); } else if (this.answerlist.type == 2) { if (index > -1) { this.checkboxValue.splice(index, 1); this.checkboxFormValue = this.checkboxValue.join(","); } else { this.checkboxValue.push(value); this.checkboxFormValue = this.checkboxValue.join(","); } console.log(this.checkboxFormValue); } }, getAnswerlists() { console.log(123); const data = { liveId: this.liveId }; api_home.getAnswerlist(data).then((res) => { if (res.code == 200) { if (res.data.length > 0) { this.allAnswerLists = res.data; this.Answerlistall = res.data.length; if (this.allAnswerLists.length > 0) { this.answerlist = this.allAnswerLists[0]; this.answerlist.content = JSON.parse(this.allAnswerLists[0].content); } this.showAnswer = true; } else { this.showAnswer = false; } } }); }, gettalklist() { const param = { id: this.liveId }; api_home.gettextlist(param).then((res) => { if (res.code == 200) { this.talklist = res.data; this.$nextTick(() => { this.scrollIntoView = `list_${this.talklist.length - 1}`; }); } }); }, open() { }, close() { this.showadd = !this.showadd; }, closes() { this.showziliao = !this.showziliao; }, closest() { this.showAnswer = !this.showAnswer; }, closestred() { this.showAnswerred = !this.showAnswerred; }, closeanswer() { this.answerbtn = !this.answerbtn; }, // 关闭小黄车 closeshop() { this.shopping = !this.shopping; }, longPress() { this.timeout = setTimeout(() => { this.isLongPress = true; common_vendor.index.saveImageToPhotosAlbum({ filePath: this.livedata.qwQrCode, // 图片的本地路径或网络路径 success: () => { common_vendor.index.showToast({ title: "保存成功" }); }, fail: () => { common_vendor.index.showToast({ title: "", icon: "none" }); } }); }, 500); }, cancelLongPress() { clearTimeout(this.timeout); this.isLongPress = false; }, // 触摸开始 handleTouchStart() { this.isZoom = true; }, // 触摸结束 handleTouchEnd() { this.isZoom = false; }, // getliving() { // const param = { // id: this.liveId // } // getlive(param).then(res => { // if (res.code == 200) { // this.livedata = res.data // this.codeimg = res.data.qwQrCode // if (this.livedata.status == 1) { // this.autoplay = true // this.videoContext.seek(this.livedata.nowDuration) // // console.log(this.autoplay) // } else { // this.autoplay = false // this.placeholderText = "直播开始才能发言讨论" // this.talkdisabled = true // } // console.log(this.autoplay) // } else { // uni.showToast({ // title: res.msg, // icon: 'none', // duration: 2000 // }); // } // }) // }, getEWechatSdk() { }, closeWebSocket() { if (socket != null) { common_vendor.index.closeSocket(); } clearInterval(pingpangTimes); }, reConnect() { var that = this; try { common_vendor.index.closeSocket(); } catch (e) { } setTimeout(function() { that.initSocket(); }, 1e4); }, initSocket() { this.userinfo = JSON.parse(common_vendor.index.getStorageSync("userInfo")); let signature = common_vendor.CryptoJS.HmacSHA256( common_vendor.CryptoJS.enc.Utf8.parse(this.liveId.toString() + this.userinfo.userId + this.userType + this.timestamp), common_vendor.CryptoJS.enc.Utf8.parse(this.timestamp) ).toString(common_vendor.CryptoJS.enc.Hex); var that = this; socket = common_vendor.index.connectSocket({ // url: wsUrl+"?userId=40486&liveId=2", // url: wsUrl + "?userId=" + this.userid + "&liveId=" + // this.liveId+"&AppToken="+'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI0IiwiaWF0IjoxNzQwNzIxMDQ1LCJleHAiOjE3NDEzMjU4NDV9.PgS83JTMSJgVFD6vGAhUsEPbS6Az4yMyX8wVug61TZNTB3092CtvANo-AB9ZG4NdSBLgLrf4litM3vvTk-FK0g', // // url: wsUrl + "?userId=" + this.userId + "&liveId=" + this.liveId + "&AppToken=" + uni // .getStorageSync('AppToken'), url: wsUrl + "?userId=" + this.userinfo.userId + "&liveId=" + this.liveId + "&userType=" + this.userType + "×tamp=" + this.timestamp + "&signature=" + signature, multiple: true, success: (res) => { clearInterval(pingpangTimes); common_vendor.index.onSocketMessage((res2) => { if (res2.data.code == 500) { common_vendor.index.showToast({ title: res2.data.msg, icon: "none", duration: 2e3 }); } const redata = JSON.parse(res2.data); console.log("WebSocket拿到的东西", redata); this.talklist.push(redata.data); this.$nextTick(() => { this.scrollIntoView = `list_${this.talklist.length - 1}`; }); if (redata.cmd == "deleteId") { common_vendor.index.$emit("deleteId"); } else if (redata.cmd == "init") { common_vendor.index.$emit("init", redata.data); } else if (redata.cmd == "reload") { common_vendor.index.$emit("reload"); } else if (redata.data.cmd == "sendRedPacketQuestion") { const list = JSON.parse(redata.data.data); this.redanswerAll = [...this.redanswerAll, ...list]; if (this.redanswerAll[1].randomAmount !== null) { this.redanswertips = JSON.parse(this.redanswerAll[0].randomAmount); } console.log(this.redanswertips); console.log(this.redanswerAll); } else if (redata.data.cmd == "entry") { this.showWelcomeMessage = true; common_vendor.index.$emit("entry", redata.data); } }); }, error: (res) => { common_vendor.index.$emit("websocket", 0); console.log(res); } }); common_vendor.index.onSocketOpen(() => { isSocketOpen = true; console.log("WebSocket连接已打开!!"); common_vendor.index.showToast({ title: "插件已打开", icon: "none" }); }); common_vendor.index.onSocketClose(() => { isSocketOpen = false; clearInterval(pingpangTimes); console.log("WebSocket连接已关闭!"); common_vendor.index.showToast({ title: "插件离线", icon: "none" }); that.reConnect(); }); common_vendor.index.onSocketError(() => { isSocketOpen = false; clearInterval(pingpangTimes); console.log("WebSocket连接打开失败"); common_vendor.index.showToast({ title: "插件离线", icon: "none" }); common_vendor.index.showModal({ content: "聊天连接失败是否重新尝试连接", success() { that.reConnect(); } }); }); }, sendMsg() { if (isSocketOpen) { const data = { liveId: this.liveId, userId: this.userinfo.userId, userType: 0, cmd: "sendMsg", msg: this.value, nickName: this.userinfo.nickName, avatar: this.userinfo.avatar }; if (this.value == "") { common_vendor.index.showToast({ title: "不能发送空消息", icon: "none" }); } else { socket.send({ data: JSON.stringify(data), success: () => { console.log("发送成功"); this.value = ""; }, fail: () => { console.log("发送失败"); } }); } } } } }; if (!Array) { const _easycom_u_avatar2 = common_vendor.resolveComponent("u-avatar"); const _easycom_u_input2 = common_vendor.resolveComponent("u-input"); const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon"); const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup"); (_easycom_u_avatar2 + _easycom_u_input2 + _easycom_u_icon2 + _easycom_u_popup2)(); } const _easycom_u_avatar = () => "../../uni_modules/uview-plus/components/u-avatar/u-avatar.js"; const _easycom_u_input = () => "../../uni_modules/uview-plus/components/u-input/u-input.js"; const _easycom_u_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js"; const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js"; if (!Math) { (_easycom_u_avatar + _easycom_u_input + _easycom_u_icon + _easycom_u_popup)(); } function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)), b: common_assets._imports_0$2, c: common_vendor.p({ src: $data.livedata.liveImgUrl, size: "32" }), d: common_vendor.t($data.livedata.liveName ? $data.livedata.liveName : "芳华未来"), e: common_vendor.t($data.liveViewData.follow || $data.liveViewData.follow === 0 ? $data.liveViewData.follow : 0), f: $data.isFollow }, $data.isFollow ? { g: common_vendor.o((...args) => $options.onFollow && $options.onFollow(...args)) } : { h: common_vendor.o((...args) => $options.onFollow && $options.onFollow(...args)) }, { i: common_vendor.f($options.filteredViewers, (item, index, i0) => { return { a: index, b: item.avatar }; }), j: common_vendor.t($data.liveViewData.online), k: common_vendor.o(($event) => $options.onLike()), l: common_assets._imports_1, m: common_vendor.t($data.liveViewData.like), n: common_assets._imports_2, o: common_vendor.o(($event) => $options.goStore()), p: common_assets._imports_3, q: common_assets._imports_4, r: common_vendor.t($data.orderUser.userName ? $options.maskString($data.orderUser.userName) : ""), s: common_vendor.t($data.orderUser.count || 0), t: $data.livingUrl, v: $data.autoplay, w: common_vendor.o((...args) => $options.videoError && $options.videoError(...args)), x: $data.isScreen ? "100vh" : "", y: common_vendor.f($data.talklist, (item, index, i0) => { return { a: common_vendor.t(item.msg), b: item.index, c: `list_${index}`, d: item.cmd == "announcement" }; }), z: common_vendor.t($data.messageContent), A: common_vendor.f($data.talklist, (item, index, i0) => { return { a: common_vendor.t(item.nickName), b: common_vendor.t(item.msg), c: item.index, d: `list_${index}`, e: item.cmd == "sendMsg" }; }), B: $data.showWelcomeMessage }, $data.showWelcomeMessage ? { C: common_vendor.f($data.talklist, (item, index, i0) => { return { a: common_vendor.t(item.nickName), b: common_vendor.t(item.msg), c: item.index, d: `list_${index}`, e: item.cmd == "entry" || item.cmd == "out" }; }), D: common_vendor.t($data.messageContent) } : {}, { E: $data.scrollIntoView, F: common_vendor.o($options.sendMsg), G: common_vendor.o($options.sendMsg), H: common_vendor.o(($event) => $data.value = $event), I: common_vendor.p({ placeholder: $data.placeholderText, border: "none", customStyle: "font-size:24rpx;", shape: "circle", color: "#fff", placeholderStyle: "color:#e7e7e7", modelValue: $data.value }), J: common_assets._imports_5, K: common_vendor.o(($event) => $data.shopping = !$data.shopping), L: common_assets._imports_6, M: common_vendor.o(($event) => $data.showziliao = !$data.showziliao), N: common_vendor.o(($event) => $data.showziliao = !$data.showziliao), O: common_vendor.p({ name: "close", size: "18" }), P: $data.livedata.liveDesc, Q: common_vendor.o($options.closes), R: common_vendor.p({ show: $data.showziliao, round: "20", bgColor: "#fffee1" }), S: common_vendor.p({ src: $data.livedata.liveImgUrl, size: "36" }), T: common_assets._imports_0$1, U: common_assets._imports_10, V: common_vendor.o((...args) => $options.onCollect && $options.onCollect(...args)), W: common_assets._imports_9, X: common_vendor.o((...args) => $options.goOrderList && $options.goOrderList(...args)), Y: common_vendor.f($data.products, (item, index, i0) => { return common_vendor.e({ a: item.imgUrl, b: common_vendor.t(index + 1), c: common_vendor.t(item.productName), d: common_vendor.t(item.productIntroduce), e: common_vendor.t(item.sales), f: common_vendor.t(Math.trunc(item.price)), g: common_vendor.t($options.getPureDecimal(item.price) ? $options.getPureDecimal(item.price) : "00"), h: common_vendor.o(($event) => $options.onCollect(item), index), i: item.status == 1 }, item.status == 1 ? { j: common_vendor.o(($event) => $options.goShop(item.productId), index) } : item.status == 0 ? { l: common_vendor.o(($event) => $options.goShop(item.productId), index) } : {}, { k: item.status == 0, m: index }); }), Z: common_assets._imports_10, aa: $data.boxHeight + "px", ab: common_vendor.o($options.closeshop), ac: common_vendor.o($options.open), ad: common_vendor.p({ show: $data.shopping, round: "20rpx", bgColor: "#f3f5f9" }) }); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-471975a0"]]); wx.createPage(MiniProgramPage);