| | |
| | | import { ref } from "vue"; |
| | | import cache from "../utils/cache"; |
| | | import { EventSourcePolyfill } from "event-source-polyfill"; |
| | | import type { BedsideAuxiliaryScreen } from './type/bedsideAuxiliaryScreen.type'; |
| | | import { defaultDeviceData, defaultconsumablesCollection, formatDeviceData } from './type/bedsideAuxiliaryScreen.type'; |
| | | |
| | | |
| | | export const useBedsideAuxiliaryScreenStore = defineStore( |
| | | "bedsideAuxiliaryScreen", |
| | | () => { |
| | | const deviceCode = ref<string>(cache.get("devcieCode") || ""); // 设备编号 |
| | | /** 设备编号 */ |
| | | const deviceCode = ref<string>(cache.get("devcieCode") || ""); |
| | | |
| | | /** 床旁血压计数据 */ |
| | | const bedsideBloodPressureMonitorData = ref({ |
| | | date_time: '', |
| | | sbp: '', |
| | | pulseRate: '', |
| | | dbp: '', |
| | | zuihouTime: '', |
| | | }); |
| | | |
| | | /** 设备信息数据 */ |
| | | const deviceData = ref<BedsideAuxiliaryScreen>(defaultDeviceData()); |
| | | |
| | | /** |
| | | * 设置设备编号 |
| | |
| | | |
| | | source.value.onmessage = (e) => { |
| | | console.log("[SSE] 消息:", e.data); |
| | | message.value = e.data; |
| | | const msg = e.data; |
| | | let dif = msg.indexOf("event:message"); |
| | | let beng = msg.indexOf("{"); |
| | | let end = msg.length - 1; |
| | | if (beng !== -1 && end !== -1 && dif !== -1) { |
| | | const datax = msg.slice(beng, end + 1); |
| | | const dataBody = JSON.parse(datax); |
| | | console.log('dataBody: ', dataBody) |
| | | // 倒计时提示文本 |
| | | if (dataBody.倒计时?.提示文本) {} |
| | | |
| | | deviceData.value = formatDeviceData(dataBody) |
| | | } |
| | | }; |
| | | }; |
| | | |
| | |
| | | console.log("[SSE] 连接已关闭"); |
| | | } |
| | | }; |
| | | |
| | | |
| | | return { |
| | | deviceCode, |
| | | deviceData, |
| | | setDeviceCode, |
| | | source, |
| | | message, |
| | | isConnected, |
| | | connect, |
| | | close |
| | | close, |
| | | }; |
| | | } |
| | | ); |