From a0c620404a5008b43a6c8e09fd0dcc9b8e5332f4 Mon Sep 17 00:00:00 2001 From: TongTongStudio Date: Sun, 9 Aug 2026 20:03:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(device):=20=E6=96=B0=E5=A2=9E=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=9C=A8=E7=BA=BF=E7=8A=B6=E6=80=81=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=B8=8E=E5=AE=9E=E6=97=B6=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增设备在线状态视图对象类型定义 - 新增设备在线状态批量查询接口与详情页查询接口 - 表格数据加载完成后批量查询并更新设备在线状态 - 详情页独立查询在线状态并展示状态指示点 - 通过 SSE 推送实时更新表格与详情页的设备在线状态 --- src/api/system/device/index.ts | 32 +++++++ src/api/system/device/types.ts | 22 +++++ src/components/DeviceSn/DevicePageContent.vue | 12 ++- src/components/DeviceSn/DeviceSnDetail.vue | 68 +++++++++++++- src/views/devices/sn/config/content.ts | 10 +- src/views/devices/sn/index.vue | 94 +++++++++++++++++++ 6 files changed, 234 insertions(+), 4 deletions(-) diff --git a/src/api/system/device/index.ts b/src/api/system/device/index.ts index ee1e7763..a3e77bd0 100644 --- a/src/api/system/device/index.ts +++ b/src/api/system/device/index.ts @@ -4,6 +4,7 @@ import type { DeviceForm, DeviceQueryParams, DeviceItem, + DeviceOnlineVO, DeviceProfileDetail, DeviceProfileForm, DevicePasswordChangeForm, @@ -456,6 +457,37 @@ const DeviceAPI = { }); }, + /** + * 批量查询设备在线状态 + * + * @param sns 设备序列号列表 + */ + /** + * 查询单个设备在线状态 + * + * @param sn 设备序列号 + */ + getOnlineStatus(sn: string) { + return request({ + url: `${DEVICE_BASE_URL}/online/status`, + method: "get", + params: { sn }, + }); + }, + + /** + * 批量查询设备在线状态 + * + * @param sns 设备序列号列表 + */ + getOnlineStatusBatch(sns: string[]) { + return request>({ + url: `${DEVICE_BASE_URL}/online/status/batch`, + method: "post", + data: sns, + }); + }, + /** * 上传应用图标(全局图标库) * diff --git a/src/api/system/device/types.ts b/src/api/system/device/types.ts index 227d704c..73a128df 100644 --- a/src/api/system/device/types.ts +++ b/src/api/system/device/types.ts @@ -58,6 +58,28 @@ export interface DeviceItem { status?: number; /** 用户名 */ Devicename?: string; + /** 设备序列号 */ + serialno?: string; + /** 在线状态(1:在线;0:离线) */ + online?: number; + /** 最后心跳时间 */ + lastHeartbeatTime?: string; + /** 推送ID */ + pushId?: string; +} + +/** 设备在线状态视图对象 */ +export interface DeviceOnlineVO { + /** 设备序列号 */ + serialno?: string; + /** 在线状态(1:在线;0:离线) */ + online?: number; + /** 最后心跳时间 */ + lastHeartbeatTime?: string; + /** 设备 IP */ + ip?: string; + /** 屏幕状态(1:亮屏;0:熄屏;null:未知) */ + screenState?: number; } /** 设备表单对象 */ diff --git a/src/components/DeviceSn/DevicePageContent.vue b/src/components/DeviceSn/DevicePageContent.vue index 3aafd8d1..6d7a29ed 100644 --- a/src/components/DeviceSn/DevicePageContent.vue +++ b/src/components/DeviceSn/DevicePageContent.vue @@ -388,6 +388,7 @@ const emit = defineEmits<{ editClick: [row: IObject]; filterChange: [data: IObject]; operateClick: [data: IOperateData]; + dataLoaded: []; }>(); // 表格工具栏按钮配置 @@ -929,6 +930,8 @@ function fetchPageData(formData: IObject = {}, isRestart = false) { } else { pageData.value = Array.isArray(data) ? data : (data?.list ?? (data as IObject)?.data ?? []); } + // 数据加载完成后通知父组件,供父组件做后处理(如批量查询设备在线状态) + emit("dataLoaded"); }) .finally(() => { loading.value = false; @@ -971,7 +974,14 @@ function saveXlsx(fileData: BlobPart, fileName: string) { } // 暴露的属性和方法 -defineExpose({ fetchPageData, exportPageData, getFilterParams, getSelectionData, handleRefresh }); +defineExpose({ + fetchPageData, + exportPageData, + getFilterParams, + getSelectionData, + handleRefresh, + pageData, +}); diff --git a/src/views/devices/sn/config/content.ts b/src/views/devices/sn/config/content.ts index 8e9be761..5956cd20 100644 --- a/src/views/devices/sn/config/content.ts +++ b/src/views/devices/sn/config/content.ts @@ -58,7 +58,15 @@ const contentConfig: IContentConfig = { prop: "serialno", templet: "custom", slotName: "serialno", - width: 150, + width: 220, + }, + { + label: "在线状态", + align: "center", + prop: "online", + templet: "custom", + slotName: "onlineStatus", + width: 100, }, { label: "设备型号", align: "center", prop: "snModel", width: 200 }, { label: "设备昵称", align: "center", prop: "snName", width: 200 }, diff --git a/src/views/devices/sn/index.vue b/src/views/devices/sn/index.vue index 56e345f2..c554cf6d 100644 --- a/src/views/devices/sn/index.vue +++ b/src/views/devices/sn/index.vue @@ -21,6 +21,7 @@ @toolbar-click="handleToolbarClick" @operate-click="handleOperateClick" @filter-change="handleFilterChange" + @data-loaded="fetchDeviceOnlineStatus" > + @@ -92,8 +102,11 @@ + +