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

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", { export const useRemoteWsStore = defineStore("remoteWs", {
state: () => { state: () => {
return { return {
activeDisconnect: [] as boolean[], // 记录主动断开状态,明确为boolean数组
reconnectTimers: [] as (number | null)[],// 记录重连定时器,明确为number或null的数组
patient: {} as any, patient: {} as any,
remoteTasks: [] as any, remoteTasks: [] as any,
remoteTasksCap: 10, remoteTasksCap: 10,
@ -44,6 +45,27 @@ export const useRemoteWsStore = defineStore("remoteWs", {
} }
}, },
actions: { 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) { setCurrentTaskIndex(i: number) {
this.currentTaskIndex = i this.currentTaskIndex = i
Session.set("currentTaskIndex", i) Session.set("currentTaskIndex", i)

View File

@ -138,7 +138,7 @@ 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, () => {
setTimeout(() => { setTimeout(() => {
ElMessage.info('远程查看' + props.index + ' 生命体征数据连接断开,正在尝试重连……') ElMessage.info('远程查看' + (props.index + 1) + ' 生命体征数据连接断开,正在尝试重连……')
initData() initData()
}, 3000) }, 3000)
}) })

View File

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

View File

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