From efe1b2994e3ef218f7bd10a9c4c058e1e2db2277 Mon Sep 17 00:00:00 2001 From: wangdongbo <949818794@qq.com> Date: Wed, 11 Feb 2026 17:49:48 +0800 Subject: [PATCH] no message --- pages/message/index.vue | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/pages/message/index.vue b/pages/message/index.vue index 50c01ef..f259a1c 100644 --- a/pages/message/index.vue +++ b/pages/message/index.vue @@ -217,6 +217,7 @@ const timChatManager = globalTimChatManager; const PENDING_FOLLOWUP_SEND_STORAGE_KEY = "ykt_followup_pending_send"; const pendingFollowUpSendConsumed = ref(false); const initialMessageListLoaded = ref(false); +const isCallbacksInitialized = ref(false); // 标记回调是否已初始化 function normalizeGroupId(v) { const s = String(v || "").trim(); @@ -515,6 +516,9 @@ const checkLoginAndInitTIM = async () => { // 初始化IM回调函数 const initTIMCallbacks = async () => { + // 标记回调已初始化 + isCallbacksInitialized.value = true; + timChatManager.setCallback("onSDKReady", () => { if (messageList.value.length === 0 && !isLoading.value) { loadMessageList(); @@ -901,13 +905,46 @@ onShow(() => { if (!isIMInitialized.value) { checkLoginAndInitTIM(); } else if (timChatManager.tim && !timChatManager.isLoggedIn) { - timChatManager.ensureIMConnection(); + // IM未登录,尝试重连 + timChatManager.ensureIMConnection().then(() => { + // 重连成功后重新注册回调 + if (timChatManager.isLoggedIn && chatInfo.value.conversationID) { + console.log("✓ 重连成功,重新注册消息监听回调"); + initTIMCallbacks(); + timChatManager.setConversationID(chatInfo.value.conversationID); + } + }); } else if ( timChatManager.tim && timChatManager.isLoggedIn && chatInfo.value.conversationID - ) + ) { + // IM已登录,只需要重新设置会话ID,不重新注册回调(避免影响正在发送的消息) + console.log("✓ 页面显示,重新设置当前会话ID"); + timChatManager.setConversationID(chatInfo.value.conversationID); + + // 如果回调未初始化,才进行初始化 + if (!isCallbacksInitialized.value) { + console.log("✓ 回调未初始化,进行初始化"); + initTIMCallbacks(); + } + + // 标记会话为已读 + if (timChatManager.tim && timChatManager.isLoggedIn) { + timChatManager.tim + .setMessageRead({ + conversationID: chatInfo.value.conversationID, + }) + .then(() => { + console.log("✓ 页面显示时已标记会话为已读"); + }) + .catch((error) => { + console.error("✗ 标记会话已读失败:", error); + }); + } + startIMMonitoring(30000); + } // 监听回访任务发送事件 uni.$on("send-followup-message", handleSendFollowUpMessage);