Skip to content

Commit c9e00d9

Browse files
committed
feat:deviceLog and deviceSimulator
1 parent b71fa84 commit c9e00d9

File tree

6 files changed

+143
-142
lines changed

6 files changed

+143
-142
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"source.fixAll.stylelint": "explicit"
8888
},
8989
"[vue]": {
90-
"editor.defaultFormatter": "esbenp.prettier-vscode"
90+
"editor.defaultFormatter": "octref.vetur"
9191
},
9292
"i18n-ally.localesPaths": ["src/locales"],
9393
"i18n-ally.keystyle": "nested",

src/api/iot/device/device/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export interface SimulatorDataVO {
6969
deviceKey: string
7070
type: string
7171
subType: string
72-
reportTime: string
72+
reportTime: number // 时间戳
7373
content: string // 存储 JSON 字符串
7474
}
7575

@@ -151,5 +151,9 @@ export const DeviceApi = {
151151
// 模拟设备
152152
simulatorDevice: async (data: SimulatorDataVO) => {
153153
return await request.post({ url: `/iot/device/data/simulator`, data })
154+
},
155+
//查询设备日志分页
156+
getDeviceLogPage: async (params: any) => {
157+
return await request.get({ url: `/iot/device/data/log/page`, params })
154158
}
155159
}

src/api/iot/thingmodel/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export interface ThingModelData {
1717
service?: ThingModelService // 服务
1818
}
1919

20+
/**
21+
* IoT 模拟设备
22+
*/
23+
export interface SimulatorData extends ThingModelData {
24+
simulateValue?: string | number // 用于存储模拟值
25+
}
26+
2027
/**
2128
* ThingModelProperty 类型
2229
*/

src/views/iot/device/device/detail/DeviceDetailsLog.vue

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,18 @@
2929
{{ formatDate(scope.row.time) }}
3030
</template>
3131
</el-table-column>
32-
<el-table-column label="类型" align="center" prop="type" width="120">
33-
<template #default="scope">
34-
<dict-tag :type="DICT_TYPE.IOT_MESSAGE_TYPE" :value="scope.row.type" />
35-
</template>
36-
</el-table-column>
37-
<el-table-column label="名称(标识符)" align="center" prop="name" />
32+
<el-table-column label="类型" align="center" prop="type" width="120" />
33+
<el-table-column label="名称(标识符)" align="center" prop="subType" width="120" />
3834
<el-table-column label="内容" align="center" prop="content" :show-overflow-tooltip="true" />
3935
</el-table>
4036

4137
<!-- 分页 -->
4238
<div class="mt-10px flex justify-end">
43-
<el-pagination
44-
v-model:current-page="queryParams.pageNo"
45-
v-model:page-size="queryParams.pageSize"
39+
<Pagination
4640
:total="total"
47-
:page-sizes="[10, 20, 50, 100]"
48-
small
49-
background
50-
layout="total, sizes, prev, pager, next, jumper"
51-
@size-change="handleQuery"
52-
@current-change="handleQuery"
41+
v-model:page="queryParams.pageNo"
42+
v-model:limit="queryParams.pageSize"
43+
@pagination="getLogList"
5344
/>
5445
</div>
5546
</ContentWrap>
@@ -61,15 +52,17 @@ import { DICT_TYPE } from '@/utils/dict'
6152
import { formatDate } from '@/utils/formatTime'
6253
6354
const props = defineProps<{
64-
deviceId: number
55+
deviceKey: number
6556
}>()
6657
67-
// 查询参数
58+
//TODO:后续看看使用什么查询条件 目前后端是留了时间范围 type subType
59+
// 查询参数
6860
const queryParams = reactive({
69-
type: '',
70-
keyword: '',
61+
deviceKey: props.deviceKey,
62+
// type: '',
63+
// keyword: '',
7164
pageNo: 1,
72-
pageSize: 20
65+
pageSize: 10
7366
})
7467
7568
// 列表数据
@@ -90,30 +83,31 @@ const typeMap = {
9083
9184
/** 查询日志列表 */
9285
const getLogList = async () => {
93-
// if (!props.deviceId) return
94-
// loading.value = true
95-
// try {
96-
// const res = await DeviceApi.getDeviceLogs(props.deviceId, queryParams)
97-
// total.value = res.total
98-
// logList.value = res.list.map((item: any) => {
99-
// const log = {
100-
// time: item.time,
101-
// type: typeMap[item.type as keyof typeof typeMap] || item.type,
102-
// name: getLogName(item),
103-
// content: item.content
104-
// }
105-
// return log
106-
// })
107-
// } finally {
108-
// loading.value = false
109-
// }
86+
if (!props.deviceKey) return
87+
loading.value = true
88+
try {
89+
const res = await DeviceApi.getDeviceLogPage(queryParams)
90+
total.value = res.total
91+
logList.value = res.list.map((item: any) => {
92+
const log = {
93+
time: item.reportTime,
94+
type: item.type,
95+
subType: item.subType,
96+
content: item.content
97+
}
98+
return log
99+
})
100+
console.log(logList.value)
101+
} finally {
102+
loading.value = false
103+
}
110104
}
111105
112106
/** 获取日志名称 */
113107
const getLogName = (log: any) => {
114108
const { type, identifier } = log
115109
let name = '未知'
116-
110+
117111
if (type === 'property') {
118112
if (identifier === 'set_reply') name = '设置回复'
119113
else if (identifier === 'report') name = '上报'
@@ -123,7 +117,7 @@ const getLogName = (log: any) => {
123117
} else if (type === 'lifetime') {
124118
name = identifier === 'register' ? '注册' : name
125119
}
126-
120+
127121
return `${name}(${identifier})`
128122
}
129123
@@ -146,11 +140,14 @@ watch(autoRefresh, (newValue) => {
146140
})
147141
148142
/** 监听设备ID变化 */
149-
watch(() => props.deviceId, (newValue) => {
150-
if (newValue) {
151-
handleQuery()
143+
watch(
144+
() => props.deviceKey,
145+
(newValue) => {
146+
if (newValue) {
147+
handleQuery()
148+
}
152149
}
153-
})
150+
)
154151
155152
/** 组件卸载时清除定时器 */
156153
onBeforeUnmount(() => {
@@ -161,7 +158,7 @@ onBeforeUnmount(() => {
161158
162159
/** 初始化 */
163160
onMounted(() => {
164-
if (props.deviceId) {
161+
if (props.deviceKey) {
165162
getLogList()
166163
}
167164
})

0 commit comments

Comments
 (0)