【功能新增】IoT:支持 state 模拟上报(上线、下线)

This commit is contained in:
YunaiV 2025-01-29 21:33:12 +08:00
parent 3c73a6728f
commit 18617d309b
3 changed files with 24 additions and 31 deletions

View File

@ -50,11 +50,10 @@ export interface DeviceHistoryDataVO {
}
// IoT 设备状态枚举
export enum DeviceStatusEnum {
export enum DeviceStateEnum {
INACTIVE = 0, // 未激活
ONLINE = 1, // 在线
OFFLINE = 2, // 离线
DISABLED = 3 // 已禁用
OFFLINE = 2 // 离线
}
// IoT 模拟设备上报数据 Request VO
@ -62,7 +61,7 @@ export interface IotDeviceSimulationReportReqVO {
id: number // 设备编号
type: string // 消息类型
identifier: string // 标识符
data: object // 请求参数
data: any // 请求参数
}
// 设备 API

View File

@ -142,10 +142,10 @@
<el-tab-pane label="状态变更" name="status">
<ContentWrap>
<div class="flex gap-4">
<el-button type="primary" @click="handleDeviceState('online')">
<el-button type="primary" @click="handleDeviceState(DeviceStateEnum.ONLINE)">
设备上线
</el-button>
<el-button type="primary" @click="handleDeviceState('offline')">
<el-button type="danger" @click="handleDeviceState(DeviceStateEnum.OFFLINE)">
设备下线
</el-button>
</div>
@ -210,7 +210,7 @@
<script setup lang="ts">
import { ProductVO } from '@/api/iot/product/product'
import { ThingModelApi, SimulatorData } from '@/api/iot/thingmodel'
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
import { DeviceApi, DeviceStateEnum, DeviceVO } from '@/api/iot/device/device'
import DeviceDetailsLog from './DeviceDetailsLog.vue'
import {
DataSpecsDataType,
@ -372,26 +372,20 @@ const handlePropertyReport = async () => {
// }
// }
// //
// const handleDeviceState = async (state: 'online' | 'offline') => {
// const reportData: ReportData = {
// productKey: props.product.productKey,
// deviceKey: props.device.deviceKey,
// type: 'status',
// subType: state,
// reportTime: new Date().toISOString(),
// content: JSON.stringify({ status: state }) // JSON
// }
// try {
// // TODO: API
// console.log(':', reportData)
// console.log('reportData.content111111111', reportData.content)
// message.success(`${state === 'online' ? '线' : '线'}`)
// } catch (error) {
// message.error(`${state === 'online' ? '线' : '线'}`)
// }
// }
/** 处理设备状态 */
const handleDeviceState = async (state: number) => {
try {
await DeviceApi.simulationReportDevice({
id: props.device.id,
type: 'state',
identifier: 'report',
data: state
})
message.success(`设备${state === DeviceStateEnum.ONLINE ? '上线' : '下线'}成功`)
} catch (error) {
message.error(`设备${state === DeviceStateEnum.ONLINE ? '上线' : '下线'}失败`)
}
}
//
const handlePropertyGet = async () => {

View File

@ -161,7 +161,7 @@
<div
class="absolute top-0 left-0 right-0 h-[50px] pointer-events-none"
:class="[
item.state === DeviceStatusEnum.ONLINE
item.state === DeviceStateEnum.ONLINE
? 'bg-gradient-to-b from-[#eefaff] to-transparent'
: 'bg-gradient-to-b from-[#fff1f1] to-transparent'
]"
@ -179,7 +179,7 @@
<div
class="w-1 h-1 rounded-full mr-1.5"
:class="
item.state === DeviceStatusEnum.ONLINE
item.state === DeviceStateEnum.ONLINE
? 'bg-[var(--el-color-success)]'
: 'bg-[var(--el-color-danger)]'
"
@ -187,7 +187,7 @@
</div>
<el-text
class="!text-xs font-bold"
:type="item.state === DeviceStatusEnum.ONLINE ? 'success' : 'danger'"
:type="item.state === DeviceStateEnum.ONLINE ? 'success' : 'danger'"
>
{{ getDictLabel(DICT_TYPE.IOT_DEVICE_STATE, item.state) }}
</el-text>
@ -369,7 +369,7 @@
<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions, getDictLabel } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { DeviceApi, DeviceVO, DeviceStatusEnum } from '@/api/iot/device/device'
import { DeviceApi, DeviceVO, DeviceStateEnum } from '@/api/iot/device/device'
import DeviceForm from './DeviceForm.vue'
import { ProductApi, ProductVO } from '@/api/iot/product/product'
import { DeviceGroupApi, DeviceGroupVO } from '@/api/iot/device/group'