安琪酵母(西藏)益生菌信息采集中心智能实验室
longyvfengyun
2023-08-24 079131b6a70ecec89a98fcf80894758847718f96
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
105
import {reactive, ref} from "vue";
import air from "@/assets/js/const/air";
import {getAirParam, setAirParam} from "@/views/airConditioning/js/api";
import {ElLoading, ElMessage} from "element-plus";
 
const airControlModule = ()=>{
  const cmd = air.cmd;
  const isCanSet = ref(false);
  const airParam = reactive({
    num: 1,
    devId: 210000001,
    opCmd: 0,
    stHumid: 0,
    stTemp: 0,
  });
  /**
   * 读取放电参数
   */
  const getParam = ()=>{
    const loading = ElLoading.service({
      lock: false,
      text: '数据加装中',
      background: 'rgba(0, 0, 0, 0.3)',
    });
    getAirParam(210000001).then(res=>{
      let rs = res.data;
      let data = {
        num: 0,
        devId: 0,
        opCmd: 0,
        stHumid: 0,
        stTemp: 0,
      };
      if(rs.code === 1 && rs.data) {
        ElMessage({
          showClose: true,
          message: '读取成功',
          type: 'success',
        });
        data = rs.data2;
        isCanSet.value = true;
      }else {
        ElMessage({
          showClose: true,
          message: '读取失败',
          type: 'error',
        });
        isCanSet.value = false;
      }
      // 设置值
      airParam.stTemp = data.stTemp;
      airParam.stHumid =data.stHumid;
      airParam.devId = data.devId;
      airParam.num = data.num;
 
      loading.close();
      console.log(res);
    }).catch(error=>{
      isCanSet.value = false;
      loading.close();
      console.log(error);
    });
  }
 
  const setParam = async ()=>{
    const loading = ElLoading.service({
      lock: false,
      text: '数据加装中',
      background: 'rgba(0, 0, 0, 0.3)',
    });
    airParam.opCmd = cmd.set;
    try {
      const res = await setAirParam(airParam);
      loading.close();
      let rs = res.data;
      if(rs.code === 1 && rs.data) {
        ElMessage({
          showClose: true,
          message: '设置成功',
          type: 'success',
        });
        return Promise.resolve(true);
      }else {
        ElMessage({
          showClose: true,
          message: '设置失败',
          type: 'error',
        });
        return Promise.resolve(false);
      }
    }catch (error) {
      loading.close();
      console.log(error);
      return Promise.resolve(false);
    }
  }
 
  return {
    isCanSet,
    airParam,
    getParam,
    setParam,
  };
}
export default airControlModule;