diff --git a/src/stores/remote-ws-store.ts b/src/stores/remote-ws-store.ts index 76a824d..fff5bca 100644 --- a/src/stores/remote-ws-store.ts +++ b/src/stores/remote-ws-store.ts @@ -178,7 +178,7 @@ export const useRemoteWsStore = defineStore("remoteWs", { if (patient && !patient['vitalWS']) { patient['vitalWS'] = new WebSocket(vitalUrl) patient['vitalWS'].onopen = function () { - ElMessage.info("远程控制" + index + ",生命体征数据连接成功") + ElMessage.info("远程控制" + (index + 1) + ",生命体征数据连接成功") patient['vitalWS'].send(JSON.stringify({ patientName: name, idNum: id, @@ -188,7 +188,7 @@ export const useRemoteWsStore = defineStore("remoteWs", { } patient['vitalWS'].onerror = () => { - ElMessage.error("远程管理" + (index + 1) + "出错") + ElMessage.error("远程管理" + (index + 1) + "生命体征数据出错") } delete this.closeStatus[name + id + date + index + 'vitalWS'] } @@ -208,7 +208,13 @@ export const useRemoteWsStore = defineStore("remoteWs", { }, vitalOnclose(name: string, id: string, date: string, index: number, cb: any) { const patient: any = this.patient[name + id + date + index] - patient.vitalWS.onclose = cb + const status = this.getCloseStatus() + patient.vitalWS.onclose = () => { + if (!status[name + id + date + index + 'vitalWS']) { + delete patient.vitalWS + cb() + } + } }, unsubscribeVital(name: string, id: string, date: string, index: number) { const patient: any = this.patient[name + id + date + index] @@ -250,7 +256,7 @@ export const useRemoteWsStore = defineStore("remoteWs", { if (patient && !patient['chatWS']) { patient['chatWS'] = new WebSocket(chatUrl) patient['chatWS'].onopen = function () { - ElMessage.info("远程控制" + index + ",通讯连接成功") + ElMessage.info("远程控制" + (index + 1) + ",通讯连接成功") patient['chatWS'].send(JSON.stringify({ patientName: name, idNum: id, @@ -260,7 +266,7 @@ export const useRemoteWsStore = defineStore("remoteWs", { } patient['chatWS'].onerror = () => { - ElMessage.error("远程管理" + (index + 1) + "出错") + ElMessage.error("远程控制" + (index + 1) + "通讯出错") } delete this.closeStatus[name + id + date + index + 'chatWS'] } @@ -280,7 +286,13 @@ export const useRemoteWsStore = defineStore("remoteWs", { }, chatOnclose(name: string, id: string, date: string, index: number, cb: any) { const patient: any = this.patient[name + id + date + index] - patient.chatWS.onclose = cb + patient.chatWS.onclose = () => { + const status = this.getCloseStatus() + if (!status[name + id + date + index + 'chatWS']) { + delete patient.chatWS + cb() + } + } }, unsubscribeChat(name: string, id: string, date: string, index: number) { const patient: any = this.patient[name + id + date + index] diff --git a/src/views/remote-manage/part/remote-item-part.vue b/src/views/remote-manage/part/remote-item-part.vue index 5291a35..ed77f52 100644 --- a/src/views/remote-manage/part/remote-item-part.vue +++ b/src/views/remote-manage/part/remote-item-part.vue @@ -104,13 +104,10 @@ function subscribeVital() { function wsClose() { remoteWsStore.vitalOnclose(remoteTask.value.patient, remoteTask.value.patientId, remoteTask.value.date, props.index, () => { - const status = remoteWsStore.getCloseStatus() - if (remoteTask.value.patient && !status[remoteTask.value.patient + remoteTask.value.patientId + remoteTask.value.date + props.index + 'vitalWS']) { - setTimeout(() => { - ElMessage.info('远程控制' + props.index + ', 生命体征数据连接断开,正在尝试重连……') - initData() - }, 3000) - } + setTimeout(() => { + ElMessage.info('远程控制' + props.index + ', 生命体征数据连接断开,正在尝试重连……') + initData() + }, 3000) }) } diff --git a/src/views/remote-manage/part/remote-part.vue b/src/views/remote-manage/part/remote-part.vue index 085518f..7c1cafb 100644 --- a/src/views/remote-manage/part/remote-part.vue +++ b/src/views/remote-manage/part/remote-part.vue @@ -166,14 +166,11 @@ function initData() { if (remoteItem.value && remoteItem.value.patient) { remoteWsStore.createVital(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex) remoteWsStore.vitalOnclose(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex, () => { - const status = remoteWsStore.getCloseStatus() - if (remoteItem.value.patient && !status[remoteItem.value.patient + remoteItem.value.patientId + remoteItem.value.date + currentIndex + 'vitalWS']) { - setTimeout(() => { - ElMessage.info('远程控制' + currentIndex + ', 生命体征数据连接断开,正在尝试重连……') - remoteWsStore.createVital(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex) - initData() - }, 3000) - } + setTimeout(() => { + ElMessage.info('远程控制' + (currentIndex + 1) + ', 生命体征数据连接断开,正在尝试重连……') + remoteWsStore.createVital(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex) + initData() + }, 3000) }) getData() } diff --git a/src/views/remote-manage/remote-control.vue b/src/views/remote-manage/remote-control.vue index 3cd1c0b..508cdc3 100644 --- a/src/views/remote-manage/remote-control.vue +++ b/src/views/remote-manage/remote-control.vue @@ -304,13 +304,10 @@ const subscribeVital = () => { updateMedicineTable(data.aiMedicineList[0], undefined); }) remoteWsStore.vitalOnclose(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentIndex, () => { - const status = remoteWsStore.getCloseStatus() - if (currentRemote.value.patient && !status[currentRemote.value.patient + currentRemote.value.patientId + currentRemote.value.date + currentIndex + 'vitalWS']) { - setTimeout(() => { - ElMessage.info('远程控制' + currentIndex + ', 生命体征数据连接断开,正在尝试重连……') - subscribeVital() - }, 3000) - } + setTimeout(() => { + ElMessage.info('远程控制' + currentIndex + ', 生命体征数据连接断开,正在尝试重连……') + subscribeVital() + }, 3000) }) } @@ -326,13 +323,10 @@ const subscribeChat = () => { } }) remoteWsStore.chatOnclose(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentIndex, () => { - const status = remoteWsStore.getCloseStatus() - if (!status[currentRemote.value.patient + currentRemote.value.patientId + currentRemote.value.date + currentIndex + 'chatWS']) { - setTimeout(() => { - ElMessage.info('远程控制' + currentIndex + ', 通讯连接断开,正在尝试重连……') - subscribeChat() - }, 3000) - } + setTimeout(() => { + ElMessage.info('远程控制' + currentIndex + ', 通讯连接断开,正在尝试重连……') + subscribeChat() + }, 3000) }) }