1
1
<template >
2
2
<ContentWrap >
3
- <!-- TODO @super:建议每个 tab 做成一个小的组件。命名为了排版整齐点,可以叫 DeviceDetailsSimulatorPropertyUpstream、DeviceDetailsSimulatorEventUpstream -->
4
3
<el-row :gutter =" 20" >
5
4
<!-- 左侧指令调试区域 -->
6
5
<el-col :span =" 12" >
17
16
:show-overflow-tooltip =" true"
18
17
:stripe =" true"
19
18
>
19
+ <!-- TODO @super:每个 colum 搞下宽度,避免 table 每一列最后有个 . -->
20
20
<el-table-column align =" center" label =" 功能名称" prop =" name" />
21
21
<el-table-column align =" center" label =" 标识符" prop =" identifier" />
22
22
<el-table-column align =" center" label =" 数据类型" prop =" identifier" >
38
38
].includes(row.property.dataType)
39
39
"
40
40
>
41
- 取值范围:{{
42
- `${row.property.dataSpecs.min}~${row.property.dataSpecs.max}`
43
- }}
41
+ 取值范围:
42
+ {{ `${row.property.dataSpecs.min}~${row.property.dataSpecs.max}` }}
44
43
</div >
45
44
<!-- 非列表型:文本 -->
46
45
<div v-if =" DataSpecsDataType.TEXT === row.property.dataType" >
95
94
</el-table-column >
96
95
</el-table >
97
96
<div class =" mt-10px" >
98
- <el-button type =" primary" @click =" handlePropertyReport" >发送</el-button >
97
+ <el-button
98
+ type =" primary"
99
+ @click =" handlePropertyReport"
100
+ v-hasPermi =" ['iot:device:simulation-report']"
101
+ >
102
+ 发送
103
+ </el-button >
99
104
</div >
100
105
</ContentWrap >
101
106
</el-tab-pane >
102
107
103
108
<!-- 事件上报 -->
109
+ <!-- TODO @super:待实现 -->
104
110
<el-tab-pane label =" 事件上报" name =" event" >
105
111
<ContentWrap >
106
112
<!-- <el-table v-loading="loading" :data="eventList" :stripe="true">
129
135
<el-tab-pane label =" 状态变更" name =" status" >
130
136
<ContentWrap >
131
137
<div class =" flex gap-4" >
132
- <el-button type =" primary" @click =" handleDeviceState('online')"
133
- > 设备上线</ el-button
134
- >
135
- <el-button type =" primary" @click =" handleDeviceState('offline')"
136
- > 设备下线</ el-button
137
- >
138
+ <el-button type =" primary" @click =" handleDeviceState('online')" >
139
+ 设备上线
140
+ </ el-button >
141
+ <el-button type =" primary" @click =" handleDeviceState('offline')" >
142
+ 设备下线
143
+ </ el-button >
138
144
</div >
139
145
</ContentWrap >
140
146
</el-tab-pane >
141
147
</el-tabs >
142
148
</el-tab-pane >
143
149
144
150
<!-- 下行指令调试 -->
151
+ <!-- TODO @super:待实现 -->
145
152
<el-tab-pane label =" 下行指令调试" name =" down" >
146
153
<el-tabs v-model =" subTab" v-if =" activeTab === 'down'" >
147
154
<!-- 属性调试 -->
170
177
</el-tab-pane >
171
178
172
179
<!-- 服务调用 -->
180
+ <!-- TODO @super:待实现 -->
173
181
<el-tab-pane label =" 服务调用" name =" service" >
174
182
<ContentWrap >
175
183
<!-- 服务调用相关内容 -->
184
192
<el-col :span =" 12" >
185
193
<el-tabs type =" border-card" >
186
194
<el-tab-pane label =" 设备日志" >
187
- <DeviceDetailsLog :deviceKey =" device.deviceKey" />
195
+ <DeviceDetailsLog :device-key =" device.deviceKey" />
188
196
</el-tab-pane >
189
197
</el-tabs >
190
198
</el-col >
195
203
<script setup lang="ts">
196
204
import { ProductVO } from ' @/api/iot/product/product'
197
205
import { ThingModelApi , SimulatorData } from ' @/api/iot/thingmodel'
198
- import { DeviceApi , DeviceVO , SimulatorDataVO } from ' @/api/iot/device/device'
206
+ import { DeviceApi , DeviceVO } from ' @/api/iot/device/device'
199
207
import DeviceDetailsLog from ' ./DeviceDetailsLog.vue'
200
208
import {
201
209
DataSpecsDataType ,
@@ -205,26 +213,33 @@ import {
205
213
ThingModelType
206
214
} from ' @/views/iot/thingmodel/config'
207
215
216
+ const props = defineProps <{
217
+ product: ProductVO
218
+ device: DeviceVO
219
+ }>()
220
+
208
221
const message = useMessage () // 消息弹窗
209
- const loading = ref (false )
210
- const activeTab = ref (' up' )
211
- const subTab = ref (' property' )
222
+ const activeTab = ref (' up' ) // TODO @super:upstream 上行、downstream 下行
223
+ const subTab = ref (' property' ) // TODO @super:upstreamTab
212
224
225
+ const loading = ref (false )
213
226
const queryParams = reactive ({
214
- type: undefined ,
227
+ type: undefined , // TODO @super:type 默认给个第一个 tab 对应的,避免下面 watch 爆红
215
228
productId: - 1
216
229
})
230
+ const list = ref <SimulatorData []>([]) // 物模型列表的数据 TODO @super:thingModelList
231
+ // TODO @super:dataTypeOptionsLabel 是不是不用定义,直接用 getDataTypeOptionsLabel 在 template 中使用即可?
217
232
const dataTypeOptionsLabel = computed (() => (value : string ) => getDataTypeOptionsLabel (value )) // 解析数据类型
218
- const props = defineProps <{ product: ProductVO ; device: DeviceVO }>()
219
- const list = ref <SimulatorData []>([]) // 物模型列表的数据
220
233
221
- /** 查询列表 */
234
+ /** 查询物模型列表 */
235
+ // TODO @super:getThingModelList 更精准
222
236
const getList = async () => {
223
237
loading .value = true
224
238
try {
225
239
queryParams .productId = props .product ?.id || - 1
226
240
const data = await ThingModelApi .getThingModelList (queryParams )
227
241
// 转换数据,添加 simulateValue 字段
242
+ // TODO @super:貌似下面的 simulateValue 不设置也可以?
228
243
list .value = data .map ((item ) => ({
229
244
... item ,
230
245
simulateValue: ' '
@@ -262,7 +277,8 @@ const getList = async () => {
262
277
// }))
263
278
// })
264
279
265
- // 监听标签页变化 todo:后续改成查询字典
280
+ /** 监听标签页变化 */
281
+ // todo:后续改成查询字典
266
282
watch (
267
283
[activeTab , subTab ],
268
284
([newActiveTab , newSubTab ]) => {
@@ -294,36 +310,26 @@ watch(
294
310
{ immediate: true }
295
311
)
296
312
297
- // interface ReportData {
298
- // productKey: string
299
- // deviceKey: string
300
- // type: string
301
- // subType: string
302
- // reportTime: string
303
- // content: string // 改为 string 类型,存储 JSON 字符串
304
- // }
305
-
306
- // 处理属性上报 TODO:数据类型效验
313
+ /** 处理属性上报 */
307
314
const handlePropertyReport = async () => {
308
- const contentObj: Record <string , any > = {}
315
+ // TODO @super:数据类型效验
316
+ const data: Record <string , object > = {}
309
317
list .value .forEach ((item ) => {
310
318
// 只有当 simulateValue 有值时才添加到 content 中
319
+ // TODO @super:直接 if (item.simulateValue) 就可以哈,js 这块还是比较灵活的
311
320
if (item .simulateValue !== undefined && item .simulateValue !== ' ' ) {
312
- contentObj [item .identifier ] = item .simulateValue
321
+ // TODO @super:这里有个红色的 idea 告警,觉得去除下
322
+ data [item .identifier ] = item .simulateValue
313
323
}
314
324
})
315
325
316
- const reportData: SimulatorDataVO = {
317
- productKey: props .product .productKey ,
318
- deviceKey: props .device .deviceKey ,
319
- type: ' property' ,
320
- subType: ' report' ,
321
- reportTime: Date .now (), // 将 reportTime 变为数字类型的时间戳
322
- content: JSON .stringify (contentObj ) // 转换为 JSON 字符串
323
- }
324
-
325
326
try {
326
- await DeviceApi .simulatorDevice (reportData )
327
+ await DeviceApi .simulationReportDevice ({
328
+ id: props .device .id ,
329
+ type: ' property' ,
330
+ identifier: ' report' ,
331
+ data: data
332
+ })
327
333
message .success (' 属性上报成功' )
328
334
} catch (error ) {
329
335
message .error (' 属性上报失败' )
0 commit comments