Skip to content

Commit 3dc7d20

Browse files
committed
【代码评审】IoT:设备日志 TDengine 表与模拟设备
1 parent f2f414a commit 3dc7d20

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,20 @@ export interface DeviceHistoryDataVO {
5858
// IoT 设备状态枚举
5959
export enum DeviceStatusEnum {
6060
INACTIVE = 0, // 未激活
61-
ONLINE = 1, // 在线
62-
OFFLINE = 2, // 离线
63-
DISABLED = 3 // 已禁用
61+
ONLINE = 1, // 在线
62+
OFFLINE = 2, // 离线
63+
DISABLED = 3 // 已禁用
6464
}
6565

6666
// IoT 模拟设备数据
67+
// TODO @super:DeviceSimulatorDataReqVO
6768
export interface SimulatorDataVO {
6869
productKey: string
6970
deviceKey: string
7071
type: string
7172
subType: string
7273
reportTime: number // 时间戳
73-
content: string // 存储 JSON 字符串
74+
content: string // 存储 JSON 字符串
7475
}
7576

7677
// 设备 API
@@ -101,10 +102,7 @@ export const DeviceApi = {
101102
},
102103

103104
// 修改设备分组
104-
updateDeviceGroup: async (data: {
105-
ids: number[]
106-
groupIds: number[]
107-
}) => {
105+
updateDeviceGroup: async (data: { ids: number[]; groupIds: number[] }) => {
108106
return await request.put({ url: `/iot/device/update-group`, data })
109107
},
110108

@@ -150,10 +148,12 @@ export const DeviceApi = {
150148

151149
// 模拟设备
152150
simulatorDevice: async (data: SimulatorDataVO) => {
151+
// TODO @super:/iot/device/simulator
153152
return await request.post({ url: `/iot/device/data/simulator`, data })
154153
},
155-
//查询设备日志分页
154+
// 查询设备日志分页
156155
getDeviceLogPage: async (params: any) => {
156+
// TODO @super:/iot/log-page 或者 /iot/log/page
157157
return await request.get({ url: `/iot/device/data/log/page`, params })
158158
}
159159
}

src/api/iot/thingmodel/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ export interface ThingModelData {
2020
/**
2121
* IoT 模拟设备
2222
*/
23+
// TODO @super:和 ThingModelSimulatorData 会不会好点
2324
export interface SimulatorData extends ThingModelData {
24-
simulateValue?: string | number // 用于存储模拟值
25+
simulateValue?: string | number // 用于存储模拟值 TODO @super:字段使用 value 会不会好点
2526
}
2627

2728
/**

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<el-form-item>
66
<el-select v-model="queryParams.type" placeholder="所有" class="!w-120px">
77
<el-option label="所有" value="" />
8+
<!-- TODO @super:搞成枚举 -->
89
<el-option label="状态" value="state" />
910
<el-option label="事件" value="event" />
1011
<el-option label="属性" value="property" />
@@ -48,15 +49,14 @@
4849

4950
<script setup lang="ts">
5051
import { DeviceApi } from '@/api/iot/device/device'
51-
import { DICT_TYPE } from '@/utils/dict'
5252
import { formatDate } from '@/utils/formatTime'
5353
5454
const props = defineProps<{
5555
deviceKey: number
5656
}>()
5757
5858
//TODO:后续看看使用什么查询条件 目前后端是留了时间范围 type subType
59-
// 查询参数
59+
// 查询参数
6060
const queryParams = reactive({
6161
deviceKey: props.deviceKey,
6262
// type: '',
@@ -68,11 +68,12 @@ const queryParams = reactive({
6868
// 列表数据
6969
const loading = ref(false)
7070
const total = ref(0)
71+
// TODO @super:字段的风格,还是类似一般 table 见面哈
7172
const logList = ref([])
7273
const autoRefresh = ref(false)
73-
let timer: any = null
74+
let timer: any = null // TODO @super:autoRefreshEnable,autoRefreshTimer;对应上
7475
75-
// 类型映射
76+
// 类型映射 TODO @super:需要删除么?
7677
const typeMap = {
7778
lifetime: '生命周期',
7879
state: '设备状态',
@@ -88,6 +89,7 @@ const getLogList = async () => {
8889
try {
8990
const res = await DeviceApi.getDeviceLogPage(queryParams)
9091
total.value = res.total
92+
// TODO @super:尽量不转换
9193
logList.value = res.list.map((item: any) => {
9294
const log = {
9395
time: item.reportTime,
@@ -138,7 +140,7 @@ watch(autoRefresh, (newValue) => {
138140
}
139141
})
140142
141-
/** 监听设备ID变化 */
143+
/** 监听设备 ID 变化 */
142144
watch(
143145
() => props.deviceKey,
144146
(newValue) => {

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<ContentWrap>
3+
<!-- TODO @super:建议每个 tab 做成一个小的组件。命名为了排版整齐点,可以叫 DeviceDetailsSimulatorPropertyUpstream、DeviceDetailsSimulatorEventUpstream -->
34
<el-row :gutter="20">
45
<!-- 左侧指令调试区域 -->
56
<el-col :span="12">
@@ -10,7 +11,12 @@
1011
<!-- 属性上报 -->
1112
<el-tab-pane label="属性上报" name="property">
1213
<ContentWrap>
13-
<el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
14+
<el-table
15+
v-loading="loading"
16+
:data="list"
17+
:show-overflow-tooltip="true"
18+
:stripe="true"
19+
>
1420
<el-table-column align="center" label="功能名称" prop="name" />
1521
<el-table-column align="center" label="标识符" prop="identifier" />
1622
<el-table-column align="center" label="数据类型" prop="identifier">
@@ -188,8 +194,8 @@
188194

189195
<script setup lang="ts">
190196
import { ProductVO } from '@/api/iot/product/product'
191-
import { ThingModelApi, ThingModelData,SimulatorData } from '@/api/iot/thingmodel'
192-
import { DeviceApi, DeviceVO,SimulatorDataVO } from '@/api/iot/device/device'
197+
import { ThingModelApi, SimulatorData } from '@/api/iot/thingmodel'
198+
import { DeviceApi, DeviceVO, SimulatorDataVO } from '@/api/iot/device/device'
193199
import DeviceDetailsLog from './DeviceDetailsLog.vue'
194200
import {
195201
DataSpecsDataType,
@@ -219,7 +225,7 @@ const getList = async () => {
219225
queryParams.productId = props.product?.id || -1
220226
const data = await ThingModelApi.getThingModelList(queryParams)
221227
// 转换数据,添加 simulateValue 字段
222-
list.value = data.map(item => ({
228+
list.value = data.map((item) => ({
223229
...item,
224230
simulateValue: ''
225231
}))
@@ -313,7 +319,7 @@ const handlePropertyReport = async () => {
313319
type: 'property',
314320
subType: 'report',
315321
reportTime: Date.now(), // 将 reportTime 变为数字类型的时间戳
316-
content: JSON.stringify(contentObj) // 转换为 JSON 字符串
322+
content: JSON.stringify(contentObj) // 转换为 JSON 字符串
317323
}
318324
319325
try {
@@ -384,4 +390,5 @@ const handlePropertyGet = async () => {
384390
onMounted(() => {
385391
getList()
386392
})
393+
// TODO @芋艿:后续再详细 review 下;
387394
</script>

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
<el-tab-pane label="子设备管理" v-if="product.deviceType === DeviceTypeEnum.GATEWAY" />
1818
<el-tab-pane label="设备影子" />
1919
<el-tab-pane label="设备日志" name="log">
20-
<DeviceDetailsLog v-if="activeTab === 'log'" :deviceKey="device.deviceKey" />
20+
<!-- TODO @super:字段类型,:device-key。idea 会告警,应该是 string -->
21+
<DeviceDetailsLog v-if="activeTab === 'log'" :device-key="device.deviceKey" />
2122
</el-tab-pane>
2223
<el-tab-pane label="模拟设备" name="simulator">
23-
<DeviceDetailsSimulator v-if="activeTab === 'simulator'" :product="product" :device="device" />
24-
</el-tab-pane>
24+
<DeviceDetailsSimulator
25+
v-if="activeTab === 'simulator'"
26+
:product="product"
27+
:device="device"
28+
/>
29+
</el-tab-pane>
2530
</el-tabs>
2631
</el-col>
2732
</template>
@@ -34,6 +39,7 @@ import DeviceDetailsInfo from './DeviceDetailsInfo.vue'
3439
import DeviceDetailsModel from './DeviceDetailsModel.vue'
3540
import DeviceDetailsLog from './DeviceDetailsLog.vue'
3641
import DeviceDetailsSimulator from './DeviceDetailsSimulator.vue'
42+
3743
defineOptions({ name: 'IoTDeviceDetail' })
3844
3945
const route = useRoute()

0 commit comments

Comments
 (0)