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