11
11
<el-tab-pane label =" 属性上报" name =" property" >
12
12
<ContentWrap >
13
13
<el-table v-loading =" loading" :data =" list" :show-overflow-tooltip =" true" :stripe =" true" >
14
- <el-table-column label =" 值" align =" center" width =" 80" >
15
- <template #default =" scope " >
16
- <el-input v-model =" scope.row.value" class =" !w-60px" />
17
- </template >
18
- </el-table-column >
19
14
<el-table-column align =" center" label =" 功能名称" prop =" name" />
20
15
<el-table-column align =" center" label =" 标识符" prop =" identifier" />
21
16
<el-table-column align =" center" label =" 数据类型" prop =" identifier" >
87
82
</div >
88
83
</template >
89
84
</el-table-column >
85
+ <el-table-column label =" 值" align =" center" width =" 80" >
86
+ <template #default =" scope " >
87
+ <el-input v-model =" scope.row.simulateValue" class =" !w-60px" />
88
+ </template >
89
+ </el-table-column >
90
90
</el-table >
91
91
<div class =" mt-10px" >
92
92
<el-button type =" primary" @click =" handlePropertyReport" >发送</el-button >
98
98
<el-tab-pane label =" 事件上报" name =" event" >
99
99
<ContentWrap >
100
100
<el-table v-loading =" loading" :data =" eventList" :stripe =" true" >
101
- <el-table-column label =" 值" align =" center" width =" 80" >
102
- <template #default =" scope " >
103
- <el-input v-model =" scope.row.value" class =" !w-60px" />
104
- </template >
105
- </el-table-column >
106
101
<el-table-column label =" 功能名称" align =" center" prop =" name" />
107
102
<el-table-column label =" 标识符" align =" center" prop =" identifier" />
108
103
<el-table-column label =" 数据类型" align =" center" prop =" dataType" />
112
107
prop =" specs"
113
108
:show-overflow-tooltip =" true"
114
109
/>
110
+ <el-table-column label =" 值" align =" center" width =" 80" >
111
+ <template #default =" scope " >
112
+ <el-input v-model =" scope.row.simulateValue" class =" !w-60px" />
113
+ </template >
114
+ </el-table-column >
115
115
</el-table >
116
116
<div class =" mt-10px" >
117
117
<el-button type =" primary" @click =" handleEventReport" >发送</el-button >
142
142
<el-tab-pane label =" 属性调试" name =" propertyDebug" >
143
143
<ContentWrap >
144
144
<el-table v-loading =" loading" :data =" propertyList" :stripe =" true" >
145
- <el-table-column label =" 值" align =" center" width =" 80" >
146
- <template #default =" scope " >
147
- <el-input v-model =" scope.row.value" class =" !w-60px" />
148
- </template >
149
- </el-table-column >
150
145
<el-table-column label =" 功能名称" align =" center" prop =" name" />
151
146
<el-table-column label =" 标识符" align =" center" prop =" identifier" />
152
147
<el-table-column label =" 数据类型" align =" center" prop =" dataType" />
156
151
prop =" specs"
157
152
:show-overflow-tooltip =" true"
158
153
/>
154
+ <el-table-column label =" 值" align =" center" width =" 80" >
155
+ <template #default =" scope " >
156
+ <el-input v-model =" scope.row.simulateValue" class =" !w-60px" />
157
+ </template >
158
+ </el-table-column >
159
159
</el-table >
160
160
<div class =" mt-10px" >
161
161
<el-button type =" primary" @click =" handlePropertyGet" >获取</el-button >
189
189
<script setup lang="ts">
190
190
import { ProductVO } from ' @/api/iot/product/product'
191
191
import { ThingModelApi , ThingModelData } from ' @/api/iot/thingmodel'
192
- import { DeviceApi , DeviceVO } from ' @/api/iot/device/device'
192
+ import { DeviceApi , DeviceVO , SimulatorDataVO } from ' @/api/iot/device/device'
193
193
import DeviceDetailsLog from ' ./DeviceDetailsLog.vue'
194
194
import {
195
195
DataSpecsDataType ,
@@ -210,18 +210,22 @@ const queryParams = reactive({
210
210
})
211
211
const dataTypeOptionsLabel = computed (() => (value : string ) => getDataTypeOptionsLabel (value )) // 解析数据类型
212
212
const props = defineProps <{ product: ProductVO ; device: DeviceVO }>()
213
- const list = ref <ThingModelData []>([]) // 物模型列表的数据
213
+ const list = ref <SimulatorData []>([]) // 物模型列表的数据
214
214
215
+ interface SimulatorData extends ThingModelData {
216
+ simulateValue? : string | number // 用于存储模拟值
217
+ }
215
218
/** 查询列表 */
216
219
const getList = async () => {
217
220
loading .value = true
218
221
try {
219
222
queryParams .productId = props .product ?.id || - 1
220
223
const data = await ThingModelApi .getThingModelList (queryParams )
221
- list .value = data
222
- console .log (data )
223
- console .log (list .value )
224
- console .log (queryParams )
224
+ // 转换数据,添加 simulateValue 字段
225
+ list .value = data .map (item => ({
226
+ ... item ,
227
+ simulateValue: ' '
228
+ }))
225
229
} finally {
226
230
loading .value = false
227
231
}
@@ -231,8 +235,6 @@ const getList = async () => {
231
235
interface TableItem {
232
236
name: string
233
237
identifier: string
234
- dataType: string
235
- specs: string
236
238
value: string | number
237
239
}
238
240
@@ -243,8 +245,6 @@ const propertyList = computed(() => {
243
245
.map ((item ) => ({
244
246
name: item .name ,
245
247
identifier: item .identifier ,
246
- dataType: item .dataType ,
247
- specs: item .specs ,
248
248
value: ' '
249
249
}))
250
250
})
@@ -255,8 +255,6 @@ const eventList = computed(() => {
255
255
.map ((item ) => ({
256
256
name: item .name ,
257
257
identifier: item .identifier ,
258
- dataType: item .dataType ,
259
- specs: item .specs ,
260
258
value: ' '
261
259
}))
262
260
})
@@ -293,22 +291,94 @@ watch(
293
291
{ immediate: true }
294
292
)
295
293
294
+ interface ReportData {
295
+ productKey: string
296
+ deviceKey: string
297
+ type: string
298
+ subType: string
299
+ reportTime: string
300
+ content: string // 改为 string 类型,存储 JSON 字符串
301
+ }
302
+
296
303
// 处理属性上报
297
304
const handlePropertyReport = async () => {
298
- // TODO: 实现属性上报逻辑
299
- message .success (' 属性上报成功' )
305
+ const contentObj: Record <string , any > = {}
306
+ list .value .forEach ((item ) => {
307
+ // 只有当 simulateValue 有值时才添加到 content 中
308
+ if (item .simulateValue !== undefined && item .simulateValue !== ' ' ) {
309
+ contentObj [item .identifier ] = item .simulateValue
310
+ }
311
+ })
312
+
313
+ const reportData: SimulatorDataVO = {
314
+ productKey: props .product .productKey ,
315
+ deviceKey: props .device .deviceKey ,
316
+ type: ' property' ,
317
+ subType: ' report' ,
318
+ reportTime: new Date ().toISOString (),
319
+ content: JSON .stringify (contentObj ) // 转换为 JSON 字符串
320
+ }
321
+
322
+ try {
323
+ // TODO: 调用API发送数据
324
+ console .log (' 上报数据:' , reportData )
325
+ console .log (' reportData.content' , reportData .content )
326
+ const data = await DeviceApi .simulatorDevice (reportData )
327
+ console .log (data )
328
+ message .success (' 属性上报成功123' )
329
+ } catch (error ) {
330
+ message .error (' 属性上报失败' )
331
+ }
300
332
}
301
333
302
334
// 处理事件上报
303
335
const handleEventReport = async () => {
304
- // TODO: 实现事件上报逻辑
305
- message .success (' 事件上报成功' )
336
+ const contentObj: Record <string , any > = {}
337
+ list .value
338
+ .filter (item => item .type === ' event' )
339
+ .forEach ((item ) => {
340
+ if (item .simulateValue !== undefined && item .simulateValue !== ' ' ) {
341
+ contentObj [item .identifier ] = item .simulateValue
342
+ }
343
+ })
344
+
345
+ const reportData: ReportData = {
346
+ productKey: props .product .productKey ,
347
+ deviceKey: props .device .deviceKey ,
348
+ type: ' event' ,
349
+ subType: list .value .find (item => item .type === ' event' )?.identifier || ' ' ,
350
+ reportTime: new Date ().toISOString (),
351
+ content: JSON .stringify (contentObj ) // 转换为 JSON 字符串
352
+ }
353
+
354
+ try {
355
+ // TODO: 调用API发送数据
356
+ console .log (' 上报数据:' , reportData )
357
+ message .success (' 事件上报成功' )
358
+ } catch (error ) {
359
+ message .error (' 事件上报失败' )
360
+ }
306
361
}
307
362
308
363
// 处理设备状态变更
309
364
const handleDeviceState = async (state : ' online' | ' offline' ) => {
310
- // TODO: 实现设备状态变更逻辑
311
- message .success (` 设备${state === ' online' ? ' 上线' : ' 下线' }成功 ` )
365
+ const reportData: ReportData = {
366
+ productKey: props .product .productKey ,
367
+ deviceKey: props .device .deviceKey ,
368
+ type: ' status' ,
369
+ subType: state ,
370
+ reportTime: new Date ().toISOString (),
371
+ content: JSON .stringify ({ status: state }) // 转换为 JSON 字符串
372
+ }
373
+
374
+ try {
375
+ // TODO: 调用API发送数据
376
+ console .log (' 状态变更数据:' , reportData )
377
+ console .log (' reportData.content111111111' , reportData .content )
378
+ message .success (` 设备${state === ' online' ? ' 上线' : ' 下线' }成功 ` )
379
+ } catch (error ) {
380
+ message .error (` 设备${state === ' online' ? ' 上线' : ' 下线' }失败 ` )
381
+ }
312
382
}
313
383
314
384
// 处理属性获取
0 commit comments