2024-05-28 23:13:41 +08:00
|
|
|
import { defineStore } from "pinia";
|
2024-05-29 10:47:41 +08:00
|
|
|
import { Session } from "@/utils/storage";
|
2024-05-29 17:09:56 +08:00
|
|
|
import { ElMessage } from "element-plus";
|
2024-04-23 09:42:25 +08:00
|
|
|
|
|
|
|
const vitalUrl = "ws://localhost:5173/socket.io/admin/rax/vitalSignsMedicine?token=" + Session.getToken()
|
|
|
|
const medicineUrl = "ws://localhost:5173/socket.io/admin/rax/addMedicine?token=" + Session.getToken()
|
|
|
|
const chatUrl = "ws://localhost:5173/socket.io/admin/rax/chatRoom?token=" + Session.getToken()
|
|
|
|
|
|
|
|
export const useRemoteWsStore = defineStore("remoteWs", {
|
|
|
|
state: () => {
|
|
|
|
return {
|
|
|
|
patient: {} as any,
|
|
|
|
remoteTasks: [] as any,
|
|
|
|
remoteTasksCap: 10,
|
2024-05-29 14:18:15 +08:00
|
|
|
currentTaskIndex: -1,
|
2024-04-23 09:42:25 +08:00
|
|
|
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异常"
|
2024-05-17 12:06:29 +08:00
|
|
|
} as any,
|
2024-04-23 09:42:25 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
2024-05-28 23:13:41 +08:00
|
|
|
setCurrentTaskIndex(i: number) {
|
|
|
|
this.currentTaskIndex = i
|
2024-05-29 10:47:41 +08:00
|
|
|
Session.set("currentTaskIndex", i)
|
2024-05-28 23:13:41 +08:00
|
|
|
},
|
|
|
|
getCurrentTaskIndex() {
|
2024-05-29 17:09:56 +08:00
|
|
|
if (Session.get("currentTaskIndex") > -1) {
|
2024-05-29 10:47:41 +08:00
|
|
|
this.currentTaskIndex = Session.get("currentTaskIndex")
|
2024-05-28 23:13:41 +08:00
|
|
|
}
|
|
|
|
return this.currentTaskIndex
|
|
|
|
},
|
|
|
|
setRemoteTask() {
|
2024-05-29 10:47:41 +08:00
|
|
|
Session.set("remoteTasks", this.remoteTasks)
|
2024-05-28 23:13:41 +08:00
|
|
|
},
|
|
|
|
getRemoteTask() {
|
2024-05-29 10:47:41 +08:00
|
|
|
if (Session.get("remoteTasks")) {
|
|
|
|
this.remoteTasks = Session.get("remoteTasks")
|
2024-05-28 23:13:41 +08:00
|
|
|
}
|
|
|
|
return this.remoteTasks
|
|
|
|
},
|
2024-04-23 09:42:25 +08:00
|
|
|
initRemoteTask() {
|
2024-05-29 10:47:41 +08:00
|
|
|
if (Session.get("remoteTasks")) {
|
|
|
|
this.remoteTasks = Session.get("remoteTasks")
|
2024-05-28 23:13:41 +08:00
|
|
|
}
|
2024-04-23 09:42:25 +08:00
|
|
|
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: []
|
|
|
|
})
|
2024-05-29 10:47:41 +08:00
|
|
|
Session.set("remoteTasks", this.remoteTasks)
|
2024-04-23 09:42:25 +08:00
|
|
|
},
|
|
|
|
getActiveRemoteTask() {
|
2024-05-29 17:14:48 +08:00
|
|
|
let index = 0
|
2024-04-23 09:42:25 +08:00
|
|
|
for (let i = 0; i < this.remoteTasks.length; i++) {
|
2024-05-29 17:09:56 +08:00
|
|
|
if (this.remoteTasks[i].isRemote) index = i
|
2024-04-23 09:42:25 +08:00
|
|
|
}
|
2024-05-29 15:20:43 +08:00
|
|
|
return index
|
2024-04-23 09:42:25 +08:00
|
|
|
},
|
|
|
|
setRemoteLog(log: any, i: number) {
|
|
|
|
this.remoteTasks[i].log.push(log)
|
|
|
|
},
|
2024-05-29 14:18:15 +08:00
|
|
|
createConnect(name: string, id: string, date: string, index: number) {
|
|
|
|
if (!this.patient[name + id + date + index]) {
|
2024-04-23 09:42:25 +08:00
|
|
|
const vitalWS = new WebSocket(vitalUrl)
|
|
|
|
const medicineWS = new WebSocket(medicineUrl)
|
|
|
|
const chatWS = new WebSocket(chatUrl)
|
|
|
|
vitalWS.onopen = function () {
|
|
|
|
vitalWS.send(JSON.stringify({
|
|
|
|
patientName: name,
|
|
|
|
idNum: id,
|
|
|
|
date: date
|
|
|
|
}))
|
|
|
|
}
|
2024-05-29 17:09:56 +08:00
|
|
|
|
|
|
|
vitalWS.onclose = () => {
|
|
|
|
ElMessage.info("远程管理" + (index + 1) + "已断开")
|
|
|
|
}
|
|
|
|
|
|
|
|
vitalWS.onerror = () => {
|
|
|
|
ElMessage.error("远程管理" + (index + 1) + "出错")
|
|
|
|
}
|
|
|
|
|
2024-04-23 09:42:25 +08:00
|
|
|
medicineWS.onopen = function () {
|
|
|
|
medicineWS.send(JSON.stringify({
|
|
|
|
patientName: name,
|
|
|
|
idNum: id,
|
|
|
|
date: date
|
|
|
|
}))
|
|
|
|
}
|
2024-05-29 17:09:56 +08:00
|
|
|
|
|
|
|
medicineWS.onclose = () => {
|
|
|
|
ElMessage.info("远程管理" + (index + 1) + "给药已断开")
|
|
|
|
}
|
|
|
|
|
|
|
|
medicineWS.onerror = () => {
|
|
|
|
ElMessage.error("远程管理" + (index + 1) + "给药出错")
|
|
|
|
}
|
|
|
|
|
2024-04-23 09:42:25 +08:00
|
|
|
chatWS.onopen = function () {
|
|
|
|
chatWS.send(JSON.stringify({
|
|
|
|
patientName: name,
|
|
|
|
idNum: id,
|
|
|
|
date: date
|
|
|
|
}))
|
|
|
|
}
|
2024-05-29 17:09:56 +08:00
|
|
|
|
|
|
|
chatWS.onclose = () => {
|
|
|
|
ElMessage.info("远程管理" + (index + 1) + "通讯已断开")
|
|
|
|
}
|
|
|
|
|
|
|
|
chatWS.onerror = () => {
|
|
|
|
ElMessage.error("远程管理" + (index + 1) + "通讯出错")
|
|
|
|
}
|
|
|
|
|
2024-05-29 14:18:15 +08:00
|
|
|
this.patient[name + id + date + index] = {
|
2024-04-23 09:42:25 +08:00
|
|
|
vitalWS,
|
|
|
|
medicineWS,
|
|
|
|
chatWS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-05-29 14:18:15 +08:00
|
|
|
disconnect(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-04-23 09:42:25 +08:00
|
|
|
if (patient) {
|
|
|
|
patient.vitalWS.close()
|
|
|
|
patient.medicineWS.close()
|
|
|
|
patient.chatWS.close()
|
2024-05-29 14:18:15 +08:00
|
|
|
delete this.patient[name + id + date + index]
|
2024-04-23 09:42:25 +08:00
|
|
|
}
|
|
|
|
},
|
2024-05-29 14:18:15 +08:00
|
|
|
subscribeVital(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-04-23 09:42:25 +08:00
|
|
|
if (patient) {
|
|
|
|
patient.vitalWS.onmessage = cb
|
|
|
|
patient.vitalCB = cb
|
|
|
|
} else {
|
2024-05-29 14:18:15 +08:00
|
|
|
this.createConnect(name, id, date, index)
|
|
|
|
this.patient[name + id + date + index].vitalWS.onmessage = cb
|
|
|
|
this.patient[name + id + date + index].vitalCB = cb
|
2024-04-23 09:42:25 +08:00
|
|
|
}
|
|
|
|
},
|
2024-05-29 19:16:11 +08:00
|
|
|
vitalOnclose(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
|
|
|
patient.vitalWS.onclose = cb
|
|
|
|
},
|
2024-05-29 14:18:15 +08:00
|
|
|
unsubscribeVital(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-04-23 09:42:25 +08:00
|
|
|
if (patient && patient.vitalWS) {
|
|
|
|
patient.vitalWS.onmessage = undefined;
|
|
|
|
patient.vitalCB = undefined;
|
|
|
|
}
|
|
|
|
},
|
2024-05-29 14:18:15 +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-04-23 09:42:25 +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-05-29 14:18:15 +08:00
|
|
|
subscribeChat(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-04-23 09:42:25 +08:00
|
|
|
if (patient) {
|
|
|
|
patient.chatCB = cb
|
|
|
|
patient.chatWS.onmessage = cb
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-05-29 19:16:11 +08:00
|
|
|
chatOnclose(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
|
|
|
patient.chatWS.onclose = cb
|
|
|
|
},
|
2024-05-29 14:18:15 +08:00
|
|
|
unsubscribeChat(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-04-23 09:42:25 +08:00
|
|
|
patient.chatCB = undefined;
|
|
|
|
patient.chatWS.onmessage = undefined;
|
|
|
|
},
|
|
|
|
sendMedicine(args: {
|
|
|
|
name: string,
|
|
|
|
id: string,
|
|
|
|
date: string,
|
|
|
|
flag: string,
|
|
|
|
medicine: string,
|
|
|
|
value: string
|
2024-05-29 14:18:15 +08:00
|
|
|
}, index: number, cb: any) {
|
|
|
|
const patient: any = this.patient[args.name + args.id + args.date + index]
|
2024-04-23 09:42:25 +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-05-29 14:18:15 +08:00
|
|
|
subscribeMedicine(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient = this.patient[name + id + date + index]
|
2024-04-23 09:42:25 +08:00
|
|
|
if (patient) {
|
|
|
|
patient.medicineCB = cb
|
|
|
|
patient.medicineWS.onmessage = cb
|
|
|
|
} else {
|
|
|
|
cb({
|
|
|
|
status: 1,
|
|
|
|
msg: "已断开连接"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-05-29 19:16:11 +08:00
|
|
|
medicineOnclose(name: string, id: string, date: string, index: number, cb: any) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
|
|
|
patient.medicineWS.onclose = cb
|
|
|
|
},
|
2024-05-29 14:18:15 +08:00
|
|
|
unsubscribeMedicine(name: string, id: string, date: string, index: number) {
|
|
|
|
const patient: any = this.patient[name + id + date + index]
|
2024-04-23 09:42:25 +08:00
|
|
|
patient.medicineCB = undefined;
|
|
|
|
patient.medicineWS.onmessage = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|