| | |
| | | import Stomp from 'stompjs' |
| | | import os from 'os' |
| | | var stompClient: Stomp.Client | null=null |
| | | |
| | | import { userInfoStore } from '@/stores/userInfo' |
| | |
| | | |
| | | let devices:Array<device>=[] |
| | | let clientCode:string='' |
| | | |
| | | /** |
| | | * 保存结果到vuex |
| | | * @param resultInfo 结果写入 |
| | | */ |
| | | const writeResult=(resultInfo:any)=>{ |
| | | if(devices.length>0){ |
| | | const deviceInfo=devices.find(de=>{de.deviceName===resultInfo.deviceName}) |
| | |
| | | type:"读卡器", |
| | | result:resultInfo.result, |
| | | resultTime:resultInfo.resultTime, |
| | | state:true |
| | | state:0 |
| | | } |
| | | ) |
| | | break |
| | |
| | | type:"体重秤", |
| | | result:resultInfo.result, |
| | | resultTime:resultInfo.resultTime, |
| | | state:true |
| | | state:0 |
| | | } |
| | | ) |
| | | break |
| | |
| | | type:"血压计", |
| | | result:resultInfo.result, |
| | | resultTime:resultInfo.resultTime, |
| | | state:true |
| | | state:0 |
| | | } |
| | | ) |
| | | break |
| | | default: |
| | | console.log('有配置类型没有匹配') |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | const writeStatu=(resultInfo:any)=>{ |
| | | if(devices.length>0){ |
| | | const deviceInfo=devices.find(de=>{ |
| | | console.log(de.deviceName,resultInfo.deviceName) |
| | | return de.deviceName===resultInfo.deviceName |
| | | }) |
| | | if(deviceInfo!==undefined){ |
| | | switch(deviceInfo.deviceType){ |
| | | case '读卡器': |
| | | sockteStore().setdkqSockte( |
| | | { |
| | | deviceName:resultInfo.deviceName, |
| | | type:"读卡器", |
| | | result:resultInfo.result, |
| | | resultTime:resultInfo.resultTime, |
| | | state:0 |
| | | } |
| | | ) |
| | | break |
| | | case "体重秤": |
| | | sockteStore().setweightState(resultInfo.status) |
| | | break |
| | | case "血压计": |
| | | sockteStore().setxyjSockte( |
| | | { |
| | | deviceName:resultInfo.deviceName, |
| | | type:"血压计", |
| | | result:resultInfo.result, |
| | | resultTime:resultInfo.resultTime, |
| | | state:0 |
| | | } |
| | | ) |
| | | break |
| | |
| | | alert("接收数据异常"); |
| | | } |
| | | }; |
| | | const callbackState=function(message:any){ |
| | | const callbackState=function(message:any) { |
| | | if (message.body) { |
| | | const data=JSON.parse(message.body) |
| | | if(data.deviceName) |
| | | if(data){ |
| | | writeStatu(data) |
| | | } |
| | | console.log(data,'设备心跳包数据') |
| | | writeResult(data) |
| | | } else { |
| | | alert("接收数据异常"); |
| | | } |
| | | } |
| | | const PatientCallback=function(message:any){ |
| | | if (message.body) { |
| | | const data=JSON.parse(message.body) |
| | | console.log(data,'患者信息读取') |
| | | } |
| | | |
| | | } |
| | | const connectCallback=function(){ |
| | | console.log("链接成功",stompClient) |
| | | const pcName= os.hostname() |
| | | // 订阅患者信息服务 |
| | | stompClient.subscribe(`/queue/patient/info/${pcName}`,PatientCallback) |
| | | console.log("链接成功",stompClient,pcName) |
| | | // 更新sockte链接状态 |
| | | sockteStore().setsockteIsLink(true) |
| | | console.log(sockteStore().isLink) |
| | | if(stompClient!==null){ |
| | | if(devices.length>0){ |
| | | devices.forEach(de=>{ |
| | | console.log(devices) |
| | | if(devices.length>0){ |
| | | devices.forEach(de=>{ |
| | | if(stompClient!==null){ |
| | | stompClient.subscribe(`/queue/${clientCode}/${de.deviceName}/result`,callback) |
| | | // /queue/{clientCode}/{deviceName}/keepalive |
| | | stompClient.subscribe(`/queue/${clientCode}/${de.deviceName}/keepalive`,callbackState) |
| | | stompClient.send(`/app/device/request/${clientCode}/${de.deviceName}`, {}, JSON.stringify({"deviceNumber":de.deviceName})); |
| | | }) |
| | | } |
| | | |
| | | |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | const error_callback=function(error:any){ |
| | |
| | | stompClient.connect({}, connectCallback,error_callback) |
| | | |
| | | } |
| | | export {creatorClient} |
| | | const sendPationCode=(codeStr:string)=>{ |
| | | if(stompClient!==null){ |
| | | stompClient.send(`/app/patient/info/get/${os.hostname()}`,{},codeStr) |
| | | } |
| | | } |
| | | export {creatorClient,sendPationCode} |