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"
>
-
-
- 加载中...
-
-