| | |
| | | </div> |
| | | <div class="device-status"> |
| | | <span class="status-dot" :class="getStatusClass(device.status)"></span> |
| | | <span :class="getStatusTextClass(device.status)">{{ device.status || '未知' }}</span> |
| | | <span :class="getStatusTextClass(device.status)">{{ getStatusLabel(device.status) }}</span> |
| | | </div> |
| | | </div> |
| | | </template> |
| | |
| | | </el-row> |
| | | </div> |
| | | <div v-else class="device-offline"> |
| | | <el-alert :title="device.statusMessage || '设备离线'" type="warning" :closable="false" show-icon /> |
| | | <el-alert :title="device.statusMessage || (device.status === 'error' ? '设备异常' : '设备离线')" :type="device.status === 'error' ? 'error' : 'warning'" :closable="false" show-icon /> |
| | | </div> |
| | | </el-card> |
| | | </div> |
| | |
| | | |
| | | <script setup> |
| | | import { ref, computed, onMounted, onUnmounted, watch } from "vue"; |
| | | import { getIotRealtimeData } from "@/api/inventoryManagement/stockInventory.js"; |
| | | import { batchGetIotRealtimeData } from "@/api/inventoryManagement/stockInventory.js"; |
| | | import { Refresh, Sunny, Drizzling, WindPower, Sunrise, Lightning } from "@element-plus/icons-vue"; |
| | | |
| | | const props = defineProps({ |
| | |
| | | } |
| | | }; |
| | | |
| | | const getStatusLabel = (status) => { |
| | | switch (status) { |
| | | case "在线": |
| | | return "在线"; |
| | | case "offline": |
| | | return "离线"; |
| | | case "error": |
| | | return "异常"; |
| | | default: |
| | | return "离线"; |
| | | } |
| | | }; |
| | | |
| | | const fetchData = async () => { |
| | | if (!props.record.id) return; |
| | | const deviceIdsStr = props.record?.warehouse; |
| | | console.log("fetchData called, warehouse:", deviceIdsStr); |
| | | if (!deviceIdsStr) { |
| | | console.warn("warehouse is empty, skip fetch"); |
| | | deviceData.value = { inventoryId: null, iotDeviceIds: "", devices: [] }; |
| | | return; |
| | | } |
| | | loading.value = true; |
| | | try { |
| | | const res = await getIotRealtimeData(props.record.id); |
| | | const deviceIds = deviceIdsStr.split(",").map(id => id.trim()).filter(id => id); |
| | | const res = await batchGetIotRealtimeData(deviceIds); |
| | | |
| | | if (res.code === 200 && res.data) { |
| | | deviceData.value = res.data; |
| | | } else { |
| | | deviceData.value = { inventoryId: null, iotDeviceIds: deviceIdsStr, devices: [] }; |
| | | } |
| | | } catch (error) { |
| | | console.error("获取物联设备数据失败:", error); |
| | |
| | | isShow.value = false; |
| | | }; |
| | | |
| | | // 监听弹窗显示状态,每次打开时获取数据 |
| | | watch(() => props.visible, (val) => { |
| | | console.log("visible changed:", val, "record:", props.record); |
| | | if (val) { |
| | | fetchData(); |
| | | } else { |
| | | // 关闭时停止自动刷新 |
| | | autoRefresh.value = false; |
| | | } |
| | | }, { immediate: true }); |
| | | |
| | | // 自动刷新 |
| | | watch(autoRefresh, (val) => { |
| | | if (val) { |
| | |
| | | refreshTimer = null; |
| | | } |
| | | } |
| | | }); |
| | | |
| | | onMounted(() => { |
| | | fetchData(); |
| | | }); |
| | | |
| | | onUnmounted(() => { |