干燥机配套车间生产管理系统/云平台前端
bsw215583320
2024-04-16 852e0f0918dc58b616cc81702efbfde3940866bb
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<template>
  <a-modal v-model:visible="visible" centered :mask="true" :maskClosable="false" :keyboard="false" :closable="false" :cancelText="null" title="警告"
           @ok="hideModal" @cancel="cnacelModal" >
    <a-card>
       <div class="indented-text">在使用远程控制设备前,请确保机器周围没有其他人员。建立一个安全区域,确保没有人能够进入该区域,防止不必要的伤害。</div>
      <div style="display: flex; justify-content: space-between; padding-top: 20px; "> 
        <p style="font-weight: bold;" >请输入密码:</p>
        <p style="color: red">{{ error }}</p>
      </div>
       <div >
        <a-input-password v-model:value="password" placeholder="请输入密码!"></a-input-password>
       </div>
    </a-card>
 
  </a-modal>
  <div class="app">
    <a-row>
      <div style="width: 60%">
      <a-card title="照明" >
      <div class="light-box">
        <div v-for="item in lightList" :key="item.identifier"  class="center">
          <!-- <a-button v-if="item.type == 0"  type="primary" class="com-btn"
                  @click="deviceClick(item)">
          {{ item.name }}
        </a-button> -->
          <div v-if="item.type==0" @click="deviceClick(item)">
            <div   :class="[ item.value?'lightOn':'lightOff' ,'device']">
 
              
            </div>
            <div class="text-center">{{ item.name }}</div>
              
            </div>
        </div>
       
      </div>
    </a-card>
  </div>
  <div style="width: 40%">
    <a-card title="监控" style=" margin-left: 10px;">
      <div class="monitor-box">
        <div v-for="item in lightList" :key="item.identifier" class="center" >
          <div v-if="item.type==1" @click="deviceClick(item)">
            <div   :class="[ item.value?'camOn':'camOff' ,'device']">
 
              
            </div>
            <div class="text-center">{{ item.name }}</div>
            </div>
      </div>
      </div>
    </a-card>
</div>
    </a-row>
 <a-row>
      <div style="width: 50%">
<a-card title="指令" style="margin-top: 10px; ">
      <div class="com-box">
        <!-- <a-button v-for="item in comList" :key="item.id" type="primary" class="com-btn"
                  @click="comClick(item)">
          {{ item.title }}
        </a-button> -->
        <div style="width: 500px;"  >
        
        <a-row class="button-row">
          <a-button type="primary" :disabled="btnDisabled"  @click="clickButton(1010, '干燥启动')" class="com-btn">  
            <div> <PlayCircleOutlined style="font-size: 20px;" /> </div>
          <div>  干燥启动 </div>
          
        </a-button>
        <!-- <a-button type="normal" @click="clickButton(1012)" class="com-btn">
          <div> <SplitCellsOutlined style="font-size: 20px;" /> </div>
          <div>  后门开关 </div>
          
        </a-button> -->
        <a-button type="default" :disabled="btnDisabled"  @click="clickButton(1003,'滚筒升')" class="com-btn w300">
          <div> <UpCircleOutlined style="font-size: 20px;" /> </div>
          <div>  滚筒升 </div>
          
        </a-button>
        <a-button type="normal" :disabled="btnDisabled" @click="clickButton(1016,'清除')" class="com-btn">
          <div> <ClearOutlined style="font-size: 20px;" /> </div>
          <div>  清除 </div>
          
        </a-button>
        </a-row>
        <a-row class="button-row">
          <a-button type="normal" :disabled="btnDisabled"  @click="clickButton(1005,'滚筒正转')" class="com-btn h100">
            <div>  <RedoOutlined style="font-size: 20px;" /> </div>
            <div> 滚筒正转 </div>
        </a-button>
          <a-button type="danger" :disabled="btnDisabled"  @click="clickButton(1007,'停止')" class="com-btn h100 w300 " >
            <div> <PauseCircleOutlined style="font-size: 20px;" />  </div>
            <div>  停止 </div>
        </a-button>
        <a-button type="normal" :disabled="btnDisabled"  @click="clickButton(1006,'滚筒反转')" class="com-btn h100">
          <div> <UndoOutlined style="font-size: 20px;" /> </div>
          <div>  滚筒反转 </div>
        </a-button>
        </a-row>
        <a-row class="button-row">
          <a-button type="success" :disabled="btnDisabled"  @click="clickButton(1015,'出料')" class="com-btn">
            <div> <DownloadOutlined style="font-size: 20px;" /> </div>
            <div>  出料 </div>
          
        </a-button>
        <!-- <a-button type="normal" @click="clickButton(1010)" class="com-btn">
          <div> <SplitCellsOutlined style="font-size: 20px;" /> </div>
          <div>  前门开关 </div>
        </a-button> -->
        <a-button type="normal" :disabled="btnDisabled"  @click="clickButton(1004,'滚筒降')" class="com-btn w300">
          <div> <DownCircleOutlined style="font-size: 20px;" /> </div>
          <div>  滚筒降 </div>
        </a-button>
        <a-button type="normal" :disabled="btnDisabled"  @click="clickButton(1013,'热风启动')" class="com-btn">
          <div> <FireOutlined style="font-size: 20px;" /> </div>
            <div>  热风启动 </div>
          
        </a-button>
      </a-row>
       
        </div>
 
 
      </div>
    </a-card>
    </div>
    <div style="width: 50%">
    <a-card title="状态" style="margin-left: 10px;margin-top:10px">
      <div class="com-box">
        <div>
      <div>
          <a-button type="warning" :disabled="btnDisabled"  @click="clickButton(1017,'手动/自动')" class="com-btn">
            <div> <SyncOutlined style="font-size: 20px;" /> </div>
          <div>  手动/自动 </div>
          
        </a-button>
       
      </div>
      <div>
        <a-button type="info" :disabled="btnDisabled"  @click="clickButton(1014, '开门观察')" class="com-btn">
          <div> <SettingOutlined style="font-size: 20px;" /> </div>
          <div>  开门观察 </div>
          
        </a-button>
       
      </div>
      <div>
        <a-button type="normal" @click="lock()" class="com-btn">
          <div> <Icon :icon="lockIcon" :size="28" /> </div>
          <div>  {{lockText}} </div>
          
        </a-button>
      </div>
      </div>
    </div>
    </a-card>
  </div>
    </a-row>
    
    <a-card title="控制台" style="margin-top: 10px; ">
      <div class="log-box">
        <p v-for="log in logList" :key="log"> {{ log }}</p>
      </div>
 
    </a-card>
  </div>
</template>
 
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { sendCommand, sendWriteCommand, listAll } from "./api";
import { useGlobSetting } from '/@/hooks/setting';
import { connectWebSocket, onWebSocket } from '/@/hooks/web/useWebSocket';
import { useUserStore } from '/@/store/modules/user';
import { RedoOutlined ,SettingOutlined, UndoOutlined,FireOutlined, SplitCellsOutlined, DownloadOutlined, PauseCircleOutlined,ClearOutlined, SyncOutlined,PlayCircleOutlined, SwapOutlined , UpCircleOutlined, DownCircleOutlined, LeftCircleOutlined, RightCircleOutlined} from '@ant-design/icons-vue';
import { router } from '/@/router'
const error = ref('')
const lockIcon = ref('tdesign:lock-off')
const lockText = ref('解锁')
const password = ref()
const visible = ref<boolean>(false);
  const glob = useGlobSetting();
interface Commant {
  id: number;
  title: string;
  icon: string;
}
 
interface Device {
  name: string;
  identifier: string;
  value: boolean;
  sort_order: number;
}
const userStore = useUserStore();
const logList = ref<string[]>([]);
const comList = ref<Commant[]>([
  {
    id: 1010,
    title: "干燥启动",
    icon: "caret-right-outlined"
  }, {
    id: 1007,
    title: "停止运行",
    icon: "caret-right-outlined"
  }, {
    id: 1013,
    title: "热风启动",
    icon: "caret-right-outlined"
  }, {
    id: 1012,
    title: "后门开关",
    icon: "caret-right-outlined"
  }, {
    id: 1003,
    title: "滚筒升",
    icon: "caret-right-outlined"
  }, {
    id: 1004,
    title: "滚筒降",
    icon: "caret-right-outlined"
  }, {
    id: 1005,
    title: "滚筒正转",
    icon: "caret-right-outlined"
  }, {
    id: 1006,
    title: "滚筒反转",
    icon: "caret-right-outlined"
  }, {
    id: 1014,
    title: "开门观察",
    icon: "caret-right-outlined"
  }, {
    id: 1015,
    title: "出料",
    icon: "caret-right-outlined"
  }, {
    id: 1016,
    title: "清除",
    icon: "caret-right-outlined"
  }, {
    id: 1017,
    title: "手动/自动",
    icon: "caret-right-outlined"
  }]);
 
const btnDisabled = ref(true)
const lightList = ref<Device[]>([]);
const monitorList = ref<Device[]>([]);
 
function lock() {
  btnDisabled.value = !btnDisabled.value
  lockIcon.value = btnDisabled.value?'tdesign:lock-off':'tdesign:lock-on'
  lockText.value = btnDisabled.value?'解锁': '锁定'
  if (btnDisabled.value) {
    showModal()
  }
}
 
function comClick(item) {
  addLog("发送", item.title);
  //发送指令
  sendCmd(item);
}
 
/**
 * 发送指令
 * @param item
 */
function sendCmd(item) {
  var params = { msg: item.title, code: item.id, tenantId: 1003, machineId: "GM001" };
  sendCommand(params).then(res => {
    if (res.success) {
      addLog("响应", res.message);
      console.info(res);
    } else {
      console.info(res);
      addLog("响应", res.message);
    }
 
  });
}
 
/**
 * 添加log
 * @param type
 * @param msg
 */
function addLog(type, msg) {
  //发送log
  const date = new Date();
  const format = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")} ${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}:${date.getSeconds().toString().padStart(2, "0")}`;
  const log = format + " " + type + ":" + msg;
  logList.value.unshift(log);
}
 
const showModal = () => {
  visible.value = true;
};
 
const cnacelModal = () => {
  router.back()
}
 
const hideModal = () => {
  if(!password.value || password.value.length<=0) {
    error.value="请输入密码!"
  }else
  if(password.value === 'LBit@123') {
    visible.value = false;
    password.value = ''
    error.value = ''
  } else {
    error.value = '密码错误!'
  }
  
  
};
 
/**
 * 查询灯和摄像头列表
 */
function queryDevice() {
  listAll({}).then(res => {
    console.log("ress000:",res);
    lightList.value = res
  })
 
 
}
 
function clickButton(cmd, msg) {
  console.log("target::::",cmd);
  let tenantId = userStore.getTenant;
  var params = { msg: msg, code: cmd, tenantId: tenantId, machineId: "GM001" };
  sendCommand(params).then(res => {
    if (res.success) {
      addLog("响应", res.message);
      console.info(res);
    } else {
      console.info(res);
      addLog("响应", res.message);
    }
 
  });
}
 
 
 
 
function deviceClick(item) {
  //console.log("item===",item.value);
  let params = {code: item.identifier, msg: !item.value}
  sendWriteCommand(params).then(res => {
    console.log("写指令结果::", res)
    if(res.success) {
      lightList.value.forEach(device => {
          if(device.identifier == item.identifier) {
            device.value = !item.value
          }
        })
    }
  }) 
 
}
 
    // 初始化 WebSocket
    function initWebSocket() {
 
        let user = userStore.getUserInfo;
        let tenantId = user.loginTenantId;
 
        console.log(user);
        // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
         let url = glob.domainUrl?.replace('https://', 'wss://').replace('http://', 'ws://') + '/drySocket/' + tenantId;
        
         connectWebSocket(url);
         onWebSocket(onWebSocketMessage);
      }
 
      function onWebSocketMessage(data) {
        console.log("drysocket:data::",data)
        lightList.value.forEach(item => {
          if(item.identifier == data.identifier) {
            item.value = data.value
          }
        })
      }
 
      function keydown(e) {
        error.value = ''
        if(e.keyCode == 13) {
          hideModal()
        }
      }
 
onMounted(() => {
  showModal();
  initWebSocket();
  window.addEventListener('keydown', keydown)
});
 
queryDevice()
 
 
</script>
 
<style lang="less" scoped>
.app {
  margin: 10px;
}
 
.com-box {
  // margin-left: 200px;
 
  display: flex;
  justify-content: center;
  
  .com-btn {
    border-radius: 5px;
    width: 100px;
    margin: 10px;
    height: 70px;
  }
}
 
.button-row {
  display: flex; justify-content: space-between;
}
 
.log-box {
  min-height: 150px;
  max-height: 150px;
  overflow-y: auto;
}
.indented-text {
  text-indent: 20px;
  font-size: 16px;
}
 
.light-box {
  display: flex;
  justify-items: center;
justify-content: center;
  flex-wrap: wrap;
 
}
.center {
  display: flex;
justify-items: center;
justify-content: center;
}
 
.text-center {
  text-align: center;
}
 
.lightOn {
    background-image: url(/src/assets/images/dry/control/light.png);
    background-repeat: no-repeat;
        background-size: 50px;
        /* border-radius: 10px; */
        background-position: 48px 0px;
  }
  .lightOff {
    background-image: url(/src/assets/images/dry/control/light-close.png);
    background-repeat: no-repeat;
        background-size: 50px;
        /* border-radius: 10px; */
        background-position: 48px 0px;
  }
 
  .camOn {
    background-image: url(/src/assets/images/dry/control/cam1.png);
    background-repeat: no-repeat;
        background-size: 50px;
        /* border-radius: 10px; */
        background-position: 48px 0px;
  }
  .camOff {
    background-image: url(/src/assets/images/dry/control/cam0.png);
    background-repeat: no-repeat;
        background-size: 50px;
        /* border-radius: 10px; */
        background-position: 48px 0px;
  }
 
 
.device {
  width: 150px; height: 60px; 
  
}
 
.h100 {
  height: 70px !important;
}
 
.w300 {
  width: 100px !important;
}
 
.monitor-box {
  display: flex;
  justify-items: center;
justify-content: center;
flex-wrap: wrap;
  
}
 
 
</style>