肖洋
2024-12-21 7c926c1e3ade5158e6b1b0b805cd1b9c142e4b6c
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
<template>
  <div>
    <div>
      <div class="Stackerbox">
        <div class="card">
          <div class="card-header">
            <div>
              <div class="card-body Stacker">
                {{ StackerOne.deviceName }}
              </div>
            </div>
          </div>
          <div class="card-body">
            <ul class="list-group">
              <li class="list-group-item list-group-item-secondary">
                任务号:{{ StackerOne.data.currentTaskNum || '暂无任务号' }}
              </li>
              <li :class="getStatusClass(StackerOne.data.stackerCraneAutoStatusDes)">
                工作模式:{{ StackerOne.data.stackerCraneAutoStatusDes }}
              </li>
              <li :class="getStatusClass(StackerOne.data.stackerCraneStatusDes)">
                设备状态:{{ StackerOne.data.stackerCraneStatusDes }}
              </li>
              <li :class="getStatusClass(StackerOne.data.stackerCraneWorkStatusDes)">
                工作状态:{{ StackerOne.data.stackerCraneWorkStatusDes }}
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <device-line v-for="device in devices" :key="device.deviceName" :device="device" />
  </div>
</template>
 
<script setup>
import { onMounted, reactive, toRefs } from "vue";
import eventBus from "@/uitils/eventBus";
import DeviceLine from "@/components/DeviceLine.vue";
 
// 堆垛机
const StackerOne = reactive({
  deviceName: "",
  data: {
  }
});
 
// 设备列表(修改重复设备名称)
const devices = reactive([
  { deviceName: "陈化出库输送线", data: { command: {}, commandWrite: {}, writeInteractiveSignal: [] } },
  { deviceName: "陈化入库输送线", data: { command: {}, commandWrite: {}, writeInteractiveSignal: [] } },
  // { deviceName: "堆垛机1", data: { command: {}, commandWrite: {}, writeInteractiveSignal: [] } },
  // Add all devices similarly...
]);
 
// 获取状态类名(优化状态判断)
const getStatusClass = (status) => {
  if (status === '正常' || status === '自动' || status === '待机') {
    return 'list-group-item list-group-item-success';
  }
  if (status === '故障' || status === '停机') {
    return 'list-group-item list-group-item-danger';
  }
  return 'list-group-item list-group-item-warning'; // 默认警告状态
};
 
// 监听设备数据变化
onMounted(() => {
  eventBus.on('locationData', eventData => {
    const device = devices.find(d => d.deviceName === eventData.deviceName);
    if (device) {
      // 使用扩展运算符更新对象属性,保持响应性
      device.data = { ...device.data, ...eventData.data };
    }
  });
});
</script>
<style scoped>
.Stackerbox {
  width: 220px;
  float: left;
}
 
.Linebox {
  width: 500px;
  float: left;
}
 
.box1 {
  float: left;
}
 
.card-body {
  text-align: center;
  border-radius: 6%;
}
 
.Stacker {
  background-color: burlywood;
}
 
.lis {
  float: left;
  width: 233px;
}
</style>