安琪酵母(西藏)益生菌信息采集中心智能实验室
longyvfengyun
2023-10-09 d310c767eef62fc8202f531e7492ecd58779af72
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
import createWs from "@/assets/js/tools/websocket/createWs";
import regEquipType from "@/assets/js/tools/regEquipType";
import {ref, onMounted, computed} from "vue";
 
const airMonitorData = ()=>{
  const {
    SOCKET
  } = createWs("homePageSocket");
  const monitorData = ref({
    airFiltrationAlm: 0,      // 过滤报警 【1报警,0不报警】
    airHumid: 0, // 空调湿度
    airOnduty: 0,  // 值班运行状态 【1运行,0停止】
    airPressturbid: 0,   // 负压/排浊【1运行,0不运行】
    airSysAlm: 0,     // 系统故障【1报警,0不报警】
    airSysstate:0,   // 空调运行状态【1.运行,0停止】
    airTemp: 0,     // 温度
    commCount:140745, // 通信计数
    commErrCount: 0,  // 错误计数
    devId: 210000001, // 设备ID
    num: 1,         // 主键
    recordTime: "2023-08-24 09:16:04",  // 数据更新日期
  });
  const handleOpen = ()=>{}
  const handleMessage = (res)=>{
    const rs = JSON.parse(res.data);
    if(rs.code === 1 && rs.data) {
      const list = rs.data2;
      let data = {
        airFiltrationAlm: 0,      // 过滤报警 【1报警,0不报警】
        airHumid: 0, // 空调湿度
        airOnduty: 0,  // 值班运行状态 【1运行,0停止】
        airPressturbid: 0,   // 负压/排浊【1运行,0不运行】
        airSysAlm: 0,     // 系统故障【1报警,0不报警】
        airSysstate:0,   // 空调运行状态【1.运行,0停止】
        airTemp: 0,     // 温度
        commCount:140745, // 通信计数
        commErrCount: 0,  // 错误计数
        devId: 210000001, // 设备ID
        num: 1,         // 主键
        recordTime: "2023-08-24 09:16:04",  // 数据更新日期
      };
      for(let i=0; i<list.length;i++) {
        if(regEquipType(list[i].devId, 'air')) {
          data = list[i].envirAirState;
          break;
        }
      }
      // 设置空调监控数据的值
      monitorData.value = data;
    }
  }
  const airState = computed(()=>{
    const airPressturbid = monitorData.value.airPressturbid ===1?0:-1;
    const airSysstate = monitorData.value.airSysstate ===1?0:-1;
    const airOnduty = monitorData.value.airOnduty ===1?0:-1;
    const airFiltrationAlm = monitorData.value.airFiltrationAlm ===1?1:0;
    const airSysAlm = monitorData.value.airSysAlm ===1?1:0;
    return {
      airPressturbid,        // 负压/排浊【1运行,0不运行】
      airSysstate,           // 空调运行状态【1.运行,0停止】
      airOnduty,             // 值班运行状态 【1运行,0停止】
      airFiltrationAlm,      // 过滤报警 【1报警,0不报警】
      airSysAlm,             // 系统故障【1报警,0不报警】
    };
  });
  onMounted(()=>{
    SOCKET.value.addEventListener("open", handleOpen, false);
    SOCKET.value.addEventListener("message", handleMessage, false);
  });
 
  return {
    monitorData,
    airState
  };
}
 
export default airMonitorData;