diff --git a/apps/web-antd/src/app.vue b/apps/web-antd/src/app.vue index b5dce8d7..ea81f39f 100644 --- a/apps/web-antd/src/app.vue +++ b/apps/web-antd/src/app.vue @@ -71,7 +71,7 @@ const initWebsocket = () => { // 当userInfo加载完成后再执行初始化 watch(userInfoLoaded, (loaded) => { if (loaded) { - // initWebsocket(); + initWebsocket(); } }); diff --git a/apps/web-antd/src/store/prescription.ts b/apps/web-antd/src/store/prescription.ts index 1a20127c..5322d8ef 100644 --- a/apps/web-antd/src/store/prescription.ts +++ b/apps/web-antd/src/store/prescription.ts @@ -79,9 +79,9 @@ export const usePrescriptionStore = defineStore('prescription', () => { const methodSelected = ref(); const syndromeSelected = ref(); - // 获取localStorage key + // 获取localStorage key(修改为在线复诊前缀) const getStorageKey = () => - `prescriptionData-chat-${currentRegisterId.value}`; + `onlineConsultation-prescriptionData${currentRegisterId.value}`; // 计算属性 const totalProductCost = computed(() => { @@ -188,9 +188,10 @@ export const usePrescriptionStore = defineStore('prescription', () => { }; // 完整初始化(包含患者信息,仅用于 PrescriptionModal) - const initializePrescription = async (registerId: number | string) => { - console.log('初始化处方,registerId:', registerId); - + const initializePrescription = async ( + registerId: number | string, + shouldFetchPatientInfo: boolean = false + ) => { // 设置当前注册ID currentRegisterId.value = registerId; @@ -202,13 +203,15 @@ export const usePrescriptionStore = defineStore('prescription', () => { await initializeBasicData(); } - // 获取患者信息(只在 PrescriptionModal 中调用) + // 获取患者信息(只在需要时调用,如 PrescriptionModal) + if (shouldFetchPatientInfo) { if ( !isPatientInfoLoaded.value || patientInfo.value?.register_id !== registerId ) { await getPatientInfo(); isPatientInfoLoaded.value = true; + } } }; @@ -641,7 +644,7 @@ export const usePrescriptionStore = defineStore('prescription', () => { total: totalCost.value, category: category.value, drug_type: 2, - register_id: patientInfo.value.id, + register_id: currentRegisterId.value, treatment_price: treatmentPrice.value, package_method_id: packageMethodId.value, process_rule_id: processRuleId.value, @@ -661,22 +664,28 @@ export const usePrescriptionStore = defineStore('prescription', () => { message.success('处方已发送'); sendMessage({ roomId: chatStore.currentFriend.room_id, - senderId: userStore.currentUser.id, + senderId: userStore.currentUser.doctor_id, receiverId: chatStore.currentFriend.id, type: 'prescription', content: JSON.stringify(res), }); chatStore.addMessage( { - roomId: chatStore.currentFriend.room_id, - senderId: userStore.currentUser.id, - receiverId: chatStore.currentFriend.id, - type: 'prescription', - content: res, + id: Date.now().toString(), + room_id: chatStore.currentFriend.room_id, + sender_user_id: `doctor-${userStore.currentUser.doctor_id}`, + receiver_user_id: chatStore.currentFriend.id, + message_type: 4, + message_content: JSON.stringify(res), + messageTypeName: 'prescription', + created_at: Date.now(), + created_at_text: new Date().toLocaleTimeString().slice(0, 5), + timestamp: Date.now(), isSent: true, - time: new Date().toLocaleTimeString().slice(0, 5), + read: true, + duration: 0, }, - userStore.currentUser.id, + userStore.currentUser.doctor_id, ); resetForm(); }); @@ -704,7 +713,7 @@ export const usePrescriptionStore = defineStore('prescription', () => { activeCategory.value = categoryValue; updateCurrentDrugs([]); localStorage.setItem( - `activeCategory-chat-${currentRegisterId.value}`, + `onlineConsultation-activeCategory${currentRegisterId.value}`, categoryValue.toString(), ); }; diff --git a/apps/web-antd/src/store/usePrescription.ts b/apps/web-antd/src/store/usePrescription.ts index 1ec90915..15f6442a 100644 --- a/apps/web-antd/src/store/usePrescription.ts +++ b/apps/web-antd/src/store/usePrescription.ts @@ -61,8 +61,8 @@ export const usePrescriptionStore = () => { const doctorSecondSign = ref(0) const checkData = ref({}) - // 获取localStorage key - const getStorageKey = () => `prescriptionData-chat-${currentRegisterId.value}` + // 获取localStorage key(修改为在线复诊前缀) + const getStorageKey = () => `onlineConsultation-prescriptionData${currentRegisterId.value}` // 计算属性 const totalProductCost = computed(() => { @@ -579,7 +579,7 @@ export const usePrescriptionStore = () => { const changeCategory = (categoryValue: number) => { activeCategory.value = categoryValue updateCurrentDrugs([]) - localStorage.setItem(`activeCategory-chat-${currentRegisterId.value}`, categoryValue.toString()) + localStorage.setItem(`onlineConsultation-activeCategory${currentRegisterId.value}`, categoryValue.toString()) } // 工具函数 diff --git a/apps/web-antd/src/views/business/chat/components/AudioMessage.vue b/apps/web-antd/src/views/business/chat/components/AudioMessage.vue index eafbea3f..0dc97b41 100644 --- a/apps/web-antd/src/views/business/chat/components/AudioMessage.vue +++ b/apps/web-antd/src/views/business/chat/components/AudioMessage.vue @@ -91,7 +91,8 @@ const getAudioDuration = () => { } // 否则创建临时音频获取元数据 - const tempAudio = new Audio(props.message.content); + const audioUrl = props.message.message_content || props.message.content || ''; + const tempAudio = new Audio(audioUrl); tempAudio.addEventListener('loadedmetadata', () => { if (tempAudio.duration && tempAudio.duration > 0) { audioDuration.value = Math.round(tempAudio.duration); @@ -180,7 +181,8 @@ const getWaveHeight = (index) => { const togglePlay = () => { if (!audio.value) { - audio.value = new Audio(props.message.content); + const audioUrl = props.message.message_content || props.message.content || ''; + audio.value = new Audio(audioUrl); // 确保获取音频时长 audio.value.addEventListener('loadedmetadata', () => { diff --git a/apps/web-antd/src/views/business/chat/components/ChatHeader.vue b/apps/web-antd/src/views/business/chat/components/ChatHeader.vue index 2e7c00af..2049e771 100644 --- a/apps/web-antd/src/views/business/chat/components/ChatHeader.vue +++ b/apps/web-antd/src/views/business/chat/components/ChatHeader.vue @@ -102,7 +102,7 @@ const viewFriendProfile = () => {