| <template> | 
|   <el-row> | 
|     <el-col :span="24"> | 
|       <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"; | 
|   | 
| // 设备列表(修改重复设备名称) | 
| const devices = reactive([]); | 
|   | 
| 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 => { | 
|     if (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 }); | 
|         } | 
|       } | 
|     } | 
|   }); | 
| }); | 
| </script> |