| | |
| | | import { defineStore } from "pinia"; |
| | | import { ref } from "vue"; |
| | | import dayjs from "dayjs"; |
| | | import cache from "../utils/cache"; |
| | | import { EventSourcePolyfill } from "event-source-polyfill"; |
| | | import type { BedsideAuxiliaryScreen, SseMsgData } from "./type/bedsideAuxiliaryScreen.type"; |
| | | import type { Task } from "./type/task.type"; |
| | |
| | | formatDeviceData, |
| | | } from "./type/bedsideAuxiliaryScreen.type"; |
| | | import { ElMessage } from "element-plus/es"; |
| | | import { Local } from "@/utils/storage"; |
| | | |
| | | export const useBedsideAuxiliaryScreenStore = defineStore( |
| | | "bedsideAuxiliaryScreen", |
| | | () => { |
| | | /** 设备编号 */ |
| | | const deviceCode = ref<string>(cache.get("devcieCode") || ""); |
| | | const deviceCode = ref<string>(Local.get("devcieCode") || ""); |
| | | |
| | | /** 设备信息数据 */ |
| | | const deviceData = ref<BedsideAuxiliaryScreen>(defaultDeviceData()); |
| | |
| | | */ |
| | | const setDeviceCode = (code: string) => { |
| | | deviceCode.value = code; |
| | | cache.set("devcieCode", code); |
| | | Local.set("devcieCode", code); |
| | | }; |
| | | |
| | | /** |
| | |
| | | if (retryCount < maxRetryCount) { |
| | | const delay = baseRetryDelay * Math.pow(2, retryCount); // 指数退避 |
| | | retryCount++; |
| | | console.log(`[SSE] 第${retryCount}次重连,延迟${delay}ms`); |
| | | console.log(`[SSE] 第${retryCount}次重连,延迟${baseRetryDelay}ms`); |
| | | ElMessage.warning( |
| | | `链接服务失败, 第${retryCount}次重连,请耐心等待重连。。` |
| | | ); |
| | |
| | | const dataBody = JSON.parse(datax) as SseMsgData; |
| | | console.log("dataBody: ", dataBody); |
| | | // 倒计时提示文本 |
| | | if (dataBody.倒计时?.提醒文本) { |
| | | const taskTime = dayjs(dataBody.倒计时?.当前服务器时间).add(dataBody.倒计时?.设定提醒倒计时, 'minute') |
| | | if (dataBody.倒计时?.提醒文本 && Number(dataBody.倒计时?.设定提醒倒计时 > 0)) { |
| | | const serverTimeRaw = dataBody.倒计时?.当前服务器时间; |
| | | const reminderMinutes = Number(dataBody.倒计时?.设定提醒倒计时 ?? 0); |
| | | const serverTimeFormatted = serverTimeRaw.replace(' ', 'T'); |
| | | |
| | | const taskTime = dayjs(serverTimeFormatted).add(reminderMinutes, 'second'); |
| | | setSyncTask({ |
| | | deviceCode: dataBody.IOT信息.设备唯一编号, |
| | | recordCode: dataBody.透析状态?.透析单编号, |
| | | taskDate: taskTime.format('YYYY-MM-DD HH:mm'), |
| | | taskName: dataBody.倒计时?.提醒文本, |
| | | overdue: false, |
| | | sync: true, |
| | | countdown: dataBody.倒计时?.设定提醒倒计时 |
| | | }) |
| | | } else { |
| | | clearTask(); |
| | | } |
| | | |
| | | deviceData.value = formatDeviceData(dataBody); |
| | | deviceData.value = formatDeviceData(deviceData.value, dataBody); |
| | | } |
| | | }; |
| | | }; |