"use strict"; var common_vendor = require("../../common/vendor.js"); var api_live = require("../../api/live.js"); require("../../api/order.js"); var api_home = require("../../api/home.js"); var common_assets = require("../../common/assets.js"); require("../../common/request.js"); var wsUrl = "ws://nd383294.natappfree.cc/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, livingUrl: "", products: {}, store: {}, orderUser: {}, userType: 0, timestamp: "", liveId: null, livedata: {}, codeimg: "", placeholderText: "\u8BF4\u70B9\u4EC0\u4E48...", isZoom: false, userinfo: "", path: "http://v56c9b8e.natappfree.cc", value: "", talkdisabled: false, autoplay: false, showadd: false, talklist: [], scrollIntoView: "", bufferRate: 0, playDuration: 0, videoContext: "", thistime: common_vendor.index.$u.timeFormat(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: {} }; }, onLoad(options) { if (options.liveId) { this.liveId = options.liveId; console.log("\u63A5\u6536\u5230\u7684liveId:", this.liveId); } }, computed: { filteredViewers() { return this.liveViewers.slice(0, 3); } }, 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" }); }, 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("\u89C6\u9891\u64AD\u653E\u9519\u8BEF:", 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 = "\u76F4\u64AD\u5F00\u59CB\u624D\u80FD\u53D1\u8A00\u8BA8\u8BBA"; 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+$/, "")) || ""; }, goBack() { common_vendor.index.navigateBack(); closeWebSocket(); }, 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("\u6B63\u5728\u8D2D\u4E70>>>>", 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("\u5C0F\u9EC4\u8F66 \u5E97\u94FA\u5C55\u793A>>>>", 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("\u83B7\u53D6\u76F4\u64AD\u95F4\u4FE1\u606F\u63A5\u53E3>>>>", 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("\u83B7\u53D6\u76F4\u64AD\u95F4\u7528\u6237>>>>", 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("\u53BB\u8D2D\u4E70,\u8DF3\u5546\u54C1\u8BE6\u60C5", 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("\u6536\u85CFlcollectStore>>>>", 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 = new Date(); this.timestamp = now.getTime(); }, 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: "\u6682\u65E0\u9898\u76EE", 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: "\u5DF2\u662F\u6700\u540E\u4E00\u9898", 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: "\u4FDD\u5B58\u6210\u529F" }); }, fail: () => { common_vendor.index.showToast({ title: "", icon: "none" }); } }); }, 500); }, cancelLongPress() { clearTimeout(this.timeout); this.isLongPress = false; }, handleTouchStart() { this.isZoom = true; }, handleTouchEnd() { this.isZoom = false; }, 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=" + 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\u62FF\u5230\u7684\u4E1C\u897F", 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\u8FDE\u63A5\u5DF2\u6253\u5F00\uFF01!"); common_vendor.index.showToast({ title: "\u63D2\u4EF6\u5DF2\u6253\u5F00", icon: "none" }); }); common_vendor.index.onSocketClose(() => { isSocketOpen = false; clearInterval(pingpangTimes); console.log("WebSocket\u8FDE\u63A5\u5DF2\u5173\u95ED\uFF01"); common_vendor.index.showToast({ title: "\u63D2\u4EF6\u79BB\u7EBF", icon: "none" }); that.reConnect(); }); common_vendor.index.onSocketError(() => { isSocketOpen = false; clearInterval(pingpangTimes); console.log("WebSocket\u8FDE\u63A5\u6253\u5F00\u5931\u8D25"); common_vendor.index.showToast({ title: "\u63D2\u4EF6\u79BB\u7EBF", icon: "none" }); common_vendor.index.showModal({ content: "\u804A\u5929\u8FDE\u63A5\u5931\u8D25\u662F\u5426\u91CD\u65B0\u5C1D\u8BD5\u8FDE\u63A5", 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: "\u4E0D\u80FD\u53D1\u9001\u7A7A\u6D88\u606F", icon: "none" }); } else { socket.send({ data: JSON.stringify(data), success: () => { console.log("\u53D1\u9001\u6210\u529F"); this.value = ""; }, fail: () => { console.log("\u53D1\u9001\u5931\u8D25"); } }); } } } } }; 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, c: common_vendor.p({ src: $data.livedata.liveImgUrl, size: "32" }), d: common_vendor.t($data.livedata.liveName ? $data.livedata.liveName : "\u82B3\u534E\u672A\u6765"), 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_vendor.t($data.liveViewData.like), m: common_vendor.o(($event) => $options.goStore()), n: common_vendor.t($data.orderUser.userName ? $options.maskString($data.orderUser.userName) : ""), o: common_vendor.t($data.orderUser.count || 0), p: $data.livingUrl, q: $data.autoplay, r: common_vendor.o((...args) => $options.videoError && $options.videoError(...args)), s: $data.isScreen ? "100vh" : "", t: 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" }; }), v: common_vendor.t($data.messageContent), w: 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" }; }), x: $data.showWelcomeMessage }, $data.showWelcomeMessage ? { y: 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" }; }), z: common_vendor.t($data.messageContent) } : {}, { A: $data.scrollIntoView, B: common_vendor.o($options.sendMsg), C: common_vendor.o($options.sendMsg), D: common_vendor.o(($event) => $data.value = $event), E: common_vendor.p({ placeholder: $data.placeholderText, border: "none", customStyle: "font-size:24rpx;", shape: "circle", color: "#fff", placeholderStyle: "color:#e7e7e7", modelValue: $data.value }), F: common_vendor.o(($event) => $data.shopping = !$data.shopping), G: common_vendor.o(($event) => $data.showziliao = !$data.showziliao), H: common_vendor.o(($event) => $data.showziliao = !$data.showziliao), I: common_vendor.p({ name: "close", size: "18" }), J: $data.livedata.liveDesc, K: common_vendor.o($options.closes), L: common_vendor.p({ show: $data.showziliao, round: "20", bgColor: "#fffee1" }), M: common_vendor.p({ src: $data.livedata.liveImgUrl, size: "36" }), N: common_assets._imports_1, O: common_assets._imports_2, P: common_vendor.o((...args) => $options.onCollect && $options.onCollect(...args)), Q: common_assets._imports_3, R: common_vendor.o((...args) => $options.goOrderList && $options.goOrderList(...args)), S: 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)), i: item.status == 1 }, item.status == 1 ? { j: common_vendor.o(($event) => $options.goShop(item.productId)) } : item.status == 0 ? { l: common_vendor.o(($event) => $options.goShop(item.productId)) } : {}, { k: item.status == 0, m: index }); }), T: $data.boxHeight + "px", U: common_vendor.o($options.closeshop), V: common_vendor.o($options.open), W: common_vendor.p({ show: $data.shopping, round: "20rpx", bgColor: "#f3f5f9" }) }); } var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-55719d20"], ["__file", "C:/Users/Administrator/Desktop/\u9879\u76EE/\u76F4\u64AD/liveH5-v3/pages/home/living.vue"]]); wx.createPage(MiniProgramPage);