commit: pre-二期

This commit is contained in:
republicline 2025-06-25 19:56:29 +08:00
parent 263c91f66c
commit b5e110081c
3 changed files with 194 additions and 18 deletions

View File

@ -2,12 +2,17 @@ import {defineStore} from "pinia";
import {Session} from "@/utils/storage";
import {ElMessage, ElMessageBox} from "element-plus";
// 本地调试版本:
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()
// // 本地调试版本:
// 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()
// 服务器部署版本
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()
// 服务器部署版本
// const vitalUrl = "wss://" + window.location.host + "/socket.io/admin/rax/vitalSignsMedicine?token=" + Session.getToken()
// // const medicineUrl = "wss://" + window.location.host + "/socket.io/admin/rax/addMedicine?token=" + Session.getToken()
@ -192,6 +197,7 @@ export const useRemoteWsStore = defineStore("remoteWs", {
disconnect(name: string, id: string, date: string, index: number) {
this.disconnectChat(name, id, date, index)
this.disconnectVital(name, id, date, index)
this.disconnectMedicine(name, id, date, index)
delete this.patient[name + id + date + index]
},
createVital(name: string, id: string, date: string, index: number) {
@ -395,6 +401,39 @@ export const useRemoteWsStore = defineStore("remoteWs", {
})
}
},
medicineOnclose(name: string, id: string, date: string, index: number, cb: any) {
const patient: any = this.patient[name + id + date + index]
patient.medicineWS.onclose = cb
},
unsubscribeMedicine(name: string, id: string, date: string, index: number) {
const patient: any = this.patient[name + id + date + index]
patient.medicineCB = undefined;
patient.medicineWS.onmessage = undefined;
},
/**
*
*/
// 初始化
createMedicineConnect(name: string, id: string, index: number) {
if (!this.patient[name + id + index]) this.patient[name + id + index] = {}
const patient = this.patient[name + id + index]
if (!patient['medicineWS']) {
patient['medicineWS'] = new WebSocket(medicineUrl)
patient.medicineWS.onopen = function () {
patient.medicineWS.send(JSON.stringify({
patientName: name,
idNum: id,
// date: date,
msgType: "init"
}))
if (this.loopSendMedicinePing) {
this.loopSendMedicinePing(name,id,index,()=>{})
}
}
}
},
subscribeMedicine(name: string, id: string, date: string, index: number, cb: any) {
const patient = this.patient[name + id + date + index]
if (patient) {
@ -416,14 +455,33 @@ export const useRemoteWsStore = defineStore("remoteWs", {
})
}
},
medicineOnclose(name: string, id: string, date: string, index: number, cb: any) {
disconnectMedicine(name: string, id: string, date: string, index: number) {
const patient: any = this.patient[name + id + date + index]
patient.medicineWS.onclose = cb
},
unsubscribeMedicine(name: string, id: string, date: string, index: number) {
const patient: any = this.patient[name + id + date + index]
patient.medicineCB = undefined;
patient.medicineWS.onmessage = undefined;
if (patient && patient.vitalWS) {
this.closeStatus[name + id + date + index + 'vitalWS'] = true
patient.medicineWS.close()
delete patient['medicineWS']
}
},
// 请求连接远程控制
reqMedicineConnect(params:{name: string, id: string,index: number, msgType: string, flag: string},cb:any){
const {name, id, index,msgType,flag} = params;
const patient = this.patient[name + id +index]
const sendData={
patientName: name,
idNum: id,
// date: date,
msgType: msgType,
webConnectionFlag: flag
}
if (patient) {
patient.medicineWS.send(JSON.stringify(sendData))
}
if (flag==='0') {
setTimeout(() => {
cb(flag)
}, 100);
}
},
}
})

View File

@ -49,6 +49,12 @@
<el-button color="#C77000" style="width: 200px;" @click="viewPatientInfo">患者信息</el-button>
<!-- <el-button color="#C77000" style="width: 150px;">已连接</el-button>-->
<!-- <el-button color="#C77000" >机器人运行正常</el-button>-->
<el-button color="#C77000" @click="connectionUnity('1')" v-if="!whetherControl">连接远程控制
</el-button>
<template v-else>
<el-button color="#C77000">已控制</el-button>
<el-button color="#C77000" @click="connectionUnity('0')">断开远程控制</el-button>
</template>
</div>
<el-button color="#e0e0e0" @click="backRemote">
<el-icon>
@ -219,7 +225,7 @@
</template>
<script lang="ts" setup>
import {onMounted, onUnmounted, onUpdated, reactive, ref} from 'vue';
import {onMounted, onUnmounted, onUpdated, reactive, ref, watch} from 'vue';
import {useRouter} from 'vue-router'
import {ElMessage, ElMessageBox} from 'element-plus';
import {dateFormater} from '@/utils/date-util';
@ -319,6 +325,7 @@ onUnmounted(() => {
function subscribeWS() {
subscribeVital()
subscribeChat()
subscribeMedicine()
/*remoteWsStore.subscribeMedicine(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, index,
function (res: any) {
const data = JSON.parse(res.data);
@ -392,8 +399,6 @@ const subscribeChat = () => {
}
function initData() {
lungAlarm.value = false;
heartAlarm.value = false;
@ -658,7 +663,120 @@ function startAI() {
});
}
/**
* 远程控制
*/
const whetherControl = ref(false);
const connectionUnityLoading = ref(false);
const subscribeMedicineData = ref(null);
function connectionUnity(flag: string) {
if (flag === "1") {
console.log("连接远程控制");
connectionUnityLoading.value = true
} else {
console.log("断开远程控制");
connectionUnityLoading.value = false
}
const params: any = {
name: currentRemote.value.patient,
id: currentRemote.value.patientId,
// date: currentRemote.value.date,
index: currentRemote.value.index,
msgType: "webRequestConnection",
flag
}
remoteWsStore.reqMedicineConnect(params, () => {
connectionUnityLoading.value = false
});
setTimeout(() => {
if (connectionUnityLoading.value) {
connectionUnityLoading.value = false
}
}, 10000)
//
}
const onMedicineClose = () => {
remoteWsStore.medicineOnclose(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentRemote.value.index, () => {
ElMessage.info('远程控制' + (currentRemote.value.index + 1) + ' 给药连接断开,正在尝试重连……')
setTimeout(() => {
remoteWsStore.createMedicineConnect(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.index)
subscribeMedicine()
}, 3000)
})
}
const subscribeMedicine = () => {
onMedicineClose()
remoteWsStore.createMedicineConnect(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.index)
remoteWsStore.subscribeMedicine(currentRemote.value.patient, currentRemote.value.patientId, currentRemote.value.date, currentRemote.value.index,
(res: any) => {
const data = JSON.parse(res.data);
subscribeMedicineData.value = data;
if (data.status != 1) {
if (data.medicine) {
if (varTableData.value[data.medicine]) varTableData.value[data.medicine] = medicineSpeedTemp[data.medicine];
if (fixedTableData.value[data.medicine]) fixedTableData.value[data.medicine] = medicineSpeedTemp[data.medicine];
}
} else {
ElMessage.error(data.msg)
}
})
}
watch(subscribeMedicineData, (newValue: any, oldValue: any) => {
if (newValue) {
const {msgType, unityConnectionFlag, msg} = newValue;
switch (msgType) {
case 'unityRequestConnection':
const params: any = {
name: currentRemote.value.patient,
id: currentRemote.value.patientId,
date: currentRemote.value.date,
index: currentRemote.value.index,
msgType: "webResponseConnection",
flag: "1"
}
ElMessageBox.confirm('确定接受远程控制', '确认提示', {
confirmButtonText: '确定',
cancelButtonText: '拒绝',
})
.then(() => {
whetherControl.value = unityConnectionFlag === '1';
remoteWsStore.reqMedicineConnect({...params, flag: unityConnectionFlag}, (res: any) => {
console.log('res >>>>>', res);
});
})
.catch(() => {
//
whetherControl.value = false;
remoteWsStore.reqMedicineConnect({...params, flag: '0'}, (res: any) => {
console.log('res >>>>>', res);
});
});
break;
case 'unityResponseConnection':
connectionUnityLoading.value = false
whetherControl.value = unityConnectionFlag === '1';
if (unityConnectionFlag === '1') {
ElMessage.success('连接成功')
} else {
ElMessage.info('连接断开')
}
break;
case 'getMedicine':
ElMessage.success('给药成功')
break;
case 'pong':
// timeDiffPing.value = newValue.msg;
break;
case 'connectionMsg':
ElMessage.info(msg)
default:
break;
}
}
})
</script>
<style lang="scss" scoped>

View File

@ -26,15 +26,15 @@ export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://127.0.0.1:6679', // 目标服务器地址
// target: 'http://110.41.142.124:6679', // 目标服务器地址
// target: 'http://127.0.0.1:6379', // 目标服务器地址
target: 'http://110.41.142.124:6379', // 目标服务器地址
ws: true, // 是否启用 WebSocket
changeOrigin: true, // 是否修改请求头中的 Origin 字段
rewrite: (path) => path.replace(/^\/api/, ''),
},
'/socket.io': {
target: 'ws://127.0.0.1:6679',
// target: 'ws://110.41.142.124:6679',
// target: 'ws://127.0.0.1:6379',
target: 'ws://110.41.142.124:6379',
ws: true,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/socket.io/, ''),