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

View File

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

View File

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