mirror of
https://gitee.com/xiongmao1988/rax-medical.git
synced 2025-08-24 13:04:57 +08:00
feat: web端和unity端的远程连接store
This commit is contained in:
parent
ed81f95e9d
commit
ad1da60f65
|
@ -1,6 +1,5 @@
|
||||||
import {defineStore} from "pinia";
|
|
||||||
import { Session } from "@/utils/storage";
|
import { Session } from "@/utils/storage";
|
||||||
import {ElMessage} from "element-plus";
|
import { defineStore } from "pinia";
|
||||||
|
|
||||||
const vitalUrl = "ws://" + window.location.host + "/socket.io/admin/rax/vitalSignsMedicine?token=" + Session.getToken()
|
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 medicineUrl = "ws://" + window.location.host + "/socket.io/admin/rax/addMedicine?token=" + Session.getToken()
|
||||||
|
@ -119,7 +118,7 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
||||||
patientName: name,
|
patientName: name,
|
||||||
idNum: id,
|
idNum: id,
|
||||||
date: date,
|
date: date,
|
||||||
msgType: "msg"
|
msgType: "init"
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,37 +293,24 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
||||||
},
|
},
|
||||||
|
|
||||||
// 请求连接远程控制
|
// 请求连接远程控制
|
||||||
reqMedicineConnect(name: string, id: string, date: string, index: number, msg: string, flag: string): Promise<number> {
|
reqMedicineConnect(params:{name: string, id: string, date: string, index: number, msgType: string, flag: string},cb:any){
|
||||||
if (!this.patient[name + id + date + index]) this.patient[name + id + date + index] = {}
|
const {name, id, date, index,msgType,flag} = params;
|
||||||
const patient = this.patient[name + id + date+index]
|
const patient = this.patient[name + id + date+index]
|
||||||
if (!patient['medicineWS']) {
|
const sendData={
|
||||||
patient['medicineWS'] = new WebSocket(medicineUrl)
|
|
||||||
patient.medicineWS.onopen = function () {
|
|
||||||
patient.medicineWS.send(JSON.stringify({
|
|
||||||
patientName: name,
|
patientName: name,
|
||||||
idNum: id,
|
idNum: id,
|
||||||
date: date,
|
date: date,
|
||||||
msgType: msg,
|
msgType: msgType,
|
||||||
webConnectionFlag: flag
|
webConnectionFlag: flag
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
if (patient) {
|
||||||
|
patient.medicineWS.send(JSON.stringify(sendData))
|
||||||
}
|
}
|
||||||
|
if (flag==='0') {
|
||||||
return new Promise((resolve) => {
|
setTimeout(() => {
|
||||||
patient.medicineWS.onmessage = (e: any) => {
|
cb(flag)
|
||||||
const msg = JSON.parse(e.data)
|
}, 100);
|
||||||
if (msg && msg.msgType === 'unityResponseConnection') {
|
|
||||||
if (msg.unityConnectionFlag === '1') {
|
|
||||||
// unity回应 连接成功
|
|
||||||
resolve(1);
|
|
||||||
}
|
}
|
||||||
if (msg.unityConnectionFlag === '0') {
|
|
||||||
// unity回应连接失败, or unity请求断连
|
|
||||||
resolve(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
subscribeMedicine(name: string, id: string, date: string, index: number, cb: any) {
|
subscribeMedicine(name: string, id: string, date: string, index: number, cb: any) {
|
||||||
|
@ -333,11 +319,17 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
||||||
patient.medicineWS.onmessage = (e: any) => {
|
patient.medicineWS.onmessage = (e: any) => {
|
||||||
if (e && e.data) {
|
if (e && e.data) {
|
||||||
const data = JSON.parse(e.data);
|
const data = JSON.parse(e.data);
|
||||||
if (data.msgType == "msg") {
|
|
||||||
|
if (data.msgType==='msg') {
|
||||||
cb(e)
|
cb(e)
|
||||||
} else {
|
} else {
|
||||||
patient.medicineWS.send(JSON.stringify({msgType: "heartbeat"}))
|
patient.medicineWS.send(JSON.stringify({msgType: "heartbeat"}))
|
||||||
}
|
}
|
||||||
|
// 抛出信息用于vue页面监听
|
||||||
|
const shouldCallBackList=['pong','unityRequestConnection','unityResponseConnection']
|
||||||
|
if (shouldCallBackList.includes(data.msgType)) {
|
||||||
|
cb(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -347,6 +339,12 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
loopSendMedicinePing(name: string, id: string, date: string, index: number, cb: any){
|
||||||
|
const patient = this.patient[name + id + date + index]
|
||||||
|
if (patient) {
|
||||||
|
patient.medicineWS.send(JSON.stringify({msgType: "ping"}))
|
||||||
|
}
|
||||||
|
},
|
||||||
medicineOnclose(name: string, id: string, date: string, index: number, cb: any) {
|
medicineOnclose(name: string, id: string, date: string, index: number, cb: any) {
|
||||||
const patient = this.patient[name + id + date + index]
|
const patient = this.patient[name + id + date + index]
|
||||||
patient.medicineWS.onclose = () => {
|
patient.medicineWS.onclose = () => {
|
||||||
|
@ -385,6 +383,7 @@ export const useRemoteWsStore = defineStore("remoteWs", {
|
||||||
medicine: string,
|
medicine: string,
|
||||||
value: string
|
value: string
|
||||||
}, cb: any) {
|
}, cb: any) {
|
||||||
|
|
||||||
const patient: any = this.patient[args.name + args.id + args.date + args.index]
|
const patient: any = this.patient[args.name + args.id + args.date + args.index]
|
||||||
if (patient) {
|
if (patient) {
|
||||||
const params = {
|
const params = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user