no message

This commit is contained in:
wangdongbo 2026-02-12 12:04:57 +08:00
parent 24d80e69f6
commit e71caa6d69
5 changed files with 47 additions and 28 deletions

View File

@ -40,7 +40,7 @@ export default {
if (success) {
console.log("IM 初始化成功");
// IM
globalUnreadListenerManager.setup();
// globalUnreadListenerManager.setup();
} else {
console.warn("IM 初始化失败");
}

View File

@ -1,6 +1,5 @@
import { ref, computed } from 'vue'
import { onShow, onUnload } from '@dcloudio/uni-app'
import { storeToRefs } from 'pinia'
import { onShow } from '@dcloudio/uni-app'
import api from '@/utils/api.js'
import useTeamStore from '@/store/team.js'
import useAccountStore from '@/store/account.js'
@ -57,12 +56,15 @@ export default function useGroupChat(groupID) {
return member.isTeamMember ? '/static/default-avatar.png' : '/static/default-patient-avatar.png'
}
// 获取群聊信息和成员头像
async function getGroupInfo() {
const gid = typeof groupID === 'string' ? groupID : groupID.value
if (!gid) return
try {
console.log('开始获取群组信息groupId:', gid)
// 1. 获取群聊基本信息
const groupResult = await api('getGroupListByGroupId', { groupId: gid })
@ -74,11 +76,16 @@ export default function useGroupChat(groupID) {
teamId: groupResult.data.teamId
}
console.log('群组基本信息:', groupInfo.value)
// 2. 如果有teamId获取团队成员头像和名称
if (groupResult.data.teamId) {
console.log('开始获取团队成员信息teamId:', groupResult.data.teamId)
const memberMap = await teamStore.getTeamMemberAvatarsAndName(groupResult.data.teamId)
console.log('团队成员信息返回:', memberMap)
// 3. 存储团队成员ID列表
teamMemberIds.value = Object.keys(memberMap)
@ -93,6 +100,8 @@ export default function useGroupChat(groupID) {
}
})
console.log('团队成员列表已构建:', members.value)
// 5. 添加患者信息(使用默认患者头像)
if (groupResult.data.patient) {
const pid = groupResult.data.patientId?.toString() || ''
@ -104,7 +113,16 @@ export default function useGroupChat(groupID) {
isTeamMember: false,
miniAppId: groupResult.data.patient.miniAppId || '' // 患者的聊天 userID
})
console.log('患者信息已添加:', {
id: pid,
name: groupResult.data.patient.name,
miniAppId: groupResult.data.patient.miniAppId
})
}
console.log('最终成员列表:', members.value)
console.log('chatMember映射:', chatMember.value)
}
}
} catch (error) {
@ -113,12 +131,10 @@ export default function useGroupChat(groupID) {
}
onShow(() => {
debugger
getGroupInfo()
})
onUnload(() => {
// 清理资源
})
return {
groupInfo,

View File

@ -444,7 +444,7 @@ function getBubbleClass(message) {
}
//
onLoad((options) => {
onLoad(async (options) => {
groupId.value = options.groupID || "";
messageList.value = [];
isLoading.value = false;
@ -473,6 +473,9 @@ onLoad((options) => {
}
});
// chatMember
await getGroupInfo();
checkLoginAndInitTIM();
updateNavigationTitle();
});
@ -563,7 +566,7 @@ const initTIMCallbacks = async () => {
.then(async () => {
console.log("✓ 收到新消息后已标记为已读");
// tabBar
await globalUnreadListenerManager.refreshBadge();
// await globalUnreadListenerManager.refreshBadge();
})
.catch((error) => {
console.error("✗ 标记已读失败:", error);
@ -717,7 +720,7 @@ const loadMessageList = async () => {
.then(async () => {
console.log("✓ 会话已标记为已读:", chatInfo.value.conversationID);
// tabBar
await globalUnreadListenerManager.refreshBadge();
// await globalUnreadListenerManager.refreshBadge();
})
.catch((error) => {
console.error("✗ 标记会话已读失败:", error);
@ -913,10 +916,10 @@ onHide(() => {
timChatManager.currentConversationID = null;
console.log("✓ 页面隐藏已清空当前会话ID");
// tabBar
if (globalUnreadListenerManager.isInitialized) {
globalUnreadListenerManager.refreshBadge();
}
// // tabBar
// if (globalUnreadListenerManager.isInitialized) {
// globalUnreadListenerManager.refreshBadge();
// }
});
//

View File

@ -380,8 +380,8 @@ const setupConversationListener = () => {
//
//
if (globalUnreadListenerManager.isInitialized) {
globalUnreadListenerManager.addCallback("onConversationListUpdated", handleConversationListUpdate);
globalUnreadListenerManager.addCallback("onMessageReceived", handleMessageReceived);
// globalUnreadListenerManager.addCallback("onConversationListUpdated", handleConversationListUpdate);
// globalUnreadListenerManager.addCallback("onMessageReceived", handleMessageReceived);
console.log("【消息列表页】已添加回调到全局监听器回调链");
} else {
console.warn("【消息列表页】全局未读监听器未初始化,使用直接回调方式");
@ -454,7 +454,7 @@ const handleClickConversation = async (conversation) => {
console.log("✓ 已标记会话为已读:", conversation.conversationID);
// tabBar
await globalUnreadListenerManager.refreshBadge();
// await globalUnreadListenerManager.refreshBadge();
} catch (error) {
console.error("✗ 标记会话已读失败:", error);
}
@ -514,9 +514,9 @@ const cleanMessageText = (text) => {
//
onShow(async () => {
// tabBar
if (globalUnreadListenerManager.isInitialized) {
await globalUnreadListenerManager.refreshBadge();
}
// if (globalUnreadListenerManager.isInitialized) {
// await globalUnreadListenerManager.refreshBadge();
// }
});
//
@ -544,12 +544,12 @@ onUnmounted(() => {
updateTimer = null;
}
//
if (globalUnreadListenerManager.isInitialized) {
globalUnreadListenerManager.removeCallback("onConversationListUpdated", handleConversationListUpdate);
globalUnreadListenerManager.removeCallback("onMessageReceived", handleMessageReceived);
console.log("【消息列表页】已从回调链移除回调");
}
// //
// if (globalUnreadListenerManager.isInitialized) {
// globalUnreadListenerManager.removeCallback("onConversationListUpdated", handleConversationListUpdate);
// globalUnreadListenerManager.removeCallback("onMessageReceived", handleMessageReceived);
// console.log("");
// }
});
</script>

View File

@ -79,7 +79,7 @@ export default defineStore("accountStore", () => {
console.log('IM 初始化成功');
// IM 初始化成功后,设置全局未读消息监听
globalUnreadListenerManager.setup();
// globalUnreadListenerManager.setup();
return true;
} catch (error) {
@ -99,7 +99,7 @@ export default defineStore("accountStore", () => {
// 清除全局未读监听
if (globalUnreadListenerManager.isInitialized) {
globalUnreadListenerManager.destroy();
// globalUnreadListenerManager.destroy();
}
} catch (error) {
console.error('退出腾讯IM失败:', error);