远程重连

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']) {
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]

View File

@ -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)
})
}

View File

@ -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()
}

View File

@ -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)
})
}