fix:问题修复
This commit is contained in:
parent
25925c1969
commit
9cbe454338
@ -1,37 +1,19 @@
|
||||
<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
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -39,75 +21,63 @@
|
||||
<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>
|
||||
<text class="time">{{
|
||||
formatMessageTime(conversation.lastMessageTime)
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="message-preview">
|
||||
<text class="preview-text">{{
|
||||
cleanMessageText(conversation.lastMessage) || "暂无消息"
|
||||
}}</text>
|
||||
}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</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" ? "暂无处理中的会话" : "暂无已结束的会话"
|
||||
}}</text>
|
||||
}}</text>
|
||||
</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>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="subscribe-entry" @click="handleSubscribeReminder">
|
||||
<text class="subscribe-entry-text">接收提醒</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from "vue";
|
||||
}}</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="subscribe-entry" @click="handleSubscribeReminder">
|
||||
<text class="subscribe-entry-text">接收提醒</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from "vue";
|
||||
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import { storeToRefs } from "pinia";
|
||||
import useAccountStore from "@/store/account.js";
|
||||
import useTeamStore from "@/store/team.js";
|
||||
import useInfoCheck from "@/hooks/useInfoCheck.js";
|
||||
import { globalTimChatManager } from "@/utils/tim-chat.js";
|
||||
import { mergeConversationWithGroupDetails } from "@/utils/conversation-merger.js";
|
||||
import MessageHeader from "../home/components/message-header.vue";
|
||||
import { requestConversationSubscribeMessage } from "@/utils/subscribe-message";
|
||||
import {
|
||||
SUBSCRIBE_MESSAGE_ROLE,
|
||||
SUBSCRIBE_MESSAGE_SCENE,
|
||||
} from "@/utils/subscribe-message-config";
|
||||
import useInfoCheck from "@/hooks/useInfoCheck.js";
|
||||
import { globalTimChatManager } from "@/utils/tim-chat.js";
|
||||
import { mergeConversationWithGroupDetails } from "@/utils/conversation-merger.js";
|
||||
import MessageHeader from "../home/components/message-header.vue";
|
||||
import { requestConversationSubscribeMessage } from "@/utils/subscribe-message";
|
||||
import {
|
||||
SUBSCRIBE_MESSAGE_ROLE,
|
||||
SUBSCRIBE_MESSAGE_SCENE,
|
||||
} from "@/utils/subscribe-message-config";
|
||||
|
||||
// 获取登录状态
|
||||
const { account, openid, isIMInitialized, doctorInfo } = storeToRefs(
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -642,29 +635,29 @@ const handleLoadMore = () => {
|
||||
};
|
||||
|
||||
// 下拉刷新
|
||||
const handleRefresh = async () => {
|
||||
refreshing.value = true;
|
||||
try {
|
||||
await loadConversationList();
|
||||
} finally {
|
||||
refreshing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubscribeReminder = async () => {
|
||||
await requestConversationSubscribeMessage({
|
||||
role: SUBSCRIBE_MESSAGE_ROLE.DOCTOR,
|
||||
scene: SUBSCRIBE_MESSAGE_SCENE.LIST,
|
||||
userId: doctorInfo.value?.userid || account.value?.userId || "",
|
||||
openid: openid.value || account.value?.openid || "",
|
||||
unionid: account.value?.unionid || "",
|
||||
doctorId: doctorInfo.value?.userid || "",
|
||||
extraData: {
|
||||
teamId: currentTeamId.value || "",
|
||||
page: "pages/home/message-home",
|
||||
},
|
||||
});
|
||||
};
|
||||
const handleRefresh = async () => {
|
||||
refreshing.value = true;
|
||||
try {
|
||||
await loadConversationList();
|
||||
} finally {
|
||||
refreshing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubscribeReminder = async () => {
|
||||
await requestConversationSubscribeMessage({
|
||||
role: SUBSCRIBE_MESSAGE_ROLE.DOCTOR,
|
||||
scene: SUBSCRIBE_MESSAGE_SCENE.LIST,
|
||||
userId: doctorInfo.value?.userid || account.value?.userId || "",
|
||||
openid: openid.value || account.value?.openid || "",
|
||||
unionid: account.value?.unionid || "",
|
||||
doctorId: doctorInfo.value?.userid || "",
|
||||
extraData: {
|
||||
teamId: currentTeamId.value || "",
|
||||
page: "pages/home/message-home",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 页面加载
|
||||
onLoad(() => {
|
||||
@ -864,36 +857,36 @@ onHide(() => {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.load-more-text {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.subscribe-entry {
|
||||
position: fixed;
|
||||
right: 32rpx;
|
||||
bottom: 180rpx;
|
||||
width: 116rpx;
|
||||
height: 116rpx;
|
||||
border-radius: 58rpx;
|
||||
background: #fff;
|
||||
border: 2rpx solid #3876f6;
|
||||
box-shadow: 0 8rpx 24rpx rgba(56, 118, 246, 0.16);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.subscribe-entry:active {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.subscribe-entry-text {
|
||||
width: 56rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.4;
|
||||
color: #3876f6;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
.load-more-text {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.subscribe-entry {
|
||||
position: fixed;
|
||||
right: 32rpx;
|
||||
bottom: 180rpx;
|
||||
width: 116rpx;
|
||||
height: 116rpx;
|
||||
border-radius: 58rpx;
|
||||
background: #fff;
|
||||
border: 2rpx solid #3876f6;
|
||||
box-shadow: 0 8rpx 24rpx rgba(56, 118, 246, 0.16);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.subscribe-entry:active {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.subscribe-entry-text {
|
||||
width: 56rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.4;
|
||||
color: #3876f6;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -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,避免离开页面后收到的消息被错误标记为已读
|
||||
timChatManager.currentConversationID = null;
|
||||
console.log("✓ 页面隐藏,已清空当前会话ID");
|
||||
});
|
||||
|
||||
// 仅在真正离开页面时清空会话,息屏/切后台触发 onHide 时仍需接收当前会话的新消息。
|
||||
onUnload(() => {
|
||||
if (timChatManager.currentConversationID === chatInfo.value.conversationID) {
|
||||
timChatManager.currentConversationID = null;
|
||||
console.log("✓ 页面卸载,已清空当前会话ID");
|
||||
}
|
||||
});
|
||||
|
||||
const sendCommonPhrase = async (phraseOrContent) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user