no message
This commit is contained in:
parent
24d80e69f6
commit
e71caa6d69
2
App.vue
2
App.vue
@ -40,7 +40,7 @@ export default {
|
||||
if (success) {
|
||||
console.log("IM 初始化成功");
|
||||
// IM 初始化成功后,设置全局未读消息监听
|
||||
globalUnreadListenerManager.setup();
|
||||
// globalUnreadListenerManager.setup();
|
||||
} else {
|
||||
console.warn("IM 初始化失败");
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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();
|
||||
// }
|
||||
});
|
||||
|
||||
// 处理取消申请
|
||||
|
||||
@ -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>
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user