索引下标问题, 断连后中止原有的重连回调函数

This commit is contained in:
republicline 2025-09-05 21:17:16 +08:00
parent e8313fda2b
commit 361d76b5c3
4 changed files with 50 additions and 10 deletions

View File

@ -21,7 +21,8 @@ const chatUrl = "/socket.io/admin/rax/chatRoom?token=" + Session.getToken()
export const useRemoteWsStore = defineStore("remoteWs", {
state: () => {
return {
activeDisconnect: [] as boolean[], // 记录主动断开状态,明确为boolean数组
reconnectTimers: [] as (number | null)[],// 记录重连定时器,明确为number或null的数组
patient: {} as any,
remoteTasks: [] as any,
remoteTasksCap: 10,
@ -44,6 +45,27 @@ export const useRemoteWsStore = defineStore("remoteWs", {
}
},
actions: {
// 设置主动断开状态
setActiveDisconnect(index : number, value : boolean) {
this.activeDisconnect[index] = value;
},
// 检查是否是主动断开
isActiveDisconnect(index : number) {
return this.activeDisconnect[index] || false;
},
// 保存重连定时器
setReconnectTimer(index : number, timerId : number) {
this.reconnectTimers[index] = timerId
},
// 清除指定索引的重连定时器
clearReconnectTimer(index : number) {
if (this.reconnectTimers[index]) {
clearTimeout(this.reconnectTimers[index])
this.reconnectTimers[index] = null
}
},
setCurrentTaskIndex(i: number) {
this.currentTaskIndex = i
Session.set("currentTaskIndex", i)

View File

@ -138,7 +138,7 @@ function subscribeVital() {
function wsClose() {
remoteWsStore.vitalOnclose(remoteTask.value.patient, remoteTask.value.patientId, remoteTask.value.date, props.index, () => {
setTimeout(() => {
ElMessage.info('远程查看' + props.index + ' 生命体征数据连接断开,正在尝试重连……')
ElMessage.info('远程查看' + (props.index + 1) + ' 生命体征数据连接断开,正在尝试重连……')
initData()
}, 3000)
})

View File

@ -216,11 +216,23 @@ 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, () => {
setTimeout(() => {
ElMessage.info('远程查看' + (currentIndex + 1) + ' 生命体征数据连接断开,正在尝试重连……')
remoteWsStore.createVital(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex)
if (remoteWsStore.isActiveDisconnect(currentIndex)) {
return;
}
// store
const timerId = setTimeout(() => {
ElMessage.info(`远程查看${currentIndex + 1},生命体征数据连接断开,正在尝试重连……`)
remoteWsStore.createVital(
remoteItem.value.patient,
remoteItem.value.patientId,
remoteItem.value.date,
currentIndex
)
initData()
}, 3000)
// IDstore
remoteWsStore.setReconnectTimer(currentIndex, timerId)
})
remoteWsStore.createChat(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex)
remoteWsStore.chatOnclose(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex, () => {
@ -275,6 +287,12 @@ function setLog(data: any) {
}
const breakRemote = () => {
ElMessage.success('断开连接成功!')
// 1.
remoteWsStore.setActiveDisconnect(currentIndex, true)
// 2.
remoteWsStore.clearReconnectTimer(currentIndex)
// 3. websocket
remoteWsStore.getRemoteTask()[currentIndex]
remoteWsStore.disconnect(remoteItem.value.patient, remoteItem.value.patientId, remoteItem.value.date, currentIndex)
remoteWsStore.resetRemoteTask(currentIndex)

View File

@ -352,7 +352,7 @@ const subscribeVital = () => {
})
remoteWsStore.vitalOnclose(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentIndex, () => {
setTimeout(() => {
ElMessage.info('远程查看' + currentIndex + ' 生命体征数据连接断开,正在尝试重连……')
// ElMessage.info('' + currentIndex + ' ')
subscribeVital()
}, 3000)
})
@ -376,7 +376,7 @@ const subscribeChat = () => {
messageList.value = msg.history;
}
if (msg.msgType == "destroy") {
ElMessageBox.confirm('远程查看' + currentIndex + '已断开与手术室连接', '提示', {
ElMessageBox.confirm('远程查看' + (currentIndex + 1) + '已断开与手术室连接', '提示', {
confirmButtonText: '确认',
type: 'info'
}).then(() => {