单应用项目,可以创建很多独立工具类页面 ,不用登录 初始化的页面
zhangchen
2025-07-18 fcd455b10a7f40d39a55c5182dc76646ecd7a7bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { defineStore } from "pinia";
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 bedsideBloodPressureMonitorData = ref({
      date_time: '',
      sbp: '',
      pulseRate: '',
      dbp: '',
      zuihouTime: '',
    });
 
    /** 设备信息数据 */
    const deviceData = ref<BedsideAuxiliaryScreen>(defaultDeviceData());
 
    /**
     * 设置设备编号
     * @param code
     */
    const setDeviceCode = (code: string) => {
      deviceCode.value = code;
      cache.set("devcieCode", code);
    };
 
    // SSE 相关状态
    const source = ref<EventSource | null>(null);
    const message = ref<string | null>(null);
    const isConnected = ref(false);
 
    /**
     * 连接 SSE 服务
     * @param url SSE 地址
     */
    const connect = (url: string) => {
      if (source.value) return; // 已连接,避免重复连接
 
      source.value = new EventSourcePolyfill(url, {
        heartbeatTimeout: 60000,
      });
 
      source.value.onopen = () => {
        console.log("[SSE] 连接成功");
        isConnected.value = true;
      };
 
      source.value.onerror = (e) => {
        console.warn("[SSE] 错误,等待重连中", e);
        isConnected.value = false;
      };
 
      source.value.onmessage = (e) => {
        console.log("[SSE] 消息:", 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)
        }
      };
    };
 
    /**
     * 关闭 SSE 连接
     */
    const close = () => {
      if (source.value) {
        source.value.close();
        source.value = null;
        isConnected.value = false;
        console.log("[SSE] 连接已关闭");
      }
    };
 
 
    return {
      deviceCode,
      deviceData,
      setDeviceCode,
      source,
      message,
      isConnected,
      connect,
      close,
    };
  }
);