mirror of
https://gitee.com/xiongmao1988/rax-medical.git
synced 2026-06-12 13:31:47 +08:00
修复,多个连接,状态提示错误, 并且去除索引
This commit is contained in:
parent
68601dda67
commit
ddc2b28726
|
|
@ -67,8 +67,14 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
|||
}
|
||||
},
|
||||
setCurrentTaskIndex(i: number) {
|
||||
this.currentTaskIndex = i
|
||||
Session.set("currentTaskIndex", i)
|
||||
// this.currentTaskIndex = i
|
||||
// Session.set("currentTaskIndex", i)
|
||||
// 切换前清除旧任务的重连定时器
|
||||
if (this.currentTaskIndex !== -1) {
|
||||
this.clearReconnectTimer(this.currentTaskIndex);
|
||||
}
|
||||
this.currentTaskIndex = i;
|
||||
Session.set("currentTaskIndex", i);
|
||||
},
|
||||
getCurrentTaskIndex() {
|
||||
if (Session.get("currentTaskIndex") > -1) {
|
||||
|
|
@ -215,29 +221,88 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
|||
}
|
||||
},*/
|
||||
|
||||
// disconnect(name: string, id: string, date: string, index: number) {
|
||||
// this.disconnectChat(name, id, date, index)
|
||||
// this.disconnectVital(name, id, date, index)
|
||||
// delete this.patient[name + id + date + index]
|
||||
// },
|
||||
disconnect(name: string, id: string, date: string, index: number) {
|
||||
this.disconnectChat(name, id, date, index)
|
||||
this.disconnectVital(name, id, date, index)
|
||||
delete this.patient[name + id + date + index]
|
||||
this.disconnectChat(name, id, date, index);
|
||||
this.disconnectVital(name, id, date, index);
|
||||
const patientKey = `${name}${id}${date}${index}`;
|
||||
delete this.patient[patientKey];
|
||||
this.setActiveDisconnect(index, true); // 确保标记主动断开
|
||||
this.clearReconnectTimer(index); // 最终清理定时器
|
||||
},
|
||||
// createVital(name: string, id: string, date: string, index: number) {
|
||||
// const patient = this.patient[name + id + date + index] ? this.patient[name + id + date + index] : this.patient[name + id + date + index] = {}
|
||||
// if (patient && !patient['vitalWS']) {
|
||||
// patient['vitalWS'] = new WebSocket(vitalUrl)
|
||||
// patient['vitalWS'].onopen = function () {
|
||||
// ElMessage.info("远程查看" + (index + 1) + ",生命体征数据连接成功")
|
||||
// patient['vitalWS'].send(JSON.stringify({
|
||||
// patientName: name,
|
||||
// idNum: id,
|
||||
// date: date,
|
||||
// msgType: "msg"
|
||||
// }))
|
||||
// }
|
||||
//
|
||||
// patient['vitalWS'].onerror = () => {
|
||||
// ElMessage.error("远程管理" + (index + 1) + "生命体征数据出错")
|
||||
// }
|
||||
// delete this.closeStatus[name + id + date + index + 'vitalWS']
|
||||
// }
|
||||
// },
|
||||
createVital(name: string, id: string, date: string, index: number) {
|
||||
const patient = this.patient[name + id + date + index] ? this.patient[name + id + date + index] : this.patient[name + id + date + index] = {}
|
||||
const patientKey = `${name}${id}${date}${index}`;
|
||||
const patient = this.patient[patientKey] ? this.patient[patientKey] : this.patient[patientKey] = {};
|
||||
// 新增:若已主动断开,直接返回不创建连接
|
||||
if (this.isActiveDisconnect(index)) {
|
||||
return;
|
||||
}
|
||||
if (patient && !patient['vitalWS']) {
|
||||
patient['vitalWS'] = new WebSocket(vitalUrl)
|
||||
patient['vitalWS'].onopen = function () {
|
||||
ElMessage.info("远程查看" + (index + 1) + ",生命体征数据连接成功")
|
||||
patient['vitalWS'] = new WebSocket(vitalUrl);
|
||||
patient['vitalWS'].onopen = () => {
|
||||
if (index === this.currentTaskIndex) {
|
||||
ElMessage.info("远程查看,生命体征数据连接成功");
|
||||
}
|
||||
patient['vitalWS'].send(JSON.stringify({
|
||||
patientName: name,
|
||||
idNum: id,
|
||||
date: date,
|
||||
msgType: "msg"
|
||||
}))
|
||||
}
|
||||
}));
|
||||
this.clearReconnectTimer(index);
|
||||
};
|
||||
|
||||
patient['vitalWS'].onerror = () => {
|
||||
ElMessage.error("远程管理" + (index + 1) + "生命体征数据出错")
|
||||
}
|
||||
delete this.closeStatus[name + id + date + index + 'vitalWS']
|
||||
if (index === this.currentTaskIndex) {
|
||||
ElMessage.error("远程管理,生命体征数据出错");
|
||||
}
|
||||
};
|
||||
|
||||
patient['vitalWS'].onclose = () => {
|
||||
// 新增:若已主动断开,不触发重连
|
||||
if (this.isActiveDisconnect(index)) {
|
||||
delete patient.vitalWS;
|
||||
return;
|
||||
}
|
||||
if (index === this.currentTaskIndex) {
|
||||
ElMessage.warning("远程查看,生命体征连接断开,正在重连...");
|
||||
this.clearReconnectTimer(index);
|
||||
const timerId = window.setTimeout(() => {
|
||||
// 重连前再次检查是否已主动断开
|
||||
if (!this.isActiveDisconnect(index)) {
|
||||
this.createVital(name, id, date, index);
|
||||
}
|
||||
}, 3000);
|
||||
this.setReconnectTimer(index, timerId);
|
||||
}
|
||||
delete patient.vitalWS;
|
||||
};
|
||||
|
||||
delete this.closeStatus[`${patientKey}vitalWS`];
|
||||
}
|
||||
},
|
||||
subscribeVital(name: string, id: string, date: string, index: number, cb: any) {
|
||||
|
|
@ -313,38 +378,108 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
|||
}
|
||||
},
|
||||
|
||||
// disconnectVital(name: string, id: string, date: string, index: number) {
|
||||
// const patient: any = this.patient[name + id + date + index]
|
||||
// if (patient && patient.vitalWS) {
|
||||
// this.closeStatus[name + id + date + index + 'vitalWS'] = true
|
||||
// patient.vitalWS.close()
|
||||
// delete patient['vitalWS']
|
||||
// }
|
||||
// },
|
||||
disconnectVital(name: string, id: string, date: string, index: number) {
|
||||
const patient: any = this.patient[name + id + date + index]
|
||||
const patientKey = `${name}${id}${date}${index}`;
|
||||
const patient: any = this.patient[patientKey];
|
||||
if (patient && patient.vitalWS) {
|
||||
this.closeStatus[name + id + date + index + 'vitalWS'] = true
|
||||
patient.vitalWS.close()
|
||||
delete patient['vitalWS']
|
||||
this.closeStatus[`${patientKey}vitalWS`] = true;
|
||||
this.setActiveDisconnect(index, true); // 标记为主动断开
|
||||
patient.vitalWS.close();
|
||||
delete patient.vitalWS;
|
||||
this.clearReconnectTimer(index); // 强制清除重连定时器
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// createChat(name: string, id: string, date: string, index: number) {
|
||||
// const patient = this.patient[name + id + date + index] ? this.patient[name + id + date + index] : this.patient[name + id + date + index] = {}
|
||||
// if (patient && !patient['chatWS']) {
|
||||
// patient['chatWS'] = new WebSocket(chatUrl)
|
||||
// patient['chatWS'].onopen = function () {
|
||||
// ElMessage.info("远程查看" + (index + 1) + ",通讯连接成功")
|
||||
// patient['chatWS'].send(JSON.stringify({
|
||||
// patientName: name,
|
||||
// idNum: id,
|
||||
// date: date,
|
||||
// msgType: "init"
|
||||
// }))
|
||||
// patient['chatWS'].send(JSON.stringify({
|
||||
// patientName: name,
|
||||
// idNum: id,
|
||||
// date: date,
|
||||
// msgType: "historyChat"
|
||||
// }))
|
||||
// }
|
||||
//
|
||||
// patient['chatWS'].onerror = () => {
|
||||
// ElMessage.error("远程查看" + (index + 1) + "通讯出错")
|
||||
// }
|
||||
// delete this.closeStatus[name + id + date + index + 'chatWS']
|
||||
// }
|
||||
// },
|
||||
createChat(name: string, id: string, date: string, index: number) {
|
||||
const patient = this.patient[name + id + date + index] ? this.patient[name + id + date + index] : this.patient[name + id + date + index] = {}
|
||||
const patientKey = `${name}${id}${date}${index}`;
|
||||
const patient = this.patient[patientKey] ? this.patient[patientKey] : this.patient[patientKey] = {};
|
||||
// 新增:若已主动断开,直接返回不创建连接
|
||||
if (this.isActiveDisconnect(index)) {
|
||||
return;
|
||||
}
|
||||
if (patient && !patient['chatWS']) {
|
||||
patient['chatWS'] = new WebSocket(chatUrl)
|
||||
patient['chatWS'].onopen = function () {
|
||||
ElMessage.info("远程查看" + (index + 1) + ",通讯连接成功")
|
||||
patient['chatWS'] = new WebSocket(chatUrl);
|
||||
patient['chatWS'].onopen = () => {
|
||||
if (index === this.currentTaskIndex) {
|
||||
ElMessage.info("远程查看,通讯连接成功");
|
||||
}
|
||||
patient['chatWS'].send(JSON.stringify({
|
||||
patientName: name,
|
||||
idNum: id,
|
||||
date: date,
|
||||
msgType: "init"
|
||||
}))
|
||||
}));
|
||||
patient['chatWS'].send(JSON.stringify({
|
||||
patientName: name,
|
||||
idNum: id,
|
||||
date: date,
|
||||
msgType: "historyChat"
|
||||
}))
|
||||
}
|
||||
}));
|
||||
this.clearReconnectTimer(index);
|
||||
};
|
||||
|
||||
patient['chatWS'].onerror = () => {
|
||||
ElMessage.error("远程查看" + (index + 1) + "通讯出错")
|
||||
}
|
||||
delete this.closeStatus[name + id + date + index + 'chatWS']
|
||||
if (index === this.currentTaskIndex) {
|
||||
ElMessage.error("远程查看,通讯出错");
|
||||
}
|
||||
};
|
||||
|
||||
patient['chatWS'].onclose = () => {
|
||||
// 新增:若已主动断开,不触发重连
|
||||
if (this.isActiveDisconnect(index)) {
|
||||
delete patient.chatWS;
|
||||
return;
|
||||
}
|
||||
if (index === this.currentTaskIndex) {
|
||||
ElMessage.warning("远程查看,通讯连接断开,正在重连...");
|
||||
this.clearReconnectTimer(index);
|
||||
const timerId = window.setTimeout(() => {
|
||||
// 重连前再次检查是否已主动断开
|
||||
if (!this.isActiveDisconnect(index)) {
|
||||
this.createChat(name, id, date, index);
|
||||
}
|
||||
}, 3000);
|
||||
this.setReconnectTimer(index, timerId);
|
||||
}
|
||||
delete patient.chatWS;
|
||||
};
|
||||
|
||||
delete this.closeStatus[`${patientKey}chatWS`];
|
||||
}
|
||||
},
|
||||
subscribeChat(name: string, id: string, date: string, index: number, cb: any) {
|
||||
|
|
@ -383,12 +518,23 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
|||
const patient: any = this.patient[name + id + date + index]
|
||||
patient.chatWS.onmessage = undefined;
|
||||
},
|
||||
// disconnectChat(name: string, id: string, date: string, index: number) {
|
||||
// const patient: any = this.patient[name + id + date + index]
|
||||
// if (patient && patient.chatWS) {
|
||||
// this.closeStatus[name + id + date + index + 'chatWS'] = true
|
||||
// patient.chatWS.close()
|
||||
// delete patient['chatWS']
|
||||
// }
|
||||
// },
|
||||
disconnectChat(name: string, id: string, date: string, index: number) {
|
||||
const patient: any = this.patient[name + id + date + index]
|
||||
const patientKey = `${name}${id}${date}${index}`;
|
||||
const patient: any = this.patient[patientKey];
|
||||
if (patient && patient.chatWS) {
|
||||
this.closeStatus[name + id + date + index + 'chatWS'] = true
|
||||
patient.chatWS.close()
|
||||
delete patient['chatWS']
|
||||
this.closeStatus[`${patientKey}chatWS`] = true;
|
||||
this.setActiveDisconnect(index, true); // 标记为主动断开
|
||||
patient.chatWS.close();
|
||||
delete patient.chatWS;
|
||||
this.clearReconnectTimer(index); // 强制清除重连定时器
|
||||
}
|
||||
},
|
||||
sendMedicine(args: {
|
||||
|
|
|
|||
|
|
@ -138,7 +138,8 @@ function subscribeVital() {
|
|||
function wsClose() {
|
||||
remoteWsStore.vitalOnclose(remoteTask.value.patient, remoteTask.value.patientId, remoteTask.value.date, props.index, () => {
|
||||
setTimeout(() => {
|
||||
ElMessage.info('远程查看' + (props.index + 1) + ', 生命体征数据连接断开,正在尝试重连……')
|
||||
// ElMessage.info('远程查看' + (props.index + 1) + ', 生命体征数据连接断开,正在尝试重连……')
|
||||
ElMessage.info('远程查看,生命体征数据连接断开,正在尝试重连……')
|
||||
initData()
|
||||
}, 3000)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -221,7 +221,8 @@ function initData() {
|
|||
}
|
||||
// 创建定时器并保存到store
|
||||
const timerId = setTimeout(() => {
|
||||
ElMessage.info(`远程查看${currentIndex + 1},生命体征数据连接断开,正在尝试重连……`)
|
||||
// ElMessage.info(`远程查看${currentIndex + 1},生命体征数据连接断开,正在尝试重连……`)
|
||||
ElMessage.info(`远程查看,生命体征数据连接断开,正在尝试重连……`)
|
||||
remoteWsStore.createVital(
|
||||
remoteItem.value.patient,
|
||||
remoteItem.value.patientId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user