From 44e7380c6bf52c824a518eb4c23383d12ff1801a Mon Sep 17 00:00:00 2001
From: 3030332422 <3030332422@qq.com>
Date: Wed, 17 Sep 2025 11:36:20 +0800
Subject: [PATCH] =?UTF-8?q?update:=20=E6=B7=BB=E5=8A=A0=E8=AE=BE=E5=A4=87?=
=?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=E5=AE=9E=E6=97=B6=E5=9C=A8?=
=?UTF-8?q?=E7=BA=BF=E7=8A=B6=E6=80=81=E6=98=BE=E7=A4=BA=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
main/manager-web/src/apis/module/device.js | 17 +++++
main/manager-web/src/i18n/en.js | 3 +
main/manager-web/src/i18n/zh_CN.js | 3 +
main/manager-web/src/i18n/zh_TW.js | 3 +
.../src/views/DeviceManagement.vue | 64 ++++++++++++++++++-
5 files changed, 89 insertions(+), 1 deletion(-)
diff --git a/main/manager-web/src/apis/module/device.js b/main/manager-web/src/apis/module/device.js
index 233c764b..bd1697b7 100644
--- a/main/manager-web/src/apis/module/device.js
+++ b/main/manager-web/src/apis/module/device.js
@@ -85,4 +85,21 @@ export default {
});
}).send();
},
+ // 获取设备状态
+ getDeviceStatus(agentId, callback) {
+ RequestService.sendRequest()
+ .url(`${getServiceUrl()}/device/bind/${agentId}`)
+ .method('POST')
+ .data({}) // 发送空对象作为请求体
+ .success((res) => {
+ RequestService.clearRequestTime();
+ callback(res);
+ })
+ .networkFail((err) => {
+ console.error('获取设备状态失败:', err);
+ RequestService.reAjaxFun(() => {
+ this.getDeviceStatus(agentId, callback);
+ });
+ }).send();
+ },
}
\ No newline at end of file
diff --git a/main/manager-web/src/i18n/en.js b/main/manager-web/src/i18n/en.js
index 1e560dc3..b5d7b856 100644
--- a/main/manager-web/src/i18n/en.js
+++ b/main/manager-web/src/i18n/en.js
@@ -326,6 +326,9 @@ export default {
'device.autoUpdateDisabled': 'Auto update disabled',
'device.batchUnbindSuccess': 'Successfully unbound {count} devices',
'device.getFirmwareTypeFailed': 'Failed to fetch firmware type',
+ 'device.deviceStatus': 'Status',
+ 'device.online': 'Online',
+ 'device.offline': 'Offline',
// Message tips
'message.success': 'Operation Successful',
diff --git a/main/manager-web/src/i18n/zh_CN.js b/main/manager-web/src/i18n/zh_CN.js
index c8c267f4..323e936e 100644
--- a/main/manager-web/src/i18n/zh_CN.js
+++ b/main/manager-web/src/i18n/zh_CN.js
@@ -327,6 +327,9 @@ export default {
'device.autoUpdateDisabled': '已关闭自动升级',
'device.batchUnbindSuccess': '成功解绑 {count} 台设备',
'device.getFirmwareTypeFailed': '获取固件类型失败',
+ 'device.deviceStatus': '状态',
+ 'device.online': '在线',
+ 'device.offline': '离线',
// 消息提示
'message.success': '操作成功',
diff --git a/main/manager-web/src/i18n/zh_TW.js b/main/manager-web/src/i18n/zh_TW.js
index 8f2c51a7..3f921279 100644
--- a/main/manager-web/src/i18n/zh_TW.js
+++ b/main/manager-web/src/i18n/zh_TW.js
@@ -326,6 +326,9 @@ export default {
'device.autoUpdateDisabled': '已關閉自動升級',
'device.batchUnbindSuccess': '成功解綁 {count} 台設備',
'device.getFirmwareTypeFailed': '獲取固件類型失敗',
+ 'device.deviceStatus': '狀態',
+ 'device.online': '在線',
+ 'device.offline': '離線',
// 消息提示
'message.success': '操作成功',
diff --git a/main/manager-web/src/views/DeviceManagement.vue b/main/manager-web/src/views/DeviceManagement.vue
index c504e5ca..c44b40b3 100644
--- a/main/manager-web/src/views/DeviceManagement.vue
+++ b/main/manager-web/src/views/DeviceManagement.vue
@@ -35,6 +35,12 @@
+
+
+ {{ $t('device.online') }}
+ {{ $t('device.offline') }}
+
+
a.rawBindTime - b.rawBindTime);
this.activeSearchKeyword = "";
this.searchKeyword = "";
+
+ // 获取设备列表后,立即获取设备状态
+ this.fetchDeviceStatus(agentId);
} else {
this.$message.error(data.msg || this.$t('device.getListFailed'));
}
});
},
+
+ // 获取设备状态
+ fetchDeviceStatus(agentId) {
+ Api.device.getDeviceStatus(agentId, ({ data }) => {
+ if (data.code === 0) {
+ try {
+ // 解析后端返回的设备状态JSON
+ const statusData = JSON.parse(data.data);
+
+ // 直接使用解析后的数据作为设备状态映射(不需要devices字段包装)
+ if (statusData && typeof statusData === 'object') {
+ // 更新设备状态
+ this.updateDeviceStatusFromResponse(statusData);
+ }
+ } catch (error) {
+ // JSON解析失败,忽略状态更新
+ }
+ }
+ });
+ },
+
+ // 根据API响应更新设备状态
+ updateDeviceStatusFromResponse(deviceStatusMap) {
+ this.deviceList.forEach(device => {
+ // 构建设备的MQTT客户端ID
+ const macAddress = device.macAddress ? device.macAddress.replace(/:/g, '_') : 'unknown';
+ const groupId = device.model ? device.model.replace(/:/g, '_') : 'GID_default';
+ const mqttClientId = `${groupId}@@@${macAddress}@@@${macAddress}`;
+
+ // 从状态映射中获取设备状态
+ if (deviceStatusMap[mqttClientId]) {
+ const statusInfo = deviceStatusMap[mqttClientId];
+
+ let isOnline = false;
+ if (statusInfo.isAlive === true) {
+ isOnline = true;
+ } else if (statusInfo.isAlive === false) {
+ isOnline = false;
+ } else if (statusInfo.isAlive === null && statusInfo.exists === true) {
+ isOnline = true;
+ } else {
+ isOnline = false;
+ }
+
+ device.deviceStatus = isOnline ? 'online' : 'offline';
+ } else {
+ // 如果没有找到对应的状态信息,默认为离线
+ device.deviceStatus = 'offline';
+ }
+ });
+ },
headerCellClassName({ columnIndex }) {
if (columnIndex === 0) {
return "custom-selection-header";