From 1b5801446235ba7009727663e2153ce4c310d7d7 Mon Sep 17 00:00:00 2001 From: YeMingfei666 <1619116647@qq.com> Date: Thu, 4 Dec 2025 10:03:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=86=E4=BA=AB=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pageChat/chat.vue | 12 ++++-- pageChat/coupon-activity/index.vue | 62 +++++++++++++++++++++++++++++- pageChat/group-info/index.vue | 5 ++- pageChat/index.vue | 49 +++++++++++++++++++---- store/chat.js | 27 +++++++++---- 5 files changed, 135 insertions(+), 20 deletions(-) diff --git a/pageChat/chat.vue b/pageChat/chat.vue index f1894a7..a8f3273 100644 --- a/pageChat/chat.vue +++ b/pageChat/chat.vue @@ -80,7 +80,10 @@ - + @@ -377,7 +380,7 @@ async function getMsgList() { // 加载失败回退页码,避免页码错乱 if (query.page > 1) query.page--; } finally { - console.log('scrollView',scrollView) + console.log("scrollView", scrollView); setTimeout(() => { scrollView.refresherTriggered = false; isLoading.value = false; @@ -389,7 +392,9 @@ const options = reactive({}); onLoad((opt) => { Object.assign(options, opt); init(); - + chatApi.messageMarkReadAll({ + session_ids: options.session_id, + }); // #ifdef H5 scrollView.safeAreaHeight = uni.getSystemInfoSync().safeArea.height; // #endif @@ -398,6 +403,7 @@ onLoad((opt) => { function toMore() { go.to("PAGES_CHAT_GROUP_INFO", { group_id: groupInfo.value.id, + session_id: options.session_id, }); } function sendText() { diff --git a/pageChat/coupon-activity/index.vue b/pageChat/coupon-activity/index.vue index 382a1c3..6ff8026 100644 --- a/pageChat/coupon-activity/index.vue +++ b/pageChat/coupon-activity/index.vue @@ -72,6 +72,13 @@ + + 分享 失效 查看 @@ -84,13 +91,22 @@ diff --git a/store/chat.js b/store/chat.js index 45cda84..3b02b9c 100644 --- a/store/chat.js +++ b/store/chat.js @@ -15,9 +15,7 @@ export const useChatStore = defineStore("chat", { socketUrl, isConnect: false, socketTask: null, - onReceiveMsg:()=>{ - - }, + onReceiveMsg: () => {}, chatList: [], }; }, @@ -83,20 +81,35 @@ export const useChatStore = defineStore("chat", { this.socketTask.onMessage((res) => { const data = JSON.parse(res.data); console.log("收到服务器消息", data); - if(data.msg){ + if (data.msg) { uni.showToast({ title: data.msg, icon: "none", }); } - - if(data&&data.operate_type=="sendMsg"){ + + if (data && data.operate_type == "sendMsg") { this.chatList.unshift(data.data); this.onReceiveMsg(data.data); console.log(this.chatList); } - }); + + this.socketTask.onError((res) => { + this.isConnect = false; + console.log("连接错误", res); + }); + + this.socketTask.onClose(() => { + this.isConnect = false; + console.log("连接已关闭"); + this.connectSocket(); + }); + }, + + closeSocket() { + this.socketTask.close(); + this.isConnect = false; }, }, unistorage: false, // 开启后对 state 的数据读写都将持久化