diff --git a/pages.json b/pages.json index 4cf1292..1114629 100644 --- a/pages.json +++ b/pages.json @@ -238,6 +238,12 @@ "navigationBarTitleText": "添加病历" } }, + { + "path": "ai-medical-case-form", + "style": { + "navigationBarTitleText": "添加病历" + } + }, { "path": "service-record-detail", "style": { diff --git a/pages/case/ai-medical-case-form.vue b/pages/case/ai-medical-case-form.vue index 532e89b..89e7790 100644 --- a/pages/case/ai-medical-case-form.vue +++ b/pages/case/ai-medical-case-form.vue @@ -103,7 +103,7 @@ const FIELD_CONFIG = { key: "visitTime", label: FIELD_LABELS.visitTime, type: "date", - required: false, + required: true, }, { key: "diagnosisName", @@ -141,13 +141,13 @@ const FIELD_CONFIG = { key: "inhosDate", label: FIELD_LABELS.inhosDate, type: "date", - required: false, + required: true, }, { key: "diagnosisName", label: "住院主诊断", type: "textarea", - required: false, + required: true, }, { key: "operation", @@ -197,7 +197,7 @@ const FIELD_CONFIG = { key: "inspectTime", label: FIELD_LABELS.inspectTime, type: "date", - required: false, + required: true, }, { key: "inspectSummary", @@ -217,19 +217,19 @@ const FIELD_CONFIG = { key: "chiefComplaint", label: FIELD_LABELS.chiefComplaint, type: "textarea", - required: false, + required: true, }, { key: "presentIllnessHistory", label: FIELD_LABELS.presentIllnessHistory, type: "textarea", - required: false, + required: true, }, { key: "pastMedicalHistory", label: FIELD_LABELS.pastMedicalHistory, type: "textarea", - required: false, + required: true, }, ], }; diff --git a/pages/home/message-home.vue b/pages/home/message-home.vue index b4cc82e..2d97669 100644 --- a/pages/home/message-home.vue +++ b/pages/home/message-home.vue @@ -6,7 +6,6 @@ @team-change="handleTeamChange" @add-patient="handleAddPatient" /> - @@ -53,7 +52,7 @@ {{ - conversation.lastMessage || "暂无消息" + cleanMessageText(conversation.lastMessage) || "暂无消息" }} @@ -61,7 +60,14 @@ + + 暂无会话 + + @@ -92,7 +98,7 @@ 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 "./components/message-header.vue"; +import MessageHeader from "../home/components/message-header.vue"; // 获取登录状态 const { account, openid, isIMInitialized } = storeToRefs(useAccountStore()); @@ -156,46 +162,191 @@ const handleAddPatient = withInfo(() => { }); }); +// 立即更新未读徽章 +const updateUnreadBadgeImmediately = async () => { + try { + if (!globalTimChatManager || !globalTimChatManager.tim) { + console.warn("TIM实例不存在,无法更新徽章"); + return; + } + + const response = await globalTimChatManager.tim.getConversationList(); + + if (!response || !response.data || !response.data.conversationList) { + console.warn("获取会话列表返回数据异常"); + return; + } + + // 计算群聊总未读数 + const totalUnreadCount = response.data.conversationList + .filter( + (conv) => conv.conversationID && conv.conversationID.startsWith("GROUP") + ) + .reduce((sum, conv) => sum + (conv.unreadCount || 0), 0); + + // 更新 tabBar 徽章 - 添加错误处理,防止在非TabBar页面调用时出错 + try { + if (totalUnreadCount > 0) { + uni.setTabBarBadge({ + index: 1, + text: totalUnreadCount > 99 ? "99+" : String(totalUnreadCount), + }); + console.log("已更新 tabBar 徽章:", totalUnreadCount); + } else { + uni.removeTabBarBadge({ + index: 1, + }); + console.log("已移除 tabBar 徽章"); + } + } catch (badgeError) { + // 在非TabBar页面上调用时会出错,这是正常的,不需要处理 + if (badgeError.errMsg && badgeError.errMsg.includes("not TabBar page")) { + console.log("当前不是TabBar页面,跳过徽章更新"); + } else { + console.error("更新TabBar徽章失败:", badgeError); + } + } + } catch (error) { + console.error("更新未读徽章失败:", error); + } +}; + // 初始化IM const initIM = async () => { - if (!isIMInitialized.value) { + // 关键修复:不仅检查 isIMInitialized,还要检查实际连接状态 + const needsInit = + !isIMInitialized.value || + !globalTimChatManager || + !globalTimChatManager.isLoggedIn; + + if (needsInit) { uni.showLoading({ title: "连接中...", }); + + // 如果已初始化但连接断开,先清理旧实例 + if ( + isIMInitialized.value && + globalTimChatManager && + !globalTimChatManager.isLoggedIn + ) { + console.log("IM已初始化但连接已断开,清理旧实例后重新初始化"); + await globalTimChatManager.cleanupOldInstance(); + } + const success = await initIMAfterLogin(); uni.hideLoading(); - // if (!success) { - // uni.showToast({ - // title: "IM连接失败,请重试", - // icon: "none", - // }); - // return false; - // } - } else if (globalTimChatManager && !globalTimChatManager.isLoggedIn) { - uni.showLoading({ - title: "重连中...", - }); - const reconnected = await globalTimChatManager.ensureIMConnection(); - uni.hideLoading(); - if (!reconnected) { - return false; + if (!success) { + handleReloginIM(); + // // 显示重试提示 + // uni.showModal({ + // title: "IM连接失败", + // content: + // "连接失败,请检查网络后重试。如果IM连接失败,请重新登陆IM再连接", + // confirmText: "重新登陆", + // cancelText: "取消", + // success: (res) => { + // if (res.confirm) { + // // 重新登陆 + // handleReloginIM(); + // } + // }, + // }); + // return false; } } return true; }; +// 重新登陆IM +const handleReloginIM = async () => { + try { + uni.showLoading({ + title: "重新登陆中...", + }); + + // 清理旧的IM实例 + if (globalTimChatManager) { + await globalTimChatManager.cleanupOldInstance(); + } + + // 重新初始化IM + const { initIMAfterLogin } = useAccountStore(); + const success = await initIMAfterLogin(); + uni.hideLoading(); + + if (success) { + // uni.showToast({ + // title: "IM连接成功", + // icon: "success", + // }); + // 重新加载会话列表 + await loadConversationList(); + setupConversationListener(); + } else { + // uni.showToast({ + // title: "IM连接失败,请检查网络", + // icon: "none", + // }); + } + } catch (error) { + uni.hideLoading(); + console.error("重新登陆IM失败:", error); + // uni.showToast({ + // title: "重新登陆失败", + // icon: "none", + // }); + } +}; + // 加载会话列表 const loadConversationList = async () => { if (loading.value) return; loading.value = true; try { console.log("开始加载群聊列表"); - if (!globalTimChatManager || !globalTimChatManager.getGroupList) { - loading.value = false; - return; + + // 确保 IM 已连接 + if (!globalTimChatManager) { + throw new Error("IM管理器未初始化"); } - const result = await globalTimChatManager.getGroupList(); + + // 检查 TIM 实例是否存在 + if (!globalTimChatManager.tim) { + console.warn("TIM实例不存在,尝试重新初始化IM"); + const reinitialized = await initIMAfterLogin(); + if (!reinitialized) { + throw new Error("IM重新初始化失败"); + } + } + + // 检查是否已登录 - 这是关键检查 + if (!globalTimChatManager.isLoggedIn) { + console.warn("IM未登录,尝试重新连接"); + const reconnected = await globalTimChatManager.ensureIMConnection(); + if (!reconnected) { + throw new Error("IM重新连接失败"); + } + } + + if (!globalTimChatManager.getGroupList) { + throw new Error("IM管理器方法不可用"); + } + + // 添加超时控制,防止永久等待 + const timeoutPromise = new Promise((_, reject) => { + setTimeout( + () => reject(new Error("加载会话列表超时,请检查网络连接")), + 35000 + ); + }); + + const result = await Promise.race([ + globalTimChatManager.getGroupList(), + timeoutPromise, + ]); + if (result && result.success && result.groupList) { // 合并后端群组详细信息(已包含格式化和排序) conversationList.value = await mergeConversationWithGroupDetails( @@ -218,17 +369,26 @@ const loadConversationList = async () => { ); } else { console.error("加载群聊列表失败:", result); - uni.showToast({ - title: "加载失败,请重试", - icon: "none", - }); + throw new Error(result?.message || "加载失败,请重试"); } } catch (error) { console.error("加载会话列表失败:", error); - uni.showToast({ - title: error.message || "加载失败,请重试", - icon: "none", - }); + + // 如果是超时或连接错误,提示用户重试 + if ( + error.message && + (error.message.includes("超时") || error.message.includes("连接")) + ) { + uni.showToast({ + title: "网络连接不稳定,请重试", + icon: "none", + }); + } else { + uni.showToast({ + title: error.message || "加载失败,请重试", + icon: "none", + }); + } } finally { loading.value = false; } @@ -389,6 +549,12 @@ const setupConversationListener = () => { }); }; +// 清理消息文本(移除换行符) +const cleanMessageText = (text) => { + if (!text) return ""; + return text.replace(/[\r\n]+/g, " ").trim(); +}; + // 格式化患者姓名 const formatPatientName = (conversation) => { return conversation.patientName || "未知患者"; @@ -506,7 +672,7 @@ onShow(async () => { // 加载团队列表 await getTeams(); - // 初始化IM + // 初始化IM - 关键修复:确保IM连接状态正确 const imReady = await initIM(); if (!imReady) { console.error("IM初始化失败"); @@ -682,7 +848,10 @@ onHide(() => { color: #999; overflow: hidden; text-overflow: ellipsis; - white-space: nowrap; + display: -webkit-box; + -webkit-line-clamp: 1; + -webkit-box-orient: vertical; + word-break: break-all; } .load-more { diff --git a/pages/message/chat.scss b/pages/message/chat.scss index aa26749..a0124af 100644 --- a/pages/message/chat.scss +++ b/pages/message/chat.scss @@ -15,7 +15,8 @@ $primary-color: #0877F1; /* 患者信息栏样式 */ .patient-info-bar { - position: relative; + position: sticky; + top: 0; background: #fff; border-bottom: 1rpx solid #f0f0f0; padding: 20rpx 32rpx; @@ -87,6 +88,7 @@ $primary-color: #0877F1; flex: 1; box-sizing: border-box; overflow-x: hidden; + overflow-y: auto; min-height: 0; } diff --git a/pages/message/message.vue b/pages/message/message.vue deleted file mode 100644 index 5adc1f9..0000000 --- a/pages/message/message.vue +++ /dev/null @@ -1,856 +0,0 @@ - - - - - \ No newline at end of file