远程重连

This commit is contained in:
yy 2024-06-05 15:38:41 +08:00
parent 4a41099f6d
commit 9b1e808e3c
4 changed files with 35 additions and 35 deletions

View File

@ -178,7 +178,7 @@ export const useRemoteWsStore = defineStore("remoteWs", {
if (patient && !patient['vitalWS']) { if (patient && !patient['vitalWS']) {
patient['vitalWS'] = new WebSocket(vitalUrl) patient['vitalWS'] = new WebSocket(vitalUrl)
patient['vitalWS'].onopen = function () { patient['vitalWS'].onopen = function () {
ElMessage.info("远程控制" + index + ",生命体征数据连接成功") ElMessage.info("远程控制" + (index + 1) + ",生命体征数据连接成功")
patient['vitalWS'].send(JSON.stringify({ patient['vitalWS'].send(JSON.stringify({
patientName: name, patientName: name,
idNum: id, idNum: id,
@ -188,7 +188,7 @@ export const useRemoteWsStore = defineStore("remoteWs", {
} }
patient['vitalWS'].onerror = () => { patient['vitalWS'].onerror = () => {
ElMessage.error("远程管理" + (index + 1) + "出错") ElMessage.error("远程管理" + (index + 1) + "生命体征数据出错")
} }
delete this.closeStatus[name + id + date + index + 'vitalWS'] 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) { vitalOnclose(name: string, id: string, date: string, index: number, cb: any) {
const patient: any = this.patient[name + id + date + index] 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) { unsubscribeVital(name: string, id: string, date: string, index: number) {
const patient: any = this.patient[name + id + date + index] const patient: any = this.patient[name + id + date + index]
@ -250,7 +256,7 @@ export const useRemoteWsStore = defineStore("remoteWs", {
if (patient && !patient['chatWS']) { if (patient && !patient['chatWS']) {
patient['chatWS'] = new WebSocket(chatUrl) patient['chatWS'] = new WebSocket(chatUrl)
patient['chatWS'].onopen = function () { patient['chatWS'].onopen = function () {
ElMessage.info("远程控制" + index + ",通讯连接成功") ElMessage.info("远程控制" + (index + 1) + ",通讯连接成功")
patient['chatWS'].send(JSON.stringify({ patient['chatWS'].send(JSON.stringify({
patientName: name, patientName: name,
idNum: id, idNum: id,
@ -260,7 +266,7 @@ export const useRemoteWsStore = defineStore("remoteWs", {
} }
patient['chatWS'].onerror = () => { patient['chatWS'].onerror = () => {
ElMessage.error("远程管理" + (index + 1) + "出错") ElMessage.error("远程控制" + (index + 1) + "通讯出错")
} }
delete this.closeStatus[name + id + date + index + 'chatWS'] 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) { chatOnclose(name: string, id: string, date: string, index: number, cb: any) {
const patient: any = this.patient[name + id + date + index] 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) { unsubscribeChat(name: string, id: string, date: string, index: number) {
const patient: any = this.patient[name + id + date + index] const patient: any = this.patient[name + id + date + index]

View File

@ -104,13 +104,10 @@ function subscribeVital() {
function wsClose() { function wsClose() {
remoteWsStore.vitalOnclose(remoteTask.value.patient, remoteTask.value.patientId, remoteTask.value.date, props.index, () => { remoteWsStore.vitalOnclose(remoteTask.value.patient, remoteTask.value.patientId, remoteTask.value.date, props.index, () => {
const status = remoteWsStore.getCloseStatus() setTimeout(() => {
if (remoteTask.value.patient && !status[remoteTask.value.patient + remoteTask.value.patientId + remoteTask.value.date + props.index + 'vitalWS']) { ElMessage.info('远程控制' + props.index + ' 生命体征数据连接断开,正在尝试重连……')
setTimeout(() => { initData()
ElMessage.info('远程控制' + props.index + ' 生命体征数据连接断开,正在尝试重连……') }, 3000)
initData()
}, 3000)
}
}) })
} }

View File

@ -166,14 +166,11 @@ function initData() {
if (remoteItem.value && remoteItem.value.patient) { if (remoteItem.value && remoteItem.value.patient) {
remoteWsStore.createVital(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex) remoteWsStore.createVital(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex)
remoteWsStore.vitalOnclose(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() setTimeout(() => {
if (remoteItem.value.patient && !status[remoteItem.value.patient + remoteItem.value.patientId + remoteItem.value.date + currentIndex + 'vitalWS']) { ElMessage.info('远程控制' + (currentIndex + 1) + ' 生命体征数据连接断开,正在尝试重连……')
setTimeout(() => { remoteWsStore.createVital(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex)
ElMessage.info('远程控制' + currentIndex + ' 生命体征数据连接断开,正在尝试重连……') initData()
remoteWsStore.createVital(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex) }, 3000)
initData()
}, 3000)
}
}) })
getData() getData()
} }

View File

@ -304,13 +304,10 @@ const subscribeVital = () => {
updateMedicineTable(data.aiMedicineList[0], undefined); updateMedicineTable(data.aiMedicineList[0], undefined);
}) })
remoteWsStore.vitalOnclose(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentIndex, () => { remoteWsStore.vitalOnclose(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentIndex, () => {
const status = remoteWsStore.getCloseStatus() setTimeout(() => {
if (currentRemote.value.patient && !status[currentRemote.value.patient + currentRemote.value.patientId + currentRemote.value.date + currentIndex + 'vitalWS']) { ElMessage.info('远程控制' + currentIndex + ' 生命体征数据连接断开,正在尝试重连……')
setTimeout(() => { subscribeVital()
ElMessage.info('远程控制' + currentIndex + ' 生命体征数据连接断开,正在尝试重连……') }, 3000)
subscribeVital()
}, 3000)
}
}) })
} }
@ -326,13 +323,10 @@ const subscribeChat = () => {
} }
}) })
remoteWsStore.chatOnclose(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentIndex, () => { remoteWsStore.chatOnclose(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentIndex, () => {
const status = remoteWsStore.getCloseStatus() setTimeout(() => {
if (!status[currentRemote.value.patient + currentRemote.value.patientId + currentRemote.value.date + currentIndex + 'chatWS']) { ElMessage.info('远程控制' + currentIndex + ' 通讯连接断开,正在尝试重连……')
setTimeout(() => { subscribeChat()
ElMessage.info('远程控制' + currentIndex + ' 通讯连接断开,正在尝试重连……') }, 3000)
subscribeChat()
}, 3000)
}
}) })
} }