fix:问题修复
This commit is contained in:
parent
25925c1969
commit
9cbe454338
@ -1,33 +1,15 @@
|
||||
<template>
|
||||
<view class="message-page">
|
||||
<!-- 头部组件 -->
|
||||
<message-header
|
||||
v-model:activeTab="activeTab"
|
||||
@team-change="handleTeamChange"
|
||||
@add-patient="handleAddPatient"
|
||||
/>
|
||||
<message-header v-model:activeTab="activeTab" @team-change="handleTeamChange" @add-patient="handleAddPatient" />
|
||||
<!-- 消息列表 -->
|
||||
<scroll-view
|
||||
class="message-list"
|
||||
scroll-y="true"
|
||||
refresher-enabled
|
||||
:refresher-triggered="refreshing"
|
||||
@refresherrefresh="handleRefresh"
|
||||
@scrolltolower="handleLoadMore"
|
||||
>
|
||||
<scroll-view class="message-list" scroll-y="true" refresher-enabled :refresher-triggered="refreshing"
|
||||
@refresherrefresh="handleRefresh" @scrolltolower="handleLoadMore">
|
||||
<!-- 消息列表项 -->
|
||||
<view
|
||||
v-for="conversation in filteredConversationList"
|
||||
:key="conversation.groupID || conversation.conversationID"
|
||||
class="message-item"
|
||||
@click="handleClickConversation(conversation)"
|
||||
>
|
||||
<view v-for="conversation in filteredConversationList" :key="conversation.groupID || conversation.conversationID"
|
||||
class="message-item" @click="handleClickConversation(conversation)">
|
||||
<view class="avatar-container">
|
||||
<image
|
||||
class="avatar"
|
||||
:src="conversation.avatar || '/static/default-patient-avatar.png'"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<image class="avatar" :src="conversation.avatar || '/static/default-patient-avatar.png'" mode="aspectFill" />
|
||||
<view v-if="conversation.unreadCount > 0" class="unread-badge">
|
||||
<text class="unread-text">{{
|
||||
conversation.unreadCount > 99 ? "99+" : conversation.unreadCount
|
||||
@ -39,10 +21,7 @@
|
||||
<view class="header">
|
||||
<view class="name-info">
|
||||
<text class="name">{{ formatPatientName(conversation) }}</text>
|
||||
<text
|
||||
v-if="conversation.patientSex || conversation.patientAge"
|
||||
class="patient-info"
|
||||
>
|
||||
<text v-if="conversation.patientSex || conversation.patientAge" class="patient-info">
|
||||
{{ formatPatientInfo(conversation) }}
|
||||
</text>
|
||||
</view>
|
||||
@ -59,17 +38,11 @@
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view
|
||||
v-if="!loading && conversationList.length === 0"
|
||||
class="empty-container"
|
||||
>
|
||||
<view v-if="!loading && conversationList.length === 0" class="empty-container">
|
||||
<image class="empty-image" src="/static/empty.svg" mode="aspectFit" />
|
||||
<text class="empty-text">暂无会话</text>
|
||||
</view>
|
||||
<view
|
||||
v-else-if="!loading && filteredConversationList.length === 0"
|
||||
class="empty-container"
|
||||
>
|
||||
<view v-else-if="!loading && filteredConversationList.length === 0" class="empty-container">
|
||||
<image class="empty-image" src="/static/empty.svg" mode="aspectFit" />
|
||||
<text class="empty-text">{{
|
||||
activeTab === "processing" ? "暂无处理中的会话" : "暂无已结束的会话"
|
||||
@ -77,10 +50,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view
|
||||
v-if="hasMore && filteredConversationList.length > 0"
|
||||
class="load-more"
|
||||
>
|
||||
<view v-if="hasMore && filteredConversationList.length > 0" class="load-more">
|
||||
<text class="load-more-text">{{
|
||||
loadingMore ? "加载中..." : "上拉加载更多"
|
||||
}}</text>
|
||||
@ -393,28 +363,51 @@ const setupConversationListener = () => {
|
||||
globalTimChatManager.setCallback("onConversationListUpdated", (eventData) => {
|
||||
console.log("会话列表更新事件:", eventData);
|
||||
|
||||
// 处理单个会话更新(标记已读的情况)
|
||||
if (eventData && !Array.isArray(eventData) && eventData.conversationID) {
|
||||
const conversationID = eventData.conversationID;
|
||||
// 兼容单个会话更新,以及 { reason, conversation, message } 的增量事件结构。
|
||||
const conversationUpdate = eventData?.conversation || eventData;
|
||||
if (
|
||||
conversationUpdate &&
|
||||
!Array.isArray(conversationUpdate) &&
|
||||
conversationUpdate.conversationID
|
||||
) {
|
||||
const conversationID = conversationUpdate.conversationID;
|
||||
const existingIndex = conversationList.value.findIndex(
|
||||
(conv) => conv.conversationID === conversationID
|
||||
);
|
||||
|
||||
if (existingIndex !== -1) {
|
||||
// 直接更新未读数,避免触发整个对象的响应式更新
|
||||
if (eventData.unreadCount !== undefined) {
|
||||
conversationList.value[existingIndex].unreadCount =
|
||||
eventData.unreadCount;
|
||||
console.log(
|
||||
`已清空会话未读数: ${conversationList.value[existingIndex].name}, unreadCount: ${eventData.unreadCount}`
|
||||
const conversation = conversationList.value[existingIndex];
|
||||
const lastMessageTimeChanged =
|
||||
conversationUpdate.lastMessageTime !== undefined &&
|
||||
conversation.lastMessageTime !== conversationUpdate.lastMessageTime;
|
||||
|
||||
if (conversationUpdate.lastMessage !== undefined) {
|
||||
conversation.lastMessage = conversationUpdate.lastMessage;
|
||||
}
|
||||
if (conversationUpdate.lastMessageTime !== undefined) {
|
||||
conversation.lastMessageTime = conversationUpdate.lastMessageTime;
|
||||
}
|
||||
if (conversationUpdate.unreadCount !== undefined) {
|
||||
conversation.unreadCount = conversationUpdate.unreadCount;
|
||||
}
|
||||
|
||||
if (lastMessageTimeChanged) {
|
||||
conversationList.value.sort(
|
||||
(a, b) => b.lastMessageTime - a.lastMessageTime
|
||||
);
|
||||
}
|
||||
console.log(`已更新会话: ${conversation.name}`, conversationUpdate);
|
||||
} else {
|
||||
// 增量事件未携带患者、团队等展示信息,重新拉取完整列表。
|
||||
loadConversationList();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!eventData || !Array.isArray(eventData)) {
|
||||
console.warn("会话列表更新事件数据格式错误");
|
||||
console.log('eventData: ', typeof eventData)
|
||||
console.log(typeof eventData === 'object' && eventData ? JSON.stringify(eventData) : eventData);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, onUnmounted, nextTick, watch, computed } from "vue";
|
||||
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import { onLoad, onShow, onHide, onUnload } from "@dcloudio/uni-app";
|
||||
import { storeToRefs } from "pinia";
|
||||
import useAccountStore from "@/store/account.js";
|
||||
import { globalTimChatManager } from "@/utils/tim-chat.js";
|
||||
@ -941,9 +941,14 @@ const handleSendFollowUpMessage = async (data) => {
|
||||
// 页面隐藏
|
||||
onHide(() => {
|
||||
stopIMMonitoring();
|
||||
// 清空当前会话ID,避免离开页面后收到的消息被错误标记为已读
|
||||
});
|
||||
|
||||
// 仅在真正离开页面时清空会话,息屏/切后台触发 onHide 时仍需接收当前会话的新消息。
|
||||
onUnload(() => {
|
||||
if (timChatManager.currentConversationID === chatInfo.value.conversationID) {
|
||||
timChatManager.currentConversationID = null;
|
||||
console.log("✓ 页面隐藏,已清空当前会话ID");
|
||||
console.log("✓ 页面卸载,已清空当前会话ID");
|
||||
}
|
||||
});
|
||||
|
||||
const sendCommonPhrase = async (phraseOrContent) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user