2024-04-23 09:42:25 +08:00
|
|
|
import {defineStore} from "pinia";
|
|
|
|
import {Session} from "@/utils/storage";
|
2024-06-05 09:17:57 +08:00
|
|
|
import {ElMessage} from "element-plus";
|
2024-04-23 09:42:25 +08:00
|
|
|
|
2024-06-05 09:17:57 +08:00
|
|
|
const vitalUrl = "ws://" + window.location.host + "/socket.io/admin/rax/vitalSignsMedicine?token=" + Session.getToken()
|
|
|
|
const medicineUrl = "ws://" + window.location.host + "/socket.io/admin/rax/addMedicine?token=" + Session.getToken()
|
|
|
|
const chatUrl = "ws://" + window.location.host + "/socket.io/admin/rax/chatRoom?token=" + Session.getToken()
|
2024-04-23 09:42:25 +08:00
|
|
|
|
|
|
|
export const useRemoteWsStore = defineStore("remoteWs", {
|
2024-06-05 09:17:57 +08:00
|
|
|
state: () => {
|
|
|
|
return {
|
|
|
|
patient: {} as any,
|
|
|
|
remoteTasks: [] as any,
|
|
|
|
remoteTasksCap: 10,
|
|
|
|
currentTaskIndex: 0,
|
|
|
|
varMedicine: ["丙泊酚", "舒芬太尼", "瑞芬太尼", "顺阿曲库胺"],
|
|
|
|
fixedMedicine: ["尼卡地平", "艾司洛尔", "麻黄素", "阿托品"],
|
|
|
|
exceptionType: ["BIS_except", "DBP_except", "EtCO2_except", "HR_except", "SBP_except", "ST_except"],
|
|
|
|
exceptionMsg: {
|
|
|
|
"BIS_except": "脑电双频指数异常", "DBP_except": "舒张压异常", "EtCO2_except": "呼气末二氧化碳异常",
|
|
|
|
"HR_except": "心率异常", "SBP_except": "收缩压异常", "ST_except": "ST异常"
|
|
|
|
} as any,
|
|
|
|
exceptions: {} as any,
|
|
|
|
closeStatus: {} as any
|
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setCurrentTaskIndex(i: number) {
|
|
|
|
this.currentTaskIndex = i
|
|
|
|
Session.set("currentTaskIndex", i)
|
|
|
|
},
|
|
|
|
getCurrentTaskIndex() {
|
|
|
|
if (Session.get("currentTaskIndex") && Session.get("currentTaskIndex") > -1) {
|
|
|
|
this.currentTaskIndex = Session.get("currentTaskIndex")
|
|
|
|
}
|
|
|
|
return this.currentTaskIndex
|
|
|
|
},
|
|
|
|
setExceptions(i: number, e: any) {
|
|
|
|
this.exceptions[i] = e
|
|
|
|
},
|
|
|
|
getExceptions() {
|
|
|
|
return this.exceptions
|
|
|
|
},
|
|
|
|
getCloseStatus() {
|
|
|
|
return this.closeStatus
|
|
|
|
},
|
|
|
|
setRemoteTask() {
|
|
|
|
Session.set("remoteTasks", this.remoteTasks)
|
|
|
|
},
|
|
|
|
getRemoteTask() {
|
2024-06-07 10:23:48 +08:00
|
|
|
if (Session.get("remoteTasks") && this.remoteTasks.length == 0) {
|
2024-06-05 09:17:57 +08:00
|
|
|
this.remoteTasks = Session.get("remoteTasks")
|
|
|
|
}
|
|
|
|
return this.remoteTasks
|
|
|
|
},
|
|
|
|
initRemoteTask() {
|
2024-06-07 10:23:48 +08:00
|
|
|
if (Session.get("remoteTasks")) {
|
2024-06-05 09:17:57 +08:00
|
|
|
this.remoteTasks = Session.get("remoteTasks")
|
|
|
|
}
|
|
|
|
if (this.remoteTasks.length <= 0) {
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
this.remoteTasks.push({
|
|
|
|
isRemote: false,
|
|
|
|
isException: false,
|
|
|
|
taskName: "",
|
|
|
|
server: "",
|
|
|
|
serverun: "",
|
|
|
|
serverps: "",
|
|
|
|
patient: "",
|
|
|
|
patientId: "",
|
|
|
|
date: "",
|
|
|
|
log: [],
|
|
|
|
index: i
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.remoteTasks
|
|
|
|
},
|
|
|
|
resetRemoteTask(i: number) {
|
|
|
|
this.remoteTasks[i] = Object.assign(this.remoteTasks[i], {
|
|
|
|
isRemote: false,
|
|
|
|
isException: false,
|
|
|
|
taskName: "",
|
|
|
|
server: "",
|
|
|
|
serverun: "",
|
|
|
|
serverps: "",
|
|
|
|
patient: "",
|
|
|
|
patientId: "",
|
|
|
|
date: "",
|
|
|
|
log: [],
|
|
|
|
index: i,
|
|
|
|
message: []
|
|
|
|
})
|
|
|
|
Session.set("remoteTasks", this.remoteTasks)
|
|
|
|
},
|
|
|
|
getActiveRemoteTask() {
|
|
|
|
let index = 0
|
|
|
|
for (let i = 0; i < this.remoteTasks.length; i++) {
|
|
|
|
if (this.remoteTasks[i].isRemote) index = i
|
|
|
|
}
|
|
|
|
return index
|
|
|
|
},
|
|
|
|
setRemoteLog(log: any, i: number) {
|
|
|
|
this.remoteTasks[i].log.push(log)
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
disconnect(name: string, id: string, date: string, index: number) {
|
|
|
|
this.disconnectVital(name, id, date, index)
|
|
|
|
this.disconnectChat(name, id, date, index)
|
|
|
|
this.disconnectMedicine(name, id, date, index)
|
|
|
|
delete this.patient[name + id + date + index]
|
|
|
|
},
|
|
|
|
createVitalConnect(name: string, id: string, date: string, index: number) {
|
|
|
|
if (!this.patient[name + id + date + index]) this.patient[name + id + date + index] = {}
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (!patient['vitalWS']) {
|
|
|
|
patient['vitalWS'] = new WebSocket(vitalUrl)
|
|
|
|
patient.vitalWS.onopen = () => {
|
|
|
|
patient.vitalWS.send(JSON.stringify({
|
|
|
|
patientName: name,
|
|
|
|
idNum: id,
|
|
|
|
date: date,
|
|
|
|
msgType: "msg"
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
subscribeVital(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 17:58:00 +08:00
|
|
|
if (patient && patient.vitalWS) {
|
2024-06-05 09:17:57 +08:00
|
|
|
patient.vitalWS.onmessage = (e: any) => {
|
|
|
|
if (e && e.data) {
|
|
|
|
const data = JSON.parse(e.data);
|
|
|
|
if (data.msgType == "msg") {
|
|
|
|
cb(e)
|
|
|
|
} else {
|
|
|
|
patient.vitalWS.send(JSON.stringify({msgType: "heartbeat"}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cb({
|
2024-06-07 10:23:48 +08:00
|
|
|
status: 2,
|
2024-06-05 09:17:57 +08:00
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
vitalOnclose(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 17:58:00 +08:00
|
|
|
if (patient && patient.vitalWS) {
|
|
|
|
patient.vitalWS.onclose = () => {
|
|
|
|
const status = this.getCloseStatus()
|
|
|
|
if (!status[name + id + date + index + 'vitalWS']) {
|
|
|
|
delete patient.vitalWS
|
|
|
|
cb()
|
|
|
|
}
|
2024-06-05 17:25:14 +08:00
|
|
|
}
|
2024-06-05 09:17:57 +08:00
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
vitalOnerror(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient.vitalWS) {
|
|
|
|
patient.vitalWS.onerror = cb
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
unsubscribeVital(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-06-07 10:23:48 +08:00
|
|
|
if (patient && patient.vitalWS) {
|
2024-06-05 09:17:57 +08:00
|
|
|
patient.vitalWS.onmessage = undefined
|
|
|
|
patient.vitalWS.onclose = undefined
|
|
|
|
patient.vitalWS.onerror = undefined
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
disconnectVital(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient && patient.vitalWS) {
|
2024-06-05 17:25:14 +08:00
|
|
|
this.closeStatus[name + id + date + index + 'vitalWS'] = true
|
2024-06-05 09:17:57 +08:00
|
|
|
patient.vitalWS.close()
|
|
|
|
delete patient['vitalWS']
|
2024-06-05 17:25:14 +08:00
|
|
|
delete this.closeStatus[name + id + date + index + 'vitalWS']
|
2024-06-05 09:17:57 +08:00
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
createChatConnect(name: string, id: string, date: string, index: number) {
|
|
|
|
if (!this.patient[name + id + date + index]) this.patient[name + id + date + index] = {}
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (!patient['chatWS']) {
|
|
|
|
patient['chatWS'] = new WebSocket(chatUrl)
|
|
|
|
patient.chatWS.onopen = function () {
|
|
|
|
patient.chatWS.send(JSON.stringify({
|
|
|
|
patientName: name,
|
|
|
|
idNum: id,
|
|
|
|
date: date,
|
|
|
|
msgType: "msg"
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
subscribeChat(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient.chatWS) {
|
|
|
|
patient.chatWS.onmessage = (e: any) => {
|
|
|
|
if (e && e.data) {
|
|
|
|
const data = JSON.parse(e.data);
|
|
|
|
if (data.msgType == "msg") {
|
|
|
|
cb(e)
|
|
|
|
} else {
|
|
|
|
patient.chatWS.send(JSON.stringify({msgType: "heartbeat"}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
chatOnclose(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
|
|
|
patient.chatWS.onclose = () => {
|
|
|
|
const status = this.getCloseStatus()
|
|
|
|
if (!status[name + id + date + index + 'chatWS']) {
|
|
|
|
delete patient.chatWS
|
|
|
|
cb()
|
|
|
|
}
|
2024-06-05 09:17:57 +08:00
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
chatOnerror(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient.chatWS) {
|
|
|
|
patient.chatWS.onerror = cb
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
unsubscribeChat(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-06-07 10:23:48 +08:00
|
|
|
if (patient && patient.chatWS) {
|
2024-06-05 09:17:57 +08:00
|
|
|
patient.chatWS.onmessage = undefined
|
|
|
|
patient.chatWS.onclose = undefined
|
|
|
|
patient.chatWS.onerror = undefined
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
sendMsg(name: string, id: string, date: string, msg: string, index: number, cb: any) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient) {
|
|
|
|
const params = {
|
|
|
|
patientName: name,
|
|
|
|
idNum: id,
|
|
|
|
date: date,
|
|
|
|
msg
|
|
|
|
}
|
|
|
|
patient.chatWS.send(JSON.stringify(params))
|
|
|
|
cb({
|
|
|
|
status: 0
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
disconnectChat(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient && patient.chatWS) {
|
2024-06-05 17:25:14 +08:00
|
|
|
this.closeStatus[name + id + date + index + 'chatWS'] = true
|
2024-06-05 09:17:57 +08:00
|
|
|
patient.chatWS.close()
|
|
|
|
delete patient['chatWS']
|
2024-06-05 17:25:14 +08:00
|
|
|
delete this.closeStatus[name + id + date + index + 'chatWS']
|
2024-06-05 09:17:57 +08:00
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
createMedicineConnect(name: string, id: string, date: string, index: number) {
|
|
|
|
if (!this.patient[name + id + date + index]) this.patient[name + id + date + index] = {}
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (!patient['medicineWS']) {
|
|
|
|
patient['medicineWS'] = new WebSocket(medicineUrl)
|
|
|
|
patient.medicineWS.onopen = function () {
|
|
|
|
patient.medicineWS.send(JSON.stringify({
|
|
|
|
patientName: name,
|
|
|
|
idNum: id,
|
|
|
|
date: date,
|
|
|
|
msgType: "msg"
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
subscribeMedicine(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient) {
|
|
|
|
patient.medicineWS.onmessage = (e: any) => {
|
|
|
|
if (e && e.data) {
|
|
|
|
const data = JSON.parse(e.data);
|
|
|
|
if (data.msgType == "msg") {
|
|
|
|
cb(e)
|
|
|
|
} else {
|
|
|
|
patient.medicineWS.send(JSON.stringify({msgType: "heartbeat"}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
medicineOnclose(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
|
|
|
patient.medicineWS.onclose = () => {
|
|
|
|
const status = this.getCloseStatus()
|
|
|
|
if (!status[name + id + date + index + 'medicineWS']) {
|
|
|
|
delete patient.medicineWS
|
|
|
|
cb()
|
|
|
|
}
|
2024-06-05 09:17:57 +08:00
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
medicineOnerror(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient.medicineWS) {
|
|
|
|
patient.medicineWS.onerror = cb
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
unsubscribeMedicine(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-06-07 10:23:48 +08:00
|
|
|
if (patient && patient.medicineWS) {
|
2024-06-05 09:17:57 +08:00
|
|
|
patient.medicineWS.onmessage = undefined
|
|
|
|
patient.medicineWS.onclose = undefined
|
|
|
|
patient.medicineWS.onerror = undefined
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sendMedicine(args: {
|
|
|
|
name: string,
|
|
|
|
id: string,
|
|
|
|
date: string,
|
2024-06-05 17:25:14 +08:00
|
|
|
index: number,
|
2024-06-05 09:17:57 +08:00
|
|
|
flag: string,
|
|
|
|
medicine: string,
|
|
|
|
value: string
|
|
|
|
}, cb: any) {
|
2024-06-05 17:25:14 +08:00
|
|
|
const patient: any = this.patient[args.name + args.id + args.date + args.index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient) {
|
|
|
|
const params = {
|
|
|
|
patientName: args.name,
|
|
|
|
idNum: args.id,
|
|
|
|
date: args.date,
|
|
|
|
flag: args.flag,
|
|
|
|
medicine: args.medicine,
|
|
|
|
value: args.value
|
|
|
|
}
|
|
|
|
patient.medicineWS.send(JSON.stringify(params))
|
|
|
|
cb({
|
|
|
|
status: 0
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-06-05 17:25:14 +08:00
|
|
|
disconnectMedicine(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-06-05 09:17:57 +08:00
|
|
|
if (patient && patient.medicineWS) {
|
2024-06-05 17:25:14 +08:00
|
|
|
this.closeStatus[name + id + date + index + 'medicineWS'] = true
|
2024-06-05 09:17:57 +08:00
|
|
|
patient.medicineWS.close()
|
|
|
|
delete patient['medicineWS']
|
2024-06-05 17:25:14 +08:00
|
|
|
delete this.closeStatus[name + id + date + index + 'medicineWS']
|
2024-06-05 09:17:57 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2024-04-23 09:42:25 +08:00
|
|
|
})
|