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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
| import {reactive, ref} from "vue";
| import air from "@/assets/js/const/air";
| import {controlAir, 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);
| });
| }
|
| /**
| * 设置参数
| * @return {Promise<Awaited<boolean>>}
| */
| 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);
| }
| }
|
| const startAir = async (opCmd)=>{
| const loading = ElLoading.service({
| lock: false,
| text: '执行中...',
| background: 'rgba(0, 0, 0, 0.3)',
| });
| let msg = "";
| switch (opCmd) {
| case 0x30:
| msg = "启动空调工作";
| break;
| case 0x32:
| msg = "停止空调工作";
| break;
| case 0x34:
| msg = "启动空调值班";
| break;
| case 0x36:
| msg = "停止空调值班";
| break;
| case 0x38:
| msg = "启动空调消毒";
| break;
| case 0x3A:
| msg = "停止空调消毒";
| break;
| case 0x3C:
| msg = "启动空调排风机";
| break;
| case 0x3E:
| msg = "启动空调排风机";
| break;
| }
| try {
| const res = await controlAir(210000001, opCmd);
| loading.close();
| let rs = res.data;
| if(rs.code === 1 && rs.data) {
| ElMessage({
| showClose: true,
| message: msg+'成功',
| type: 'success',
| });
| }else {
| ElMessage({
| showClose: true,
| message: msg+'失败',
| type: 'error',
| });
| }
| }catch (error) {
| ElMessage({
| showClose: true,
| message: msg+'失败',
| type: 'error',
| });
| loading.close();
| console.log(error);
| }
|
| }
|
| return {
| isCanSet,
| airParam,
| getParam,
| setParam,
| startAir
| };
| }
| export default airControlModule;
|
|