12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- "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://192.168.10.166:7114/app/webSocket";
- var isSocketOpen = false;
- var socket = null;
- const _sfc_main = {
- data() {
- return {
- reconnectCount: 0,
- maxReconnectAttempts: 3,
- reconnectTimer: null,
- isCollect: false,
- showPurchasePrompt: false,
- purchasePromptTimer: null,
- prevOrderCount: 0,
- // 用于记录上一次的购买人数
- videoUrl: null,
- showType: 1,
- //横屏1 竖屏2
- 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: {}, //直播间点赞、关注、在线人数数据
- };
- },
- onLoad(options) {
- if (options.liveId) {
- this.liveId = options.liveId;
- console.log("接收到的liveId:", this.liveId);
- }
- common_vendor.index.showShareMenu({
- withShareTicket: true
- });
- },
- onShareAppMessage() {
- return {
- // title: this.product.title,
- title: livedata.liveName,
- path: "/pages/home/index",
- imageUrl: this.product.image,
- success(res) {
- console.log("分享成功", res);
- },
- fail(err) {
- console.error("分享失败", err);
- }
- };
- },
- 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() {
- this.closeWebSocket();
- if (this.hlsPlayer) {
- this.hlsPlayer.destroy();
- }
- if (this.pingpangTimes) {
- clearInterval(this.pingpangTimes);
- }
- },
- watch: {
- // 监听orderUser.count的变化
- "orderUser.count": {
- handler(newVal, oldVal) {
- if (newVal !== this.prevOrderCount) {
- this.prevOrderCount = newVal;
- this.showPurchaseMessage();
- }
- },
- immediate: true
- }
- },
- methods: {
- // 显示购买提示信息
- showPurchaseMessage() {
- if (this.purchasePromptTimer) {
- clearTimeout(this.purchasePromptTimer);
- }
- this.showPurchasePrompt = true;
- this.purchasePromptTimer = setTimeout(() => {
- this.showPurchasePrompt = false;
- }, 2e3);
- },
- truncateString(str, maxLength) {
- return str.length > maxLength ? str.slice(0, maxLength) + "..." : str;
- },
- goStore() {
- console.log("带过去storeId", this.products[0].storeId);
- common_vendor.index.navigateTo({
- url: "/pages_shop/store?liveId=" + this.liveId + "&storeId=" + this.products[0].storeId
- });
- },
- // 去订单列表
- 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() {
- console.log("获取直播信息");
- const param = {
- id: this.liveId
- };
- api_home.getlive(param).then((res) => {
- if (res.code !== 200) {
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none",
- duration: 2e3
- });
- return;
- }
- this.livedata = res.data;
- this.showType = res.data.showType;
- console.log("横屏1或竖屏2", this.showType);
- if (res.data.liveType === 2) {
- this.videoUrl = res.data.videoUrl;
- this.autoplay = true;
- this.placeholderText = "观看回放中";
- this.talkdisabled = false;
- } else if (res.data.liveType === 1) {
- this.livingUrl = res.data.flvHlsUrl;
- this.autoplay = true;
- this.placeholderText = "说点什么...";
- this.talkdisabled = false;
- } else {
- this.livingUrl = "";
- this.autoplay = false;
- this.placeholderText = "直播未开始,暂时无法发言";
- this.talkdisabled = true;
- return;
- }
- this.$nextTick(() => {
- if (!this.livingUrl)
- return;
- if (!this.videoContext) {
- this.videoContext = common_vendor.index.createVideoContext("myVideo", this);
- }
- if (res.data.liveType === 1) {
- this.videoContext.seek(res.data.nowDuration || 0);
- } else {
- this.videoContext.play();
- }
- });
- }).catch((err) => {
- console.error("获取直播信息失败:", err);
- common_vendor.index.showToast({
- title: "获取直播信息失败",
- icon: "none"
- });
- });
- },
- 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() {
- const pages = getCurrentPages();
- this.closeWebSocket();
- if (pages.length > 1) {
- common_vendor.index.navigateBack();
- } else {
- common_vendor.index.switchTab({
- url: "/pages/list/index"
- // 替换为你的首页路径
- });
- }
- },
- //直播间点赞、关注、在线人数数据
- getliveViewData() {
- if (!this.liveId)
- return;
- 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() {
- if (!this.liveId)
- return;
- 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 (res.like) {
- this.liveViewData.like++;
- } else {
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none"
- });
- }
- } else {
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none"
- });
- }
- },
- (rej) => {
- }
- );
- },
- // 去购买,跳商品详情
- goShop(productId, goodsId, storeId) {
- common_vendor.index.navigateTo({
- url: "/pages_shop/goods?productId=" + productId + "&liveId=" + this.liveId + "&goodsId=" + goodsId + "&storeId=" + storeId
- });
- },
- // 收藏
- onCollect(item) {
- let storeId;
- if (item) {
- storeId = this.products[0].storeId;
- } else {
- storeId = item.storeId;
- }
- let data = {
- liveId: this.liveId,
- productId: item.productId || "",
- storeId
- };
- api_live.collectStore(data).then(
- (res) => {
- if (res.code == 200) {
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none"
- });
- } 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(',')
- // setTimeout(() => {
- // uni.showToast({
- // title: '准备下一题',
- // icon: 'none',
- // duration: 2000
- // });
- // }, 1000);
- // 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;
- },
- getEWechatSdk() {
- },
- closeWebSocket() {
- clearInterval(this.pingpangTimes);
- clearTimeout(this.reconnectTimer);
- if (socket && isSocketOpen) {
- try {
- common_vendor.index.closeSocket();
- isSocketOpen = false;
- console.log("WebSocket已主动关闭");
- } catch (e) {
- console.error("关闭WebSocket时出错:", e);
- }
- }
- },
- reConnect() {
- var that = this;
- try {
- common_vendor.index.closeSocket();
- } catch (e) {
- }
- setTimeout(function() {
- that.initSocket();
- }, 1e4);
- },
- startHeartbeat() {
- clearInterval(this.pingpangTimes);
- console.log("开始心跳检测");
- this.pingpangTimes = setInterval(() => {
- if (isSocketOpen) {
- const pingData = {
- cmd: "ping",
- timestamp: (/* @__PURE__ */ new Date()).getTime()
- };
- socket.send({
- data: JSON.stringify(pingData),
- success: () => {
- console.log("心跳发送成功");
- },
- fail: (err) => {
- console.error("心跳发送失败:", err);
- this.scheduleReconnect();
- }
- });
- }
- }, 3e4);
- },
- initSocket() {
- var _a;
- if (!this.liveId) {
- console.warn("liveId为空,不尝试WebSocket连接");
- return;
- }
- if (this.reconnectCount >= this.maxReconnectAttempts) {
- console.log("已达到最大重连次数,不再尝试连接");
- common_vendor.index.showToast({
- title: "连接失败,请刷新页面重试",
- icon: "none"
- });
- return;
- }
- this.userinfo = JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}");
- if (!this.userinfo.userId) {
- console.warn("用户信息不存在,不尝试WebSocket连接");
- return;
- }
- this.closeWebSocket();
- let signature = common_vendor.CryptoJS.HmacSHA256(
- common_vendor.CryptoJS.enc.Utf8.parse(((_a = this.liveId) == null ? void 0 : _a.toString()) + this.userinfo.userId + this.userType + this.timestamp),
- common_vendor.CryptoJS.enc.Utf8.parse(this.timestamp)
- ).toString(common_vendor.CryptoJS.enc.Hex);
- 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) => {
- this.reconnectCount++;
- clearInterval(this.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);
- }
- });
- },
- fail: (res) => {
- common_vendor.index.$emit("websocket", 0);
- console.log(res);
- this.scheduleReconnect();
- }
- });
- common_vendor.index.onSocketOpen(() => {
- isSocketOpen = true;
- this.reconnectCount = 0;
- console.log("WebSocket 连接成功");
- this.startHeartbeat();
- });
- common_vendor.index.onSocketClose(() => {
- isSocketOpen = false;
- console.log("WebSocket连接已关闭!");
- this.scheduleReconnect();
- });
- common_vendor.index.onSocketError((err) => {
- isSocketOpen = false;
- console.error("WebSocket 连接错误:", err);
- this.scheduleReconnect();
- });
- },
- scheduleReconnect() {
- if (this.reconnectCount >= this.maxReconnectAttempts) {
- console.log("已达到最大重连次数,不再尝试连接");
- common_vendor.index.showToast({
- title: "连接失败,请刷新页面重试",
- icon: "none"
- });
- return;
- }
- clearTimeout(this.reconnectTimer);
- this.closeWebSocket();
- const delay = Math.min(1e3 * Math.pow(2, this.reconnectCount), 3e4);
- console.log(`将在 ${delay}ms 后尝试第 ${this.reconnectCount + 1} 次重连`);
- this.reconnectTimer = setTimeout(() => {
- this.initSocket();
- }, delay);
- },
- 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$1,
- c: common_vendor.p({
- src: $data.livedata.liveImgUrl,
- size: "32"
- }),
- d: common_vendor.t($data.livedata.liveName ? $options.truncateString($data.livedata.liveName, 5) : "未命名"),
- 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 || 0),
- k: common_vendor.o((...args) => $options.onLike && $options.onLike(...args)),
- l: common_assets._imports_1$1,
- m: common_vendor.t($data.liveViewData.like),
- n: common_vendor.o(($event) => $options.goStore()),
- o: common_assets._imports_2,
- p: common_assets._imports_3,
- q: common_vendor.n($data.showType == 1 ? "siderow-group" : "side-group"),
- r: $data.showPurchasePrompt
- }, $data.showPurchasePrompt ? {
- s: common_assets._imports_4,
- t: common_vendor.t($data.orderUser.userName ? $options.maskString($data.orderUser.userName) : ""),
- v: common_vendor.t($data.orderUser.count || 0)
- } : {}, {
- w: $data.livingUrl
- }, $data.livingUrl ? {
- x: common_vendor.n($data.showType == 1 ? "video_row" : "videotop"),
- y: $data.livingUrl,
- z: $data.autoplay,
- A: common_vendor.o((...args) => $options.videoError && $options.videoError(...args))
- } : {}, {
- B: $data.videoUrl
- }, $data.videoUrl ? {
- C: common_vendor.n($data.showType == 1 ? "video_row" : "videotop"),
- D: $data.videoUrl,
- E: $data.autoplay,
- F: common_vendor.o((...args) => $options.videoError && $options.videoError(...args))
- } : {}, {
- G: 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"
- };
- }),
- H: common_vendor.t($data.messageContent),
- I: 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"
- };
- }),
- J: $data.showWelcomeMessage
- }, $data.showWelcomeMessage ? {
- K: 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"
- };
- }),
- L: common_vendor.t($data.messageContent)
- } : {}, {
- M: $data.scrollIntoView,
- N: common_vendor.o($options.sendMsg),
- O: common_vendor.o($options.sendMsg),
- P: common_vendor.o(($event) => $data.value = $event),
- Q: common_vendor.p({
- placeholder: $data.placeholderText,
- border: "none",
- customStyle: "font-size:24rpx;",
- shape: "circle",
- color: "#fff",
- placeholderStyle: "color:#e7e7e7",
- modelValue: $data.value
- }),
- R: common_assets._imports_5,
- S: common_vendor.o(($event) => $data.shopping = !$data.shopping),
- T: common_assets._imports_6,
- U: common_vendor.o(($event) => $data.showziliao = !$data.showziliao),
- V: common_vendor.o(($event) => $data.showziliao = !$data.showziliao),
- W: common_vendor.p({
- name: "close",
- size: "18"
- }),
- X: $data.livedata.liveDesc,
- Y: common_vendor.o($options.closes),
- Z: common_vendor.p({
- show: $data.showziliao,
- round: "20",
- bgColor: "#fffee1"
- }),
- aa: common_vendor.p({
- src: $data.livedata.liveImgUrl,
- size: "36"
- }),
- ab: common_assets._imports_1,
- ac: $data.isCollect
- }, $data.isCollect ? {
- ad: common_assets._imports_11
- } : {
- ae: common_assets._imports_12
- }, {
- af: common_vendor.o((...args) => $options.onCollect && $options.onCollect(...args)),
- ag: common_assets._imports_10,
- ah: common_vendor.o((...args) => $options.goOrderList && $options.goOrderList(...args)),
- ai: 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")
- }, $data.isCollect ? {
- h: common_vendor.o(($event) => $options.onCollect(item), index),
- i: common_assets._imports_11
- } : {
- j: common_vendor.o(($event) => $options.onCollect(item), index),
- k: common_assets._imports_12
- }, {
- l: item.status == 1
- }, item.status == 1 ? {
- m: common_vendor.o(($event) => $options.goShop(item.productId, item.goodsId, item.storeId), index)
- } : item.status == 0 ? {
- o: common_vendor.o(($event) => $options.goShop(item.productId), index)
- } : {}, {
- n: item.status == 0,
- p: index
- });
- }),
- aj: $data.isCollect,
- ak: $data.boxHeight + "px",
- al: common_vendor.o($options.closeshop),
- am: common_vendor.o($options.open),
- an: 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"]]);
- _sfc_main.__runtimeHooks = 2;
- wx.createPage(MiniProgramPage);
|