From 0b07091e791896d6d19fa823d6be8d3716341c32 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 7 May 2026 21:26:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(im):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=88=87=E4=BC=9A=E8=AF=9D=20watch=20=E4=BB=85=E7=9B=91?= =?UTF-8?q?=E5=90=AC=20targetId=20=E5=AF=BC=E8=87=B4=E7=A7=81=E8=81=8A?= =?UTF-8?q?=E4=B8=8E=E7=BE=A4=E8=81=8A=20id=20=E5=90=8C=E5=8F=B7=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit home/index.vue 已读 watch、MessagePanel 滚动 / 侧栏 / 群资料预拉 watch 都只看 targetId, 私聊 1 切群 1 时不会触发,会把侧栏 / 新消息浮窗 / 滚动状态 / 已读上报漏掉,且不跑 ensureGroupData。 对齐多选 + 语音那两条 watch,统一改成监听 [type, targetId]。 --- src/views/im/home/index.vue | 13 ++++++++----- .../components/message/MessagePanel.vue | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/views/im/home/index.vue b/src/views/im/home/index.vue index bcfb88e21..fa04284ff 100644 --- a/src/views/im/home/index.vue +++ b/src/views/im/home/index.vue @@ -146,19 +146,22 @@ onUnmounted(() => { /** * 当前会话切换:本地清零未读 + 上报后端已读 + 私聊补"对方已读到哪条" * - * 只针对当前 active 会话做处理,其它会话已读状态由 WebSocket READ/RECEIPT 事件被动同步。 - * 私聊补一次拉对方已读位置,弥补离线 / 多端漏掉的 RECEIPT 推送 + * type+targetId 一起监听:私聊与群聊 id 同号时切换也能触发;其它会话已读状态由 WebSocket + * READ / RECEIPT 事件被动同步。私聊补一次拉对方已读位置,弥补离线 / 多端漏掉的 RECEIPT 推送 */ watch( - () => conversationStore.activeConversation?.targetId, - async (targetId) => { + () => [ + conversationStore.activeConversation?.type, + conversationStore.activeConversation?.targetId + ], + async ([type, targetId]) => { if (!targetId) { return } // 本地清零未读 + 上报后端已读,让其它端 / 对方 UI 同步 await readActive() // 私聊补一次"对方已读到哪条",弥补离线 / 多端漏掉的 RECEIPT 推送 - if (conversationStore.activeConversation?.type === ImConversationType.PRIVATE) { + if (type === ImConversationType.PRIVATE) { void syncPrivateReadStatus(targetId) } } diff --git a/src/views/im/home/pages/conversation/components/message/MessagePanel.vue b/src/views/im/home/pages/conversation/components/message/MessagePanel.vue index 3077025c5..2962ad580 100644 --- a/src/views/im/home/pages/conversation/components/message/MessagePanel.vue +++ b/src/views/im/home/pages/conversation/components/message/MessagePanel.vue @@ -573,19 +573,22 @@ watch( /** * 切换会话:清空"在不在底部"相关状态、强制滚到底部、群会话预拉资料 * - * immediate:true 让首次进入页面就能正确初始化(无需等到第一次切换) + * type+targetId 一起监听:私聊与群聊 id 同号时切换也能触发;immediate:true 让首次进入页面就能初始化 */ watch( - () => conversationStore.activeConversation?.targetId, - (targetId) => { - // 切群时上一会话的"未读累计 + 浮窗显示"必须清掉,否则会带到新会话里看起来很突兀 + () => [ + conversationStore.activeConversation?.type, + conversationStore.activeConversation?.targetId + ], + ([type, targetId]) => { + // 切会话时上一会话的「未读累计 + 浮窗显示」必须清掉,否则会带到新会话里看起来很突兀 newMessageCount.value = 0 showJumpToBottom.value = false // 抽屉里展示的群信息 / 好友信息属于上一会话,切会话时统一关掉 sideVisible.value = false scrollToBottom() // 仅群聊预拉详情 / 成员(私聊对端在首屏 fetchFriends 时就拉了) - if (targetId && conversationStore.activeConversation?.type === ImConversationType.GROUP) { + if (targetId && type === ImConversationType.GROUP) { ensureGroupData(targetId) } },