From dc7afd089a74edf6a9e50d0eb3e0607d09e72548 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期五, 08 七月 2022 17:15:29 +0800
Subject: [PATCH] confingUpdete

---
 src/views/home/index.vue   |  189 ++++++++++++++++++++++++++++---
 src/samples/sockteStomp.ts |   67 +++++++++-
 src/samples/node-api.ts    |   31 ++++
 package.json               |    1 
 src/samples/timerServer.ts |    1 
 electron/main/index.ts     |   28 +++
 src/stores/patient.ts      |   17 ++
 src/stores/sockteInfo.ts   |   12 +
 8 files changed, 302 insertions(+), 44 deletions(-)

diff --git a/electron/main/index.ts b/electron/main/index.ts
index 6ead326..f68297a 100644
--- a/electron/main/index.ts
+++ b/electron/main/index.ts
@@ -8,6 +8,7 @@
 const Store = require('electron-store');
 const  store = new Store();
 console.log(store.path)
+
 // 读
 // console.log(store.get('clientCode'))
 // console.log(store.get('deviceList'))
@@ -52,7 +53,8 @@
   // 测试推送消息到Renderer进程
   win.webContents.on('did-finish-load', () => {
     win?.webContents.send('main-process-message', new Date().toLocaleString())
-    win?.webContents.send('getConfigData',store.get('clientCode'),store.get('deviceList'),store.path)
+    win?.webContents.send('getConfigData',store.get('clientCode'),store.get('devices'),store.path)
+    win?.webContents.send('getScreenTimeout',store.get('screenTimeout'))
   })
 
   // Make all links open with the browser, not with the application
@@ -108,8 +110,24 @@
 ipcMain.on("main-process-message2",()=>{
   console.log("33344")
 })
-// 渲染端发送消息到主进程
-ipcMain.on('synchronous-message', (event, arg) => {
-  console.log(arg) // 在 Node 控制台中打印“ping”
-  event.returnValue = store.get('clientCode')
+// 渲染端发送消息到主进程修改confing文件
+ipcMain.on('setConfingData', (event, arg) => {
+  const mode1=store.store
+  const mode2={
+    "clientCode": arg.clientCode,
+    "machineName": arg.machineName,
+    "screenTimeout": arg.screenTimeout,
+    "devices":arg.devices
+  }
+  //对比两端配置文件
+  if(JSON.stringify(mode1)!=JSON.stringify(mode2)){
+    //更新cofing.json
+    console.log('update confing.json')
+    store.set(mode2)
+    // 重新建立sockte 通讯
+    win?.webContents.send('getConfigData',store.get('clientCode'),store.get('devices'),store.path)
+    win?.webContents.send('getScreenTimeout',store.get('screenTimeout'))
+  }
+  
+  
 })
\ No newline at end of file
diff --git a/package.json b/package.json
index 5e0cc35..65f4246 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,7 @@
     "iconv-lite": "^0.6.3",
     "internet-available": "^1.0.0",
     "pinia": "^2.0.14",
+    "sound-play": "^1.1.0",
     "stompjs": "^2.3.3",
     "vue-router": "^4.0.16"
   }
diff --git a/src/samples/node-api.ts b/src/samples/node-api.ts
index cd7aa76..faf35ee 100644
--- a/src/samples/node-api.ts
+++ b/src/samples/node-api.ts
@@ -1,10 +1,14 @@
-import { lstat } from 'fs/promises'
+
 import { cwd } from 'process'
 import { ipcRenderer } from 'electron'
 import {creatorClient} from './sockteStomp'
 import {sockteStore} from '@/stores/sockteInfo'
+import { patientInfoStore } from '@/stores/patient'
+import os from 'os'
 // import internetAvailable  from "internet-available"
 var internetAvailable = require("internet-available")
+import { ElMessage, ElMessageBox } from 'element-plus'
+import { on } from 'events'
 let deviceList=[]
 let clientCode=''
 // 主进程发送消息到渲染进程
@@ -15,7 +19,23 @@
 ipcRenderer.on('getConfigData',(_event,...args)=>{
   console.log("config.json",...args)
   if(args[0]===undefined){
-    alert("配置文件没有写入配置,请检查配置文件 文件路径:"+args[2])
+    // alert("配置文件没有写入配置,请检查配置文件 文件路径:"+args[2])
+    ElMessageBox.prompt('没有设定客户编号,请输入客户编号并保存', '警告', {
+      confirmButtonText: '保存',
+      showClose:false,
+      showCancelButton:false,
+      inputErrorMessage: 'Invalid Email',
+    })
+      .then(({ value }) => {
+        const mode={
+          clientCode:value,
+          machineName:os.hostname(),
+          screenTimeout: 300,
+          devices:[]
+        }
+        ipcRenderer.send('setConfingData',mode)
+      }) 
+    
   }
   else if(args.length>0&&args[0].length>0){
     clientCode=args[0]
@@ -24,17 +44,20 @@
     creatorClient(deviceList,clientCode)
   }
 })
-
+ipcRenderer.on("getScreenTimeout",(_event,args)=>{
+  console.log(args,'得到配置文件时间')
+  patientInfoStore().setViewNumber(args)
+})
 setInterval(function(){
   // 检查网络状态
   internetAvailable({
     domainName: "baidu.com",
     host: '114.114.114.114' 
   }).then(()=>{
-    console.log('网路已连接')
     sockteStore().setnetLink(true)
   }).catch(()=>{
     sockteStore().setnetLink(false)
     console.log("网路链接失败")
   })
 },10000)
+
diff --git a/src/samples/sockteStomp.ts b/src/samples/sockteStomp.ts
index 38460f8..0007296 100644
--- a/src/samples/sockteStomp.ts
+++ b/src/samples/sockteStomp.ts
@@ -1,9 +1,13 @@
 import Stomp from 'stompjs'
 import os from 'os'
+import { ipcRenderer } from 'electron'
 var stompClient: Stomp.Client | null=null
 
 import { userInfoStore } from '@/stores/userInfo'
+import { patientInfoStore } from '@/stores/patient'
 import {sockteStore} from '@/stores/sockteInfo'
+import { result } from 'lodash'
+const sound = require("sound-play");
 
 
 
@@ -24,7 +28,7 @@
         const deviceInfo=devices.find(de=>{
             return de.deviceName===resultInfo.deviceNumber
         })
-        console.log('---1-',deviceInfo)
+        console.log(deviceInfo,'更具设备number查找到的设备')
         if(deviceInfo!==undefined){
             switch(deviceInfo.deviceType){
                 case '读卡器':
@@ -34,7 +38,7 @@
                             type:"读卡器",
                             result:resultInfo.result,
                             resultTime:resultInfo.resultTime,
-                            state:0
+                            state:2
                         }
                     )
                     break
@@ -46,18 +50,19 @@
                             type:"体重秤",
                             result:resultInfo.result,
                             resultTime:resultInfo.resultTime,
-                            state:0
+                            state:2
                         }
                     )
                     break
                 case "血压计":
+                    console.log(resultInfo,'血压计')
                     sockteStore().setxyjSockte(
                         {
                             deviceName:resultInfo.deviceNumber,
                             type:"血压计",
                             result:resultInfo.result,
                             resultTime:resultInfo.resultTime,
-                            state:0
+                            state:2
                         }
                     )
                     break
@@ -108,13 +113,29 @@
     }
 
 }
+const writePatient=(resultInfo:any)=>{
+    const info={
+        id:resultInfo.patientInfo===null?0:resultInfo.patientInfo.id,
+        code:resultInfo.patientInfo===null?'':resultInfo.patientInfo.code,
+        name:resultInfo.patientInfo===null?0:resultInfo.patientInfo.patientName,
+        patientAvatarIcon:resultInfo.patientInfo===null?0:resultInfo.patientInfo.patientAvatarIcon,
+        deviceCode:resultInfo.deviceCode===null?"":resultInfo.deviceCode,
+        hemoCode:resultInfo.hemoCode===null?"":resultInfo.hemoCode,
+        pureWeight:resultInfo.pureWeight===null?"":resultInfo.pureWeight
+    }
+    // 写入vuex里
+    patientInfoStore().setpatientInfo(info)
+    console.log('播放声音')
+    // sound.play("https://dhcdn.leon056.com/hemo/autoselfsign/step2.mp3")
+    
+
+}
 
 // 订阅结果事件返回函数
 const  callback = function(message:any) {
     console.log('接收到数据-----',message.body)
     if (message.body!==undefined) {
         const data=JSON.parse(message.body)
-        console.log(data,"体重数据")
         writeResult(data)
     }
     else {
@@ -134,21 +155,34 @@
     if (message.body) {
         const data=JSON.parse(message.body)
         console.log(data,'患者信息读取')
+        writePatient(data)
+
     }
     
+}
+const configCallback =function(message:any){
+    if(message.body){
+        const data=JSON.parse(message.body)
+        console.log(data,'配置文件读取')
+        ipcRenderer.send('setConfingData',data)
+        
+    }
 }
 const connectCallback=function(){
     const pcName= os.hostname()
     // 订阅患者信息服务
     if(stompClient!==null){
         stompClient.subscribe(`/queue/patient/info/${pcName}`,PatientCallback)
+        stompClient.subscribe(`/queue/workstation/config/set/${clientCode}/${pcName}`,configCallback)
+        stompClient.send(`/app/workstation/config/set/${clientCode}/${pcName}`,{},JSON.stringify({"clientCode":clientCode,"machineName":pcName}))
+        
     }
     console.log("链接成功",stompClient,pcName)
     // 更新sockte链接状态
     sockteStore().setsockteIsLink(true)
     console.log(sockteStore().isLink)
     console.log(devices)
-    if(devices.length>0){
+    if(devices!==undefined&&devices.length>0){
         devices.forEach(de=>{
             if(stompClient!==null){
                 stompClient.subscribe(`/queue/${clientCode}/${de.deviceName}/result`,callback)
@@ -181,9 +215,26 @@
     stompClient.connect({}, connectCallback,error_callback)
 
 }
+/**
+ * 发送患者卡号返回患者信息
+ * @param codeStr 
+ */
 const sendPationCode=(codeStr:string)=>{
+    const mode={
+        clientCode:clientCode,
+        queryCode:codeStr
+    }
     if(stompClient!==null){
-        stompClient.send(`/app/patient/info/get/${os.hostname()}`,{},codeStr)
+        stompClient.send(`/app/patient/info/get/${os.hostname()}`,{},JSON.stringify(mode))
     }
 }
-export {creatorClient,sendPationCode}
+/**
+ * 
+ * @param mode 发送结果到sockt服务
+ */
+const sendPationSet=(mode:any)=>{
+    if(stompClient!==null){
+        stompClient.send(`/app/patient/info/set`,{},JSON.stringify(mode))
+    }
+}
+export {creatorClient,sendPationCode,sendPationSet}
diff --git a/src/samples/timerServer.ts b/src/samples/timerServer.ts
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/src/samples/timerServer.ts
@@ -0,0 +1 @@
+
diff --git a/src/stores/patient.ts b/src/stores/patient.ts
index e9750fa..ad5dd5e 100644
--- a/src/stores/patient.ts
+++ b/src/stores/patient.ts
@@ -3,10 +3,23 @@
 import { Session } from '@/utils/storage'
 
 export const patientInfoStore =defineStore('patientInfo',()=>{
-    const patientInfo=ref({id:0,code:'',patientCode:'',schemeName:'',scheduleDate:'',patientPreHemoWeight:0,pureWeight:0,confirmUserInfo:{userName:''},patientInfo:{patientName:'',patientGender:0,age:'',patientHemoCode:''},deviceInfo:{deviceNo:''}})// 初始值
+    const patientInfo=ref({
+            id:0,
+            code:'',
+            name:'',
+            patientAvatarIcon:'',
+            deviceCode:'',
+            hemoCode:'',
+            pureWeight:''
+
+       })// 初始值
+    const viewNumber=ref(60)
     function setpatientInfo(patient:any){
         patientInfo.value=patient
         Session.set('patientInfo', patient)
     }
-    return {patientInfo,setpatientInfo}
+    function setViewNumber(num:any){
+        viewNumber.value=num
+    }
+    return {patientInfo,setpatientInfo,viewNumber,setViewNumber}
 })
\ No newline at end of file
diff --git a/src/stores/sockteInfo.ts b/src/stores/sockteInfo.ts
index 319c934..1f8aeff 100644
--- a/src/stores/sockteInfo.ts
+++ b/src/stores/sockteInfo.ts
@@ -7,32 +7,32 @@
     deviceName:string;
     result:string;
     resultTime:string;
-    state:0;
+    state:number;
 }
 
 let weightInfo:info={
     type:"体重秤",
-    state:0,
+    state:2,
     deviceName:"",
     result:"0",
     resultTime:""
 } 
 let xyjInfo:info={
     type:"血压计",
-    state:0,
+    state:2,
     deviceName:"",
     result:"",
     resultTime:""
 } 
 let dkqInfo:info={
     type:"读卡器",
-    state:0,
+    state:2,
     deviceName:"",
     result:"",
     resultTime:""
 }
 export const sockteStore =defineStore('sockteInfo',()=>{
-    const isLink=ref(false) // sockte 链接状态
+    const isLink=ref(true) // sockte 链接状态
     const netLink=ref(true) // 网络链接状态
     const weightSockte=ref(weightInfo) // 体重秤sockte结果
     const xyjSockte=ref(xyjInfo) // 血压计sockte结果
@@ -53,6 +53,7 @@
         weightSockte.value.deviceName=info.deviceName
         weightSockte.value.result=info.result
         weightSockte.value.resultTime=info.resultTime
+        weightSockte.value.state=info.state
     }
      /**
      * 更新体重秤工作状态
@@ -69,6 +70,7 @@
         xyjSockte.value.deviceName=info.deviceName
         xyjSockte.value.result=info.result
         xyjSockte.value.resultTime=info.resultTime
+        weightSockte.value.state=info.state
     }
       /**
      * 更新血压计结果
diff --git a/src/views/home/index.vue b/src/views/home/index.vue
index 02947a8..e1a76c2 100644
--- a/src/views/home/index.vue
+++ b/src/views/home/index.vue
@@ -1,15 +1,22 @@
 <script lang="ts">
 import { userInfoStore } from '@/stores/userInfo'
 import { sockteStore } from '@/stores/sockteInfo'
+import { patientInfoStore } from '@/stores/patient'
 import { ipcRenderer } from 'electron'
-import { reactive,computed, toRefs,onMounted ,ref} from "vue"
-import{sendPationCode} from '../../samples/sockteStomp'
+import os from "os"
+import { reactive,computed, toRefs,onMounted ,ref,watch} from "vue"
+import{sendPationCode,sendPationSet} from '../../samples/sockteStomp'
 import {formatDate} from '@/utils/formatTime'
  export default {
         setup() {
+            let  timer:any=0
             const user = userInfoStore()
             const sockte= sockteStore()
             const inputRef=ref()
+            const AudioRef0=ref()
+            const AudioRef=ref()
+            const AudioRef2=ref()
+            const AudioRef3=ref()
             const isLink= computed(()=>{
                 return !sockte.isLink
             }) 
@@ -19,36 +26,178 @@
             const weightInfo= computed(()=>{
                 return sockte.weightSockte
             })
+            const xyjInfo= computed(()=>{
+                return sockte.xyjSockte
+            })
+            const patientInfo=computed(()=>{
+                return patientInfoStore().patientInfo
+            })
+            const viewNumber=computed(()=>{
+                return patientInfoStore().viewNumber
+            })
+
+            const settime=()=>{
+                // 计数倒计时
+                state.clockNum=patientInfoStore().viewNumber
+                // 清除定时器
+                clearInterval(state.timerNum)
+                console.log('------------------')
+                timer= setInterval(() => {
+                    if (state.clockNum > 0) {
+                        state.clockNum--
+                    }
+                    else {
+                        clearInterval(timer)
+                        patientInfoStore().setpatientInfo({
+                            id:0,
+                            code:'',
+                            name:'',
+                            patientAvatarIcon:'',
+                            deviceCode:'',
+                            hemoCode:'',
+                            pureWeight:''
+                        })
+                        state.clockNum = patientInfoStore().viewNumber
+                    }
+                }, 1000)
+                // 记录定时器
+                state.timerNum=timer
+                console.log(timer)
+            }
             const state=reactive({
                 dialogVisible:false,
                 isActive:false,
                 inputCode:"",
-                Newdate:""
+                Newdate:"",
+                clockNum:60,
+                timerNum:0,//定时器数
+                aimTSL:0,// 目标脱水量,
+                gao_ya:"",//高压
+                di_ya:"",//低压
+                mai_bu:""//脉搏
             })
+            watch(
+                ()=>patientInfo.value.id,
+                ()=>{
+                    console.log('患者变化了',patientInfo)
+                    if(patientInfo.value.id!==0)
+                    {
+                        AudioRef.value.play();
+                        sockteStore().setweightSockte({
+                            type:"体重秤",
+                            state:2,
+                            deviceName:"",
+                            result:"0",
+                            resultTime:""
+                        })
+                        sockteStore().setxyjSockte({
+                            type:"血压计",
+                            state:2,
+                            deviceName:"",
+                            result:"",
+                            resultTime:""
+                        })
+                        settime()
+                       
+                    }
+                }
+            )
+            watch(
+                ()=>weightInfo.value.resultTime,
+                ()=>{
+                    settime()
+                    console.log("体重变化了")
+                    // AudioRef2.value.play()
+                    if(patientInfo.value.id===0){
+                        AudioRef0.value.play()
+                    }
+                    else{
+                        AudioRef2.value.play()
+                        // 发送结果到sockte服务
+                        const mode={
+                            patientCode:patientInfo.value.code,
+                            weight:weightInfo.value.result,
+                            bloodPressure:''
+
+                        }
+                        console.log('发送患者结果',mode)
+                        sendPationSet(mode)
+                        // 计算目标脱水量
+                        if(Number(weightInfo.value.result)>0&&Number(patientInfo.value.pureWeight)!==0){
+                            state.aimTSL=Number(weightInfo.value.result)-Number(patientInfo.value.pureWeight)
+                        }
+                    }
+                }
+            )
+            watch(
+                ()=>xyjInfo.value.resultTime,
+                ()=>{
+                    if(xyjInfo.value.result!==''){
+                        const list=xyjInfo.value.result.split(',')
+                        if(list.length===3){ 
+                            state.gao_ya=list[0]
+                            state.di_ya=list[1]
+                            state.mai_bu=list[2]
+                        }
+                        if(patientInfo.value.id===0){
+                            AudioRef0.value.play()
+                            settime()
+                        }else{
+                            AudioRef3.value.play()
+                            settime()
+                            const mode={
+                                patientCode:patientInfo.value.code,
+                                weight:weightInfo.value.result,
+                                bloodPressure:xyjInfo.value.result
+
+                            }
+                            console.log('发送患者结果',mode)
+                            sendPationSet(mode)
+                        }    
+                    }else{
+                        state.gao_ya=""
+                        state.di_ya=""
+                        state.mai_bu=""
+                    }
+                }
+            )
+            watch(()=>viewNumber,
+                ()=>{
+                    state.clockNum=viewNumber.value
+                }
+            )
             const inputChabge=()=>{
                 sendPationCode(state.inputCode)
+                setTimeout(function(){
+                    state.inputCode=''
+                },1000)
             }
             onMounted(() => {
-                console.log('Component is mounted!')
-                inputRef.value.focus();
-                console.log(inputRef)
+                console.log('页面初始化',os.hostname())
+                state.clockNum=patientInfoStore().viewNumber
                 setTimeout(function(){
-                    // state.inputCode="3434"
-                    console.log('-----------sdsds')
+                    console.log('7秒后操作')
                     inputRef.value.focus();
-                },10000)
+                },7000)
                 setInterval(function(){
                     state.Newdate=formatDate(new Date(),"YYYY-mm-dd HH:MM:SS")
-                    // console.log(state.Newdate,'----ss')
                 },1000)
             })
-            return{ ...toRefs(state),isLink,netLink,weightInfo,inputRef,inputChabge
+            return{ ...toRefs(state),isLink,netLink,weightInfo,patientInfo,inputRef,AudioRef0,AudioRef,AudioRef2,AudioRef3,inputChabge
             }
         }
     }
 </script>
 <template>
     <div class="home">
+        <!-- 提醒刷卡 -->
+        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step1.mp3" ref="AudioRef0" id="eventAudio"></audio>
+        <!-- 患者信息读取成功 -->
+        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step2.mp3" ref="AudioRef" id="eventAudio"></audio>
+        <!-- 体重结果回传成功 -->
+        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step3.mp3" ref="AudioRef2" id="eventAudio"></audio>
+        <!-- 血压结果回传成功 -->
+        <audio src="https://dhcdn.leon056.com/hemo/autoselfsign/step4.mp3" ref="AudioRef3" id="eventAudio"></audio>
         <el-dialog
             title="提示"
             v-model="netLink"
@@ -75,7 +224,7 @@
             </el-col>
             <el-col :span="6">
                 <div class="datess">
-                    60
+                    {{clockNum}}
                 </div>
             </el-col>
         </el-row>
@@ -85,9 +234,9 @@
                     shape="square"
                     :size="100"
                     fit="cover"
-                    src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
+                    :src="patientInfo.patientAvatarIcon"
                 />
-                <div class="zsf">张三丰</div>
+                <div class="zsf">{{patientInfo.name}}</div>
             </div>
             <div class="grid-item">
                 <div class="lableText">当前时间:</div>
@@ -95,19 +244,19 @@
             </div>
             <div class="grid-item">
                 <div class="lableText">透析号:</div>
-                <div class="conText">123456</div>
+                <div class="conText">{{patientInfo.hemoCode}}</div>
             </div>
             <div class="grid-item">
                 <div class="lableText">机号:</div>
-                <div class="conText">001</div>
+                <div class="conText">{{patientInfo.deviceCode}}</div>
             </div>
             <div class="grid-item">
                 <div class="lableText">序号:</div>
-                <div class="conText">10</div>
+                <div class="conText">0</div>
             </div>
             <div class="grid-item">
                 <div class="lableText">干体重(kg):</div>
-                <div class="conText">88</div>
+                <div class="conText">{{patientInfo.pureWeight}}</div>
             </div>
             <div class="grid-item" >
                 <div>
@@ -119,11 +268,11 @@
             </div>
             <div class="grid-item">
                 <div class="lableText">目标脱水量:</div>
-                <div class="conText">2</div>
+                <div class="conText">{{aimTSL}}</div>
             </div>
             <div class="grid-item">
                 <div class="lableText">血压:</div>
-                <div class="conText">140/90</div>
+                <div class="conText">{{gao_ya}}/{{di_ya}}</div>
             </div>
         </div>
     </div>

--
Gitblit v1.8.0