Skip to content

Commit 3d65f1c

Browse files
committed
【功能优化】Bpm:设备属性上报
1 parent 3dc7d20 commit 3d65f1c

File tree

3 files changed

+60
-56
lines changed

3 files changed

+60
-56
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,12 @@ export enum DeviceStatusEnum {
6363
DISABLED = 3 // 已禁用
6464
}
6565

66-
// IoT 模拟设备数据
67-
// TODO @super:DeviceSimulatorDataReqVO
68-
export interface SimulatorDataVO {
69-
productKey: string
70-
deviceKey: string
71-
type: string
72-
subType: string
73-
reportTime: number // 时间戳
74-
content: string // 存储 JSON 字符串
66+
// IoT 模拟设备上报数据 Request VO
67+
export interface IotDeviceSimulationReportReqVO {
68+
id: number // 设备编号
69+
type: string // 消息类型
70+
identifier: string // 标识符
71+
data: object // 请求参数
7572
}
7673

7774
// 设备 API
@@ -146,11 +143,12 @@ export const DeviceApi = {
146143
return await request.download({ url: `/iot/device/get-import-template` })
147144
},
148145

149-
// 模拟设备
150-
simulatorDevice: async (data: SimulatorDataVO) => {
146+
// 模拟设备上报
147+
simulationReportDevice: async (data: IotDeviceSimulationReportReqVO) => {
151148
// TODO @super:/iot/device/simulator
152-
return await request.post({ url: `/iot/device/data/simulator`, data })
149+
return await request.post({ url: `/iot/device/simulation-report`, data })
153150
},
151+
154152
// 查询设备日志分页
155153
getDeviceLogPage: async (params: any) => {
156154
// TODO @super:/iot/log-page 或者 /iot/log/page

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { DeviceApi } from '@/api/iot/device/device'
5252
import { formatDate } from '@/utils/formatTime'
5353
5454
const props = defineProps<{
55-
deviceKey: number
55+
deviceKey: string
5656
}>()
5757
5858
//TODO:后续看看使用什么查询条件 目前后端是留了时间范围 type subType

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

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<ContentWrap>
3-
<!-- TODO @super:建议每个 tab 做成一个小的组件。命名为了排版整齐点,可以叫 DeviceDetailsSimulatorPropertyUpstream、DeviceDetailsSimulatorEventUpstream -->
43
<el-row :gutter="20">
54
<!-- 左侧指令调试区域 -->
65
<el-col :span="12">
@@ -17,6 +16,7 @@
1716
:show-overflow-tooltip="true"
1817
:stripe="true"
1918
>
19+
<!-- TODO @super:每个 colum 搞下宽度,避免 table 每一列最后有个 . -->
2020
<el-table-column align="center" label="功能名称" prop="name" />
2121
<el-table-column align="center" label="标识符" prop="identifier" />
2222
<el-table-column align="center" label="数据类型" prop="identifier">
@@ -38,9 +38,8 @@
3838
].includes(row.property.dataType)
3939
"
4040
>
41-
取值范围:{{
42-
`${row.property.dataSpecs.min}~${row.property.dataSpecs.max}`
43-
}}
41+
取值范围:
42+
{{ `${row.property.dataSpecs.min}~${row.property.dataSpecs.max}` }}
4443
</div>
4544
<!-- 非列表型:文本 -->
4645
<div v-if="DataSpecsDataType.TEXT === row.property.dataType">
@@ -95,12 +94,19 @@
9594
</el-table-column>
9695
</el-table>
9796
<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>
99104
</div>
100105
</ContentWrap>
101106
</el-tab-pane>
102107

103108
<!-- 事件上报 -->
109+
<!-- TODO @super:待实现 -->
104110
<el-tab-pane label="事件上报" name="event">
105111
<ContentWrap>
106112
<!-- <el-table v-loading="loading" :data="eventList" :stripe="true">
@@ -129,19 +135,20 @@
129135
<el-tab-pane label="状态变更" name="status">
130136
<ContentWrap>
131137
<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>
138144
</div>
139145
</ContentWrap>
140146
</el-tab-pane>
141147
</el-tabs>
142148
</el-tab-pane>
143149

144150
<!-- 下行指令调试 -->
151+
<!-- TODO @super:待实现 -->
145152
<el-tab-pane label="下行指令调试" name="down">
146153
<el-tabs v-model="subTab" v-if="activeTab === 'down'">
147154
<!-- 属性调试 -->
@@ -170,6 +177,7 @@
170177
</el-tab-pane>
171178

172179
<!-- 服务调用 -->
180+
<!-- TODO @super:待实现 -->
173181
<el-tab-pane label="服务调用" name="service">
174182
<ContentWrap>
175183
<!-- 服务调用相关内容 -->
@@ -184,7 +192,7 @@
184192
<el-col :span="12">
185193
<el-tabs type="border-card">
186194
<el-tab-pane label="设备日志">
187-
<DeviceDetailsLog :deviceKey="device.deviceKey" />
195+
<DeviceDetailsLog :device-key="device.deviceKey" />
188196
</el-tab-pane>
189197
</el-tabs>
190198
</el-col>
@@ -195,7 +203,7 @@
195203
<script setup lang="ts">
196204
import { ProductVO } from '@/api/iot/product/product'
197205
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'
199207
import DeviceDetailsLog from './DeviceDetailsLog.vue'
200208
import {
201209
DataSpecsDataType,
@@ -205,26 +213,33 @@ import {
205213
ThingModelType
206214
} from '@/views/iot/thingmodel/config'
207215
216+
const props = defineProps<{
217+
product: ProductVO
218+
device: DeviceVO
219+
}>()
220+
208221
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
212224
225+
const loading = ref(false)
213226
const queryParams = reactive({
214-
type: undefined,
227+
type: undefined, // TODO @super:type 默认给个第一个 tab 对应的,避免下面 watch 爆红
215228
productId: -1
216229
})
230+
const list = ref<SimulatorData[]>([]) // 物模型列表的数据 TODO @super:thingModelList
231+
// TODO @super:dataTypeOptionsLabel 是不是不用定义,直接用 getDataTypeOptionsLabel 在 template 中使用即可?
217232
const dataTypeOptionsLabel = computed(() => (value: string) => getDataTypeOptionsLabel(value)) // 解析数据类型
218-
const props = defineProps<{ product: ProductVO; device: DeviceVO }>()
219-
const list = ref<SimulatorData[]>([]) // 物模型列表的数据
220233
221-
/** 查询列表 */
234+
/** 查询物模型列表 */
235+
// TODO @super:getThingModelList 更精准
222236
const getList = async () => {
223237
loading.value = true
224238
try {
225239
queryParams.productId = props.product?.id || -1
226240
const data = await ThingModelApi.getThingModelList(queryParams)
227241
// 转换数据,添加 simulateValue 字段
242+
// TODO @super:貌似下面的 simulateValue 不设置也可以?
228243
list.value = data.map((item) => ({
229244
...item,
230245
simulateValue: ''
@@ -262,7 +277,8 @@ const getList = async () => {
262277
// }))
263278
// })
264279
265-
// 监听标签页变化 todo:后续改成查询字典
280+
/** 监听标签页变化 */
281+
// todo:后续改成查询字典
266282
watch(
267283
[activeTab, subTab],
268284
([newActiveTab, newSubTab]) => {
@@ -294,36 +310,26 @@ watch(
294310
{ immediate: true }
295311
)
296312
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+
/** 处理属性上报 */
307314
const handlePropertyReport = async () => {
308-
const contentObj: Record<string, any> = {}
315+
// TODO @super:数据类型效验
316+
const data: Record<string, object> = {}
309317
list.value.forEach((item) => {
310318
// 只有当 simulateValue 有值时才添加到 content 中
319+
// TODO @super:直接 if (item.simulateValue) 就可以哈,js 这块还是比较灵活的
311320
if (item.simulateValue !== undefined && item.simulateValue !== '') {
312-
contentObj[item.identifier] = item.simulateValue
321+
// TODO @super:这里有个红色的 idea 告警,觉得去除下
322+
data[item.identifier] = item.simulateValue
313323
}
314324
})
315325
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-
325326
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+
})
327333
message.success('属性上报成功')
328334
} catch (error) {
329335
message.error('属性上报失败')

0 commit comments

Comments
 (0)