From 8bf286fda0ddf78e0c9a0e70efe9ebeba4b0c818 Mon Sep 17 00:00:00 2001 From: haohao <1036606149@qq.com> Date: Fri, 16 Jan 2026 17:38:02 +0800 Subject: [PATCH 1/6] =?UTF-8?q?refactor:=E3=80=90antd=E3=80=91=E3=80=90iot?= =?UTF-8?q?=E3=80=91=E5=B0=86=20DeviceSaveReqVO=20=E5=92=8C=20DeviceRespVO?= =?UTF-8?q?=20=E5=90=88=E5=B9=B6=E5=88=B0=20Device=EF=BC=8C=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E8=AE=BE=E5=A4=87=20API=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/iot/device/device/index.ts | 79 ++++-------- .../views/iot/device/device/detail/index.vue | 2 +- .../device/device/detail/modules/config.vue | 4 +- .../device/device/detail/modules/header.vue | 4 +- .../iot/device/device/detail/modules/info.vue | 2 +- .../device/detail/modules/simulator.vue | 2 +- .../device/detail/modules/sub-device.vue | 115 +++++++----------- .../src/views/iot/device/device/index.vue | 16 +-- .../iot/device/device/modules/card-view.vue | 12 +- .../views/iot/device/device/modules/form.vue | 45 ++++--- .../iot/ota/modules/task/ota-task-form.vue | 4 +- 11 files changed, 114 insertions(+), 171 deletions(-) diff --git a/apps/web-antd/src/api/iot/device/device/index.ts b/apps/web-antd/src/api/iot/device/device/index.ts index 5e7581274..8d615a5d0 100644 --- a/apps/web-antd/src/api/iot/device/device/index.ts +++ b/apps/web-antd/src/api/iot/device/device/index.ts @@ -3,49 +3,14 @@ import type { PageParam, PageResult } from '@vben/request'; import { requestClient } from '#/api/request'; export namespace IotDeviceApi { - /** 设备新增/修改 Request VO */ - // TODO @haohao:可以降低一些 VO 哈:DeviceSaveReqVO、DeviceRespVO 合并成 Device 就好,类似别的模块 - export interface DeviceSaveReqVO { + /** 设备 */ + export interface Device { id?: number; // 设备编号 deviceName: string; // 设备名称 nickname?: string; // 备注名称 serialNumber?: string; // 设备序列号 picUrl?: string; // 设备图片 groupIds?: number[]; // 设备分组编号数组 - productId: number; // 产品编号(必填) - gatewayId?: number; // 网关设备 ID - config?: string; // 设备配置 - locationType: number; // 定位类型(必填) - latitude?: number; // 设备位置的纬度 - longitude?: number; // 设备位置的经度 - } - - /** 设备更新分组 Request VO */ - export interface DeviceUpdateGroupReqVO { - ids: number[]; // 设备编号列表(必填) - groupIds: number[]; // 分组编号列表(必填) - } - - /** 设备分页 Request VO */ - // TODO @haohao:可以不用 DevicePageReqVO,直接 PageParam 即可,简洁一点。这里的强类型,收益不大; - export interface DevicePageReqVO extends PageParam { - deviceName?: string; // 设备名称 - nickname?: string; // 备注名称 - productId?: number; // 产品编号 - deviceType?: number; // 设备类型 - status?: number; // 设备状态 - groupId?: number; // 设备分组编号 - gatewayId?: number; // 网关设备 ID - } - - /** 设备 Response VO */ - export interface DeviceRespVO { - id: number; // 设备编号 - deviceName: string; // 设备名称 - nickname?: string; // 设备备注名称 - serialNumber?: string; // 设备序列号 - picUrl?: string; // 设备图片 - groupIds?: number[]; // 设备分组编号数组 productId: number; // 产品编号 productKey?: string; // 产品标识 deviceType?: number; // 设备类型 @@ -57,12 +22,18 @@ export namespace IotDeviceApi { deviceSecret?: string; // 设备密钥,用于设备认证 authType?: string; // 认证类型(如一机一密、动态注册) config?: string; // 设备配置 - locationType?: number; // 定位方式 + locationType?: number; // 定位类型 latitude?: number; // 设备位置的纬度 longitude?: number; // 设备位置的经度 createTime?: Date; // 创建时间 } + /** 设备更新分组 Request VO */ + export interface DeviceUpdateGroupReqVO { + ids: number[]; // 设备编号列表(必填) + groupIds: number[]; // 分组编号列表(必填) + } + /** 设备认证信息 Response VO */ export interface DeviceAuthInfoRespVO { clientId: string; // 客户端 ID @@ -104,8 +75,8 @@ export namespace IotDeviceApi { } /** 查询设备分页 */ -export function getDevicePage(params: IotDeviceApi.DevicePageReqVO) { - return requestClient.get>( +export function getDevicePage(params: PageParam) { + return requestClient.get>( '/iot/device/page', { params }, ); @@ -113,18 +84,16 @@ export function getDevicePage(params: IotDeviceApi.DevicePageReqVO) { /** 查询设备详情 */ export function getDevice(id: number) { - return requestClient.get( - `/iot/device/get?id=${id}`, - ); + return requestClient.get(`/iot/device/get?id=${id}`); } /** 新增设备 */ -export function createDevice(data: IotDeviceApi.DeviceSaveReqVO) { +export function createDevice(data: IotDeviceApi.Device) { return requestClient.post('/iot/device/create', data); } /** 修改设备 */ -export function updateDevice(data: IotDeviceApi.DeviceSaveReqVO) { +export function updateDevice(data: IotDeviceApi.Device) { return requestClient.put('/iot/device/update', data); } @@ -146,7 +115,7 @@ export function deleteDeviceList(ids: number[]) { } /** 导出设备 */ -export function exportDeviceExcel(params: IotDeviceApi.DevicePageReqVO) { +export function exportDeviceExcel(params: PageParam) { return requestClient.download('/iot/device/export-excel', { params }); } @@ -157,22 +126,16 @@ export function getDeviceCount(productId: number) { /** 获取设备的精简信息列表 */ export function getSimpleDeviceList(deviceType?: number, productId?: number) { - return requestClient.get( - '/iot/device/simple-list', - { - params: { deviceType, productId }, - }, - ); + return requestClient.get('/iot/device/simple-list', { + params: { deviceType, productId }, + }); } /** 根据产品编号,获取设备的精简信息列表 */ export function getDeviceListByProductId(productId: number) { - return requestClient.get( - '/iot/device/simple-list', - { - params: { productId }, - }, - ); + return requestClient.get('/iot/device/simple-list', { + params: { productId }, + }); } /** 获取导入模板 */ diff --git a/apps/web-antd/src/views/iot/device/device/detail/index.vue b/apps/web-antd/src/views/iot/device/device/detail/index.vue index 4ba957410..4b549a363 100644 --- a/apps/web-antd/src/views/iot/device/device/detail/index.vue +++ b/apps/web-antd/src/views/iot/device/device/detail/index.vue @@ -31,7 +31,7 @@ const router = useRouter(); const id = Number(route.params.id); const loading = ref(true); const product = ref({} as IotProductApi.Product); -const device = ref({} as IotDeviceApi.DeviceRespVO); +const device = ref({} as IotDeviceApi.Device); const activeTab = ref('info'); const thingModelList = ref([]); diff --git a/apps/web-antd/src/views/iot/device/device/detail/modules/config.vue b/apps/web-antd/src/views/iot/device/device/detail/modules/config.vue index 72ad3a463..072a1ff77 100644 --- a/apps/web-antd/src/views/iot/device/device/detail/modules/config.vue +++ b/apps/web-antd/src/views/iot/device/device/detail/modules/config.vue @@ -12,7 +12,7 @@ import { IotDeviceMessageMethodEnum } from '#/views/iot/utils/constants'; defineOptions({ name: 'DeviceDetailConfig' }); const props = defineProps<{ - device: IotDeviceApi.DeviceRespVO; + device: IotDeviceApi.Device; }>(); const emit = defineEmits<{ @@ -114,7 +114,7 @@ async function updateDeviceConfig() { await updateDevice({ id: props.device.id, config: JSON.stringify(config.value), - } as IotDeviceApi.DeviceSaveReqVO); + } as IotDeviceApi.Device); message.success({ content: '更新成功!' }); // 触发 success 事件 emit('success'); diff --git a/apps/web-antd/src/views/iot/device/device/detail/modules/header.vue b/apps/web-antd/src/views/iot/device/device/detail/modules/header.vue index 1cc42b791..8a739a180 100644 --- a/apps/web-antd/src/views/iot/device/device/detail/modules/header.vue +++ b/apps/web-antd/src/views/iot/device/device/detail/modules/header.vue @@ -12,7 +12,7 @@ import DeviceForm from '../../modules/form.vue'; interface Props { product: IotProductApi.Product; - device: IotDeviceApi.DeviceRespVO; + device: IotDeviceApi.Device; loading?: boolean; } @@ -50,7 +50,7 @@ function goToProductDetail(productId: number | undefined) { } /** 打开编辑表单 */ -function openEditForm(row: IotDeviceApi.DeviceRespVO) { +function openEditForm(row: IotDeviceApi.Device) { formModalApi.setData(row).open(); } diff --git a/apps/web-antd/src/views/iot/device/device/detail/modules/info.vue b/apps/web-antd/src/views/iot/device/device/detail/modules/info.vue index d1f5d66b7..634daddf1 100644 --- a/apps/web-antd/src/views/iot/device/device/detail/modules/info.vue +++ b/apps/web-antd/src/views/iot/device/device/detail/modules/info.vue @@ -24,7 +24,7 @@ import { getDeviceAuthInfo } from '#/api/iot/device/device'; import { DictTag } from '#/components/dict-tag'; interface Props { - device: IotDeviceApi.DeviceRespVO; + device: IotDeviceApi.Device; product: IotProductApi.Product; } diff --git a/apps/web-antd/src/views/iot/device/device/detail/modules/simulator.vue b/apps/web-antd/src/views/iot/device/device/detail/modules/simulator.vue index 67bced3b7..ea9c97bb7 100644 --- a/apps/web-antd/src/views/iot/device/device/detail/modules/simulator.vue +++ b/apps/web-antd/src/views/iot/device/device/detail/modules/simulator.vue @@ -34,7 +34,7 @@ import DataDefinition from '../../../../thingmodel/modules/components/data-defin import DeviceDetailsMessage from './message.vue'; const props = defineProps<{ - device: IotDeviceApi.DeviceRespVO; + device: IotDeviceApi.Device; product: IotProductApi.Product; thingModelList: ThingModelData[]; }>(); diff --git a/apps/web-antd/src/views/iot/device/device/detail/modules/sub-device.vue b/apps/web-antd/src/views/iot/device/device/detail/modules/sub-device.vue index 1d0f7c0ab..7ad04ae89 100644 --- a/apps/web-antd/src/views/iot/device/device/detail/modules/sub-device.vue +++ b/apps/web-antd/src/views/iot/device/device/detail/modules/sub-device.vue @@ -1,17 +1,17 @@