From c9e00d97ebdd4f29623f803545d5e8c75568d935 Mon Sep 17 00:00:00 2001 From: alwayssuper <191763414@qq.com> Date: Mon, 6 Jan 2025 16:39:22 +0800 Subject: [PATCH] feat:deviceLog and deviceSimulator --- .vscode/settings.json | 2 +- src/api/iot/device/device/index.ts | 6 +- src/api/iot/thingmodel/index.ts | 7 + .../device/device/detail/DeviceDetailsLog.vue | 85 ++++---- .../device/detail/DeviceDetailsSimulator.vue | 183 +++++++++--------- src/views/iot/device/device/detail/index.vue | 2 +- 6 files changed, 143 insertions(+), 142 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f145f386..cc1dae50 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -87,7 +87,7 @@ "source.fixAll.stylelint": "explicit" }, "[vue]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "octref.vetur" }, "i18n-ally.localesPaths": ["src/locales"], "i18n-ally.keystyle": "nested", diff --git a/src/api/iot/device/device/index.ts b/src/api/iot/device/device/index.ts index 5377203b..b489a04f 100644 --- a/src/api/iot/device/device/index.ts +++ b/src/api/iot/device/device/index.ts @@ -69,7 +69,7 @@ export interface SimulatorDataVO { deviceKey: string type: string subType: string - reportTime: string + reportTime: number // 时间戳 content: string // 存储 JSON 字符串 } @@ -151,5 +151,9 @@ export const DeviceApi = { // 模拟设备 simulatorDevice: async (data: SimulatorDataVO) => { return await request.post({ url: `/iot/device/data/simulator`, data }) + }, + //查询设备日志分页 + getDeviceLogPage: async (params: any) => { + return await request.get({ url: `/iot/device/data/log/page`, params }) } } diff --git a/src/api/iot/thingmodel/index.ts b/src/api/iot/thingmodel/index.ts index 3672c64c..0c3ccdb4 100644 --- a/src/api/iot/thingmodel/index.ts +++ b/src/api/iot/thingmodel/index.ts @@ -17,6 +17,13 @@ export interface ThingModelData { service?: ThingModelService // 服务 } +/** + * IoT 模拟设备 + */ +export interface SimulatorData extends ThingModelData { + simulateValue?: string | number // 用于存储模拟值 +} + /** * ThingModelProperty 类型 */ diff --git a/src/views/iot/device/device/detail/DeviceDetailsLog.vue b/src/views/iot/device/device/detail/DeviceDetailsLog.vue index d0a43a5c..b73eb1b0 100644 --- a/src/views/iot/device/device/detail/DeviceDetailsLog.vue +++ b/src/views/iot/device/device/detail/DeviceDetailsLog.vue @@ -29,27 +29,18 @@ {{ formatDate(scope.row.time) }} - - - - + +
-
@@ -61,15 +52,17 @@ import { DICT_TYPE } from '@/utils/dict' import { formatDate } from '@/utils/formatTime' const props = defineProps<{ - deviceId: number + deviceKey: number }>() -// 查询参数 +//TODO:后续看看使用什么查询条件 目前后端是留了时间范围 type subType +// 查询参数 const queryParams = reactive({ - type: '', - keyword: '', + deviceKey: props.deviceKey, + // type: '', + // keyword: '', pageNo: 1, - pageSize: 20 + pageSize: 10 }) // 列表数据 @@ -90,30 +83,31 @@ const typeMap = { /** 查询日志列表 */ const getLogList = async () => { - // if (!props.deviceId) return - // loading.value = true - // try { - // const res = await DeviceApi.getDeviceLogs(props.deviceId, queryParams) - // total.value = res.total - // logList.value = res.list.map((item: any) => { - // const log = { - // time: item.time, - // type: typeMap[item.type as keyof typeof typeMap] || item.type, - // name: getLogName(item), - // content: item.content - // } - // return log - // }) - // } finally { - // loading.value = false - // } + if (!props.deviceKey) return + loading.value = true + try { + const res = await DeviceApi.getDeviceLogPage(queryParams) + total.value = res.total + logList.value = res.list.map((item: any) => { + const log = { + time: item.reportTime, + type: item.type, + subType: item.subType, + content: item.content + } + return log + }) + console.log(logList.value) + } finally { + loading.value = false + } } /** 获取日志名称 */ const getLogName = (log: any) => { const { type, identifier } = log let name = '未知' - + if (type === 'property') { if (identifier === 'set_reply') name = '设置回复' else if (identifier === 'report') name = '上报' @@ -123,7 +117,7 @@ const getLogName = (log: any) => { } else if (type === 'lifetime') { name = identifier === 'register' ? '注册' : name } - + return `${name}(${identifier})` } @@ -146,11 +140,14 @@ watch(autoRefresh, (newValue) => { }) /** 监听设备ID变化 */ -watch(() => props.deviceId, (newValue) => { - if (newValue) { - handleQuery() +watch( + () => props.deviceKey, + (newValue) => { + if (newValue) { + handleQuery() + } } -}) +) /** 组件卸载时清除定时器 */ onBeforeUnmount(() => { @@ -161,7 +158,7 @@ onBeforeUnmount(() => { /** 初始化 */ onMounted(() => { - if (props.deviceId) { + if (props.deviceKey) { getLogList() } }) diff --git a/src/views/iot/device/device/detail/DeviceDetailsSimulator.vue b/src/views/iot/device/device/detail/DeviceDetailsSimulator.vue index bc16d69f..7718f1a5 100644 --- a/src/views/iot/device/device/detail/DeviceDetailsSimulator.vue +++ b/src/views/iot/device/device/detail/DeviceDetailsSimulator.vue @@ -97,7 +97,7 @@ - + @@ -141,7 +141,7 @@ - + @@ -178,7 +178,7 @@ - + @@ -188,7 +188,7 @@