From 2925fce7fbd64ab4dcab0aeea7cfefa2693380be Mon Sep 17 00:00:00 2001 From: fhysy <1149505133@qq.com> Date: Thu, 11 Sep 2025 15:08:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增设备日志查询 API - 实现事件、功能、上下线日志查询 - 优化属性日志查询接口 - 修复事件和功能模拟相关问题 --- apps/web-antd/src/api/device/device/index.ts | 40 +++ .../detail/components/LogManagement.vue | 147 +++++----- .../detail/components/RunningStatus.vue | 48 +++- .../detail/components/running/EventsPanel.vue | 128 +++++---- .../components/running/FunctionPanel.vue | 241 +++++++++++++++++ .../components/running/OnlineStatusPanel.vue | 204 ++++++++++++++ .../components/running/PropertyPanel.vue | 202 ++++++++++++++ .../components/running/RealtimePanel.vue | 93 +++++-- .../components/simulation/EventSimulation.vue | 35 ++- .../simulation/FunctionSimulation.vue | 58 ++-- .../simulation/OnlineOfflineSimulation.vue | 2 +- .../simulation/PropertySimulation.vue | 253 +++++++++++++----- .../views/device/productCategory/index.vue | 1 + 13 files changed, 1194 insertions(+), 258 deletions(-) create mode 100644 apps/web-antd/src/views/device/device/detail/components/running/FunctionPanel.vue create mode 100644 apps/web-antd/src/views/device/device/detail/components/running/OnlineStatusPanel.vue create mode 100644 apps/web-antd/src/views/device/device/detail/components/running/PropertyPanel.vue diff --git a/apps/web-antd/src/api/device/device/index.ts b/apps/web-antd/src/api/device/device/index.ts index 1f3df1b..9ae5529 100644 --- a/apps/web-antd/src/api/device/device/index.ts +++ b/apps/web-antd/src/api/device/device/index.ts @@ -34,6 +34,46 @@ export function deviceInfo(id: ID) { return requestClient.get(`/device/device/${id}`); } +/** + * 查询设备日志数据(属性/事件) + * @param params + * @returns 设备日志数据 + */ +export function deviceLogList(params?: DeviceQuery) { + return requestClient.post('/device/device/data/field', params); +} + +/** + * 查询设备功能操作日志列表 + * @param params + * @returns 设备功能操作日志 + */ +export function functionLogList(params?: DeviceQuery) { + return requestClient.get('/device/functionLog/list', { + params, + }); +} + +/** + * 查询设备上下线日志列表 + * @param params + * @returns 设备上下线日志 + */ +export function onlineLogList(params?: DeviceQuery) { + return requestClient.get('/device/onlineLog/list', { + params, + }); +} + +/** + * 查询设备日志数据(上报/下发) + * @param params + * @returns 设备日志数据 + */ +export function deviceUpDownLogList(params?: DeviceQuery) { + return requestClient.post('/device/device/log', params); +} + /** * 新增设备 * @param data diff --git a/apps/web-antd/src/views/device/device/detail/components/LogManagement.vue b/apps/web-antd/src/views/device/device/detail/components/LogManagement.vue index 8754b40..8261982 100644 --- a/apps/web-antd/src/views/device/device/detail/components/LogManagement.vue +++ b/apps/web-antd/src/views/device/device/detail/components/LogManagement.vue @@ -4,14 +4,15 @@ import { onMounted, ref } from 'vue'; import { Button, DatePicker, - Empty, Modal, Select, Space, Table, Tag, } from 'ant-design-vue'; -import { Dayjs } from 'dayjs'; +import dayjs, { Dayjs } from 'dayjs'; + +import { deviceUpDownLogList } from '#/api/device/device'; interface Props { deviceId: string; @@ -32,15 +33,15 @@ const pagination = ref({ current: 1, pageSize: 10, total: 0 }); // 日志类型选项 const logTypeOptions = [ { label: '全部', value: '' }, - { label: '上报', value: 'upload' }, - { label: '下发', value: 'download' }, + { label: '上报', value: 'up' }, + { label: '下发', value: 'down' }, ]; // 表格列 const columns = [ + { title: '时间', dataIndex: 'timestamp', key: 'timestamp', width: 200 }, { title: '类型', dataIndex: 'logType', key: 'logType', width: 120 }, { title: '名称内容', dataIndex: 'content', key: 'content', ellipsis: true }, - { title: '时间', dataIndex: 'timestamp', key: 'timestamp', width: 200 }, { title: '操作', key: 'action', width: 100 }, ]; @@ -49,7 +50,13 @@ const viewVisible = ref(false); const viewRecord = ref(null); const openView = (record: any) => { - viewRecord.value = record; + let content = ''; + try { + content = JSON.stringify(JSON.parse(record.content), null, 2); + } catch { + content = record.content; + } + viewRecord.value = content; viewVisible.value = true; }; @@ -62,53 +69,52 @@ const closeView = () => { const loadList = async () => { try { loading.value = true; - const [start, end] = timeRange.value || []; + let startTime = null; + let endTime = null; + if (timeRange.value?.length === 2) { + startTime = timeRange.value[0].valueOf(); + endTime = timeRange.value[1].valueOf(); + } const params = { - deviceId: props.deviceId, - startTime: start?.format('YYYY-MM-DD HH:mm:ss'), - endTime: end?.format('YYYY-MM-DD HH:mm:ss'), - logType: logType.value || undefined, - pageNo: pagination.value.current, - pageSize: pagination.value.pageSize, + deviceKey: props.deviceInfo.deviceKey, + productKey: props.deviceInfo.productObj.productKey, + // direction: logType.value, + orderType: 2, + current: pagination.value.current, + size: pagination.value.pageSize, + listWhere: [], }; + if (startTime && endTime) { + params.startTime = startTime; + params.endTime = endTime; + } + if (logType.value) { + params.listWhere.push({ + field: 'direction', + val: logType.value, + operator: 'eq', + valType: 'string', + }); + } + // if (messageId.value) { + // params.listWhere.push({ + // field: 'msg_id', + // val: messageId.value?.trim(), + // operator: 'eq', + // valType: 'string', + // }); + // } console.log('query logs with', params); - - // TODO: 替换为真实接口 - const mock = [ - { - id: 1, - timestamp: '2025-01-20 10:30:15', - logType: '上报', - content: '设备启动成功,固件版本:v1.0.0', - }, - { - id: 2, - timestamp: '2025-01-20 10:30:20', - logType: '下发', - content: '{"switch": "on"}', - }, - { - id: 3, - timestamp: '2025-01-20 10:30:25', - logType: '上报', - content: '网络连接不稳定,重试次数:3', - }, - { - id: 4, - timestamp: '2025-01-20 10:30:30', - logType: '下发', - content: - '功能执行失败,错误码:E001,错误信息:参数无效功能执行失败,错误码:E001,错误信息:参数无效功能执行失败,错误码:E001,错误信息:参数无效功能执行失败,错误码:E001,错误信息:参数无效', - }, - { - id: 5, - timestamp: '2025-01-20 10:30:35', - logType: '上报', - content: '调试信息:设备响应时间 150ms', - }, - ]; - dataSource.value = mock; - pagination.value.total = mock.length; + const data = await deviceUpDownLogList(params); + dataSource.value = data?.records.map((item: any) => { + return { + messageId: item.msg_id, + logType: item.direction, + timestamp: dayjs(item.time).format('YYYY-MM-DD HH:mm:ss'), + content: item.log_data, + }; + }); + pagination.value.total = data.total; } finally { loading.value = false; } @@ -141,7 +147,7 @@ onMounted(() => {
- + 日志类型: {
精简模式下属性只支持输入框的方式录入 + + 请选择要读取的属性 +
高级模式下支持JSON格式直接编辑 + + 填写读取属性id,使用逗号分开 +
@@ -530,9 +605,10 @@ onMounted(() => {
-
+
{
+ + +
- +