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 的数据读写都将持久化