|  |  |  | 
|---|
|  |  |  | <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> | 
|---|
|  |  |  | <el-row> | 
|---|
|  |  |  | <el-col :span="3"> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <device-stacker v-for="stacker in Stackers" :key="stacker.deviceName" :Stacker="stacker"></device-stacker> | 
|---|
|  |  |  | </el-col> | 
|---|
|  |  |  | <el-col :span="21"> | 
|---|
|  |  |  | <device-line v-for="device in devices" :key="device.deviceName" :device="device" /> | 
|---|
|  |  |  | </el-col> | 
|---|
|  |  |  | </el-row> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <script setup> | 
|---|
|  |  |  | import { onMounted, reactive, toRefs } from "vue"; | 
|---|
|  |  |  | import eventBus from "@/uitils/eventBus"; | 
|---|
|  |  |  | import DeviceLine from "@/components/DeviceLine.vue"; | 
|---|
|  |  |  | import DeviceStacker from "@/components/DeviceStacker.vue"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 堆垛机 | 
|---|
|  |  |  | const StackerOne = reactive({ | 
|---|
|  |  |  | deviceName: "", | 
|---|
|  |  |  | data: { | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | const Stackers = reactive([]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 设备列表(修改重复设备名称) | 
|---|
|  |  |  | const devices = reactive([ | 
|---|
|  |  |  | { deviceName: "陈化出库输送线", data: { command: {}, commandWrite: {}, writeInteractiveSignal: [] } }, | 
|---|
|  |  |  | { deviceName: "陈化入库输送线", data: { command: {}, commandWrite: {}, writeInteractiveSignal: [] } }, | 
|---|
|  |  |  | // { deviceName: "堆垛机1", data: { command: {}, commandWrite: {}, writeInteractiveSignal: [] } }, | 
|---|
|  |  |  | // Add all devices similarly... | 
|---|
|  |  |  | ]); | 
|---|
|  |  |  | const devices = reactive([]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取状态类名(优化状态判断) | 
|---|
|  |  |  | 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'; // 默认警告状态 | 
|---|
|  |  |  | const intToBitArrayFromBinaryString = (num, numBits) => { | 
|---|
|  |  |  | let binaryString = num.toString(2).padStart(numBits, '0'); | 
|---|
|  |  |  | return Array.from({ length: numBits }, (_, index) => binaryString[index] === '1'); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 监听设备数据变化 | 
|---|
|  |  |  | onMounted(() => { | 
|---|
|  |  |  | eventBus.on('locationData', eventData => { | 
|---|
|  |  |  | const device = devices.find(d => d.deviceName === eventData.deviceName); | 
|---|
|  |  |  | if (device) { | 
|---|
|  |  |  | // 使用扩展运算符更新对象属性,保持响应性 | 
|---|
|  |  |  | device.data = { ...device.data, ...eventData.data }; | 
|---|
|  |  |  | console.log(eventData) | 
|---|
|  |  |  | if (eventData.deviceName === "陈化入库输送线" || eventData.deviceName === "陈化入库输送线") { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (devices.length <= 0) { | 
|---|
|  |  |  | devices.push({ deviceName: eventData.deviceName, data: eventData.data, childDeviceCode: eventData.childDeviceCode }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else { | 
|---|
|  |  |  | const device = devices.find(c => c.childDeviceCode == eventData.childDeviceCode) | 
|---|
|  |  |  | if (device) { | 
|---|
|  |  |  | const number = eventData.data.commandWrite.writeInteractiveSignal; | 
|---|
|  |  |  | const writeInteractiveSignal = intToBitArrayFromBinaryString(number, 8) | 
|---|
|  |  |  | eventData.data.writeInteractiveSignal = writeInteractiveSignal; | 
|---|
|  |  |  | device.data = eventData.data | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else { | 
|---|
|  |  |  | const number = eventData.data.commandWrite.writeInteractiveSignal; | 
|---|
|  |  |  | const writeInteractiveSignal = intToBitArrayFromBinaryString(number, 8) | 
|---|
|  |  |  | eventData.data.writeInteractiveSignal = writeInteractiveSignal; | 
|---|
|  |  |  | devices.push({ deviceName: eventData.deviceName, data: eventData.data, childDeviceCode: eventData.childDeviceCode }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | eventBus.on('stackerData', eventData => { | 
|---|
|  |  |  | if (eventData.deviceName.indexOf("陈化") != -1) { | 
|---|
|  |  |  | if (Stackers.length == 0) { | 
|---|
|  |  |  | Stackers.push({ deviceName: eventData.deviceName, data: eventData.data }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else { | 
|---|
|  |  |  | const Stacker = Stackers.find(c => c.deviceName == eventData.deviceName); | 
|---|
|  |  |  | if (Stacker) { | 
|---|
|  |  |  | Stacker.data = eventData.data | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else { | 
|---|
|  |  |  | Stackers.push({ deviceName: eventData.deviceName, data: eventData.data }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | </script> | 
|---|
|  |  |  | <style scoped> | 
|---|