Skip to content

Commit 18617d3

Browse files
committed
【功能新增】IoT:支持 state 模拟上报(上线、下线)
1 parent 3c73a67 commit 18617d3

File tree

3 files changed

+24
-31
lines changed

3 files changed

+24
-31
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ export interface DeviceHistoryDataVO {
5050
}
5151

5252
// IoT 设备状态枚举
53-
export enum DeviceStatusEnum {
53+
export enum DeviceStateEnum {
5454
INACTIVE = 0, // 未激活
5555
ONLINE = 1, // 在线
56-
OFFLINE = 2, // 离线
57-
DISABLED = 3 // 已禁用
56+
OFFLINE = 2 // 离线
5857
}
5958

6059
// IoT 模拟设备上报数据 Request VO
6160
export interface IotDeviceSimulationReportReqVO {
6261
id: number // 设备编号
6362
type: string // 消息类型
6463
identifier: string // 标识符
65-
data: object // 请求参数
64+
data: any // 请求参数
6665
}
6766

6867
// 设备 API

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@
142142
<el-tab-pane label="状态变更" name="status">
143143
<ContentWrap>
144144
<div class="flex gap-4">
145-
<el-button type="primary" @click="handleDeviceState('online')">
145+
<el-button type="primary" @click="handleDeviceState(DeviceStateEnum.ONLINE)">
146146
设备上线
147147
</el-button>
148-
<el-button type="primary" @click="handleDeviceState('offline')">
148+
<el-button type="danger" @click="handleDeviceState(DeviceStateEnum.OFFLINE)">
149149
设备下线
150150
</el-button>
151151
</div>
@@ -210,7 +210,7 @@
210210
<script setup lang="ts">
211211
import { ProductVO } from '@/api/iot/product/product'
212212
import { ThingModelApi, SimulatorData } from '@/api/iot/thingmodel'
213-
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
213+
import { DeviceApi, DeviceStateEnum, DeviceVO } from '@/api/iot/device/device'
214214
import DeviceDetailsLog from './DeviceDetailsLog.vue'
215215
import {
216216
DataSpecsDataType,
@@ -372,26 +372,20 @@ const handlePropertyReport = async () => {
372372
// }
373373
// }
374374
375-
// // 处理设备状态变更
376-
// const handleDeviceState = async (state: 'online' | 'offline') => {
377-
// const reportData: ReportData = {
378-
// productKey: props.product.productKey,
379-
// deviceKey: props.device.deviceKey,
380-
// type: 'status',
381-
// subType: state,
382-
// reportTime: new Date().toISOString(),
383-
// content: JSON.stringify({ status: state }) // 转换为 JSON 字符串
384-
// }
385-
386-
// try {
387-
// // TODO: 调用API发送数据
388-
// console.log('状态变更数据:', reportData)
389-
// console.log('reportData.content111111111', reportData.content)
390-
// message.success(`设备${state === 'online' ? '上线' : '下线'}成功`)
391-
// } catch (error) {
392-
// message.error(`设备${state === 'online' ? '上线' : '下线'}失败`)
393-
// }
394-
// }
375+
/** 处理设备状态 */
376+
const handleDeviceState = async (state: number) => {
377+
try {
378+
await DeviceApi.simulationReportDevice({
379+
id: props.device.id,
380+
type: 'state',
381+
identifier: 'report',
382+
data: state
383+
})
384+
message.success(`设备${state === DeviceStateEnum.ONLINE ? '上线' : '下线'}成功`)
385+
} catch (error) {
386+
message.error(`设备${state === DeviceStateEnum.ONLINE ? '上线' : '下线'}失败`)
387+
}
388+
}
395389
396390
// 处理属性获取
397391
const handlePropertyGet = async () => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
<div
162162
class="absolute top-0 left-0 right-0 h-[50px] pointer-events-none"
163163
:class="[
164-
item.state === DeviceStatusEnum.ONLINE
164+
item.state === DeviceStateEnum.ONLINE
165165
? 'bg-gradient-to-b from-[#eefaff] to-transparent'
166166
: 'bg-gradient-to-b from-[#fff1f1] to-transparent'
167167
]"
@@ -179,15 +179,15 @@
179179
<div
180180
class="w-1 h-1 rounded-full mr-1.5"
181181
:class="
182-
item.state === DeviceStatusEnum.ONLINE
182+
item.state === DeviceStateEnum.ONLINE
183183
? 'bg-[var(--el-color-success)]'
184184
: 'bg-[var(--el-color-danger)]'
185185
"
186186
>
187187
</div>
188188
<el-text
189189
class="!text-xs font-bold"
190-
:type="item.state === DeviceStatusEnum.ONLINE ? 'success' : 'danger'"
190+
:type="item.state === DeviceStateEnum.ONLINE ? 'success' : 'danger'"
191191
>
192192
{{ getDictLabel(DICT_TYPE.IOT_DEVICE_STATE, item.state) }}
193193
</el-text>
@@ -369,7 +369,7 @@
369369
<script setup lang="ts">
370370
import { DICT_TYPE, getIntDictOptions, getDictLabel } from '@/utils/dict'
371371
import { dateFormatter } from '@/utils/formatTime'
372-
import { DeviceApi, DeviceVO, DeviceStatusEnum } from '@/api/iot/device/device'
372+
import { DeviceApi, DeviceVO, DeviceStateEnum } from '@/api/iot/device/device'
373373
import DeviceForm from './DeviceForm.vue'
374374
import { ProductApi, ProductVO } from '@/api/iot/product/product'
375375
import { DeviceGroupApi, DeviceGroupVO } from '@/api/iot/device/group'

0 commit comments

Comments
 (0)