update:仅在 MQTT 服务可用时显示设备在线状态列

This commit is contained in:
3030332422
2025-12-26 17:39:08 +08:00
parent 2a42d86db0
commit eab8b48c9c
@@ -35,7 +35,7 @@
<el-table-column :label="$t('device.bindTime')" prop="bindTime" align="center"></el-table-column> <el-table-column :label="$t('device.bindTime')" prop="bindTime" align="center"></el-table-column>
<el-table-column :label="$t('device.lastConversation')" prop="lastConversation" <el-table-column :label="$t('device.lastConversation')" prop="lastConversation"
align="center"></el-table-column> align="center"></el-table-column>
<el-table-column :label="$t('device.deviceStatus')" prop="deviceStatus" align="center"> <el-table-column v-if="mqttServiceAvailable" :label="$t('device.deviceStatus')" prop="deviceStatus" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag v-if="scope.row.deviceStatus === 'online'" type="success">{{ $t('device.online') }}</el-tag> <el-tag v-if="scope.row.deviceStatus === 'online'" type="success">{{ $t('device.online') }}</el-tag>
<el-tag v-else type="danger">{{ $t('device.offline') }}</el-tag> <el-tag v-else type="danger">{{ $t('device.offline') }}</el-tag>
@@ -147,6 +147,7 @@ export default {
loading: false, loading: false,
userApi: null, userApi: null,
firmwareTypes: [], firmwareTypes: [],
mqttServiceAvailable: false, // MQTT服务是否可用
}; };
}, },
computed: { computed: {
@@ -392,12 +393,21 @@ export default {
// 直接使用解析后的数据作为设备状态映射(不需要devices字段包装) // 直接使用解析后的数据作为设备状态映射(不需要devices字段包装)
if (statusData && typeof statusData === 'object') { if (statusData && typeof statusData === 'object') {
// 成功获取到设备状态
this.mqttServiceAvailable = true;
// 更新设备状态 // 更新设备状态
this.updateDeviceStatusFromResponse(statusData); this.updateDeviceStatusFromResponse(statusData);
} else {
// 数据格式不正确,MQTT服务不可用
this.mqttServiceAvailable = false;
} }
} catch (error) { } catch (error) {
// JSON解析失败,忽略状态更新 // JSON解析失败,MQTT服务不可用
this.mqttServiceAvailable = false;
} }
} else {
// 接口调用失败,MQTT服务不可用
this.mqttServiceAvailable = false;
} }
}); });
}, },