From ec2d76a382e02b57e51011b03d94c6b31233b965 Mon Sep 17 00:00:00 2001 From: wangdongbo <949818794@qq.com> Date: Wed, 28 Jan 2026 17:50:58 +0800 Subject: [PATCH] =?UTF-8?q?IM=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/message/index.vue | 31 ++++++- pages/message/message.vue | 178 +++++++++++++++++--------------------- store/account.js | 12 +-- utils/tim-chat.js | 116 ++++++++++++++++++++----- 4 files changed, 210 insertions(+), 127 deletions(-) diff --git a/pages/message/index.vue b/pages/message/index.vue index debd6fb..131a069 100644 --- a/pages/message/index.vue +++ b/pages/message/index.vue @@ -388,6 +388,25 @@ const initTIMCallbacks = async () => { nextTick(() => { scrollToBottom(true); }); + + // 立即标记会话为已读,确保未读数为0 + if (timChatManager.tim && timChatManager.isLoggedIn && chatInfo.value.conversationID) { + timChatManager.tim + .setMessageRead({ + conversationID: chatInfo.value.conversationID, + }) + .then(() => { + console.log("✓ 收到新消息后已标记为已读"); + // 触发会话列表更新,确保未读数为0 + timChatManager.triggerCallback('onConversationListUpdated', { + conversationID: chatInfo.value.conversationID, + unreadCount: 0 + }); + }) + .catch((error) => { + console.error("✗ 标记已读失败:", error); + }); + } } }); @@ -526,21 +545,27 @@ const loadMessageList = async () => { timChatManager.enterConversation(chatInfo.value.conversationID || "test1"); - // 标记会话为已读 + // 标记会话为已读 - 确保清空未读数 if ( timChatManager.tim && timChatManager.isLoggedIn && chatInfo.value.conversationID ) { + console.log("标记会话为已读:", chatInfo.value.conversationID); timChatManager.tim .setMessageRead({ conversationID: chatInfo.value.conversationID, }) .then(() => { - console.log("会话已标记为已读:", chatInfo.value.conversationID); + console.log("✓ 会话已标记为已读:", chatInfo.value.conversationID); + // 触发会话列表更新回调,通知消息列表页面清空未读数 + timChatManager.triggerCallback('onConversationListUpdated', { + conversationID: chatInfo.value.conversationID, + unreadCount: 0 + }); }) .catch((error) => { - console.error("标记会话已读失败:", error); + console.error("✗ 标记会话已读失败:", error); }); } }; diff --git a/pages/message/message.vue b/pages/message/message.vue index f89ffb2..5a18dd7 100644 --- a/pages/message/message.vue +++ b/pages/message/message.vue @@ -9,14 +9,6 @@ @refresherrefresh="handleRefresh" @scrolltolower="handleLoadMore" > - - - 加载中... - -