From 9daa0e7fd34cac86f1b246f4655312a0450b1d13 Mon Sep 17 00:00:00 2001 From: lzh Date: Fri, 17 Apr 2026 10:02:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=EF=BC=9Aiot=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=90=8C=E6=AD=A5=E8=87=B3=20yudao/master=20=E6=9C=80?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 Modbus 支持:config/point API + 3 个表单/列表组件 - apps/web-antd/src/api/iot/device/modbus/{config,point}/index.ts - apps/web-antd/src/views/iot/device/device/detail/modules/modbus-*.vue - 设备详情页与子设备列表按 upstream 更新对齐 - 产品/数据类型、物模型常量更新 - packages/constants/dict-enum: 新增 IOT_MODBUS_MODE / IOT_MODBUS_FRAME_FORMAT, IOT_CODEC_TYPE 重命名为 IOT_SERIALIZE_TYPE(本地无引用) 对比 yudao/master 范围: git diff 36aa19537..yudao/master -- 'apps/web-antd/src/{views,api}/iot' 类型检查:对 iot 模块净引入 4/净修复 4,均为 upstream 本身的历史问题。 Co-Authored-By: Claude Opus 4.7 (1M context) --- .../src/api/iot/device/modbus/config/index.ts | 30 ++ .../src/api/iot/device/modbus/point/index.ts | 52 +++ .../src/api/iot/product/product/index.ts | 23 +- .../views/iot/device/device/detail/index.vue | 20 +- .../detail/modules/modbus-config-form.vue | 222 +++++++++++ .../device/detail/modules/modbus-config.vue | 359 ++++++++++++++++++ .../detail/modules/modbus-point-form.vue | 314 +++++++++++++++ .../device/detail/modules/sub-device.vue | 11 +- .../src/views/iot/device/device/index.vue | 4 +- .../src/views/iot/product/product/data.ts | 22 +- .../product/product/detail/modules/info.vue | 13 +- .../web-antd/src/views/iot/utils/constants.ts | 134 ++++++- packages/constants/src/dict-enum.ts | 4 +- 13 files changed, 1188 insertions(+), 20 deletions(-) create mode 100644 apps/web-antd/src/api/iot/device/modbus/config/index.ts create mode 100644 apps/web-antd/src/api/iot/device/modbus/point/index.ts create mode 100644 apps/web-antd/src/views/iot/device/device/detail/modules/modbus-config-form.vue create mode 100644 apps/web-antd/src/views/iot/device/device/detail/modules/modbus-config.vue create mode 100644 apps/web-antd/src/views/iot/device/device/detail/modules/modbus-point-form.vue diff --git a/apps/web-antd/src/api/iot/device/modbus/config/index.ts b/apps/web-antd/src/api/iot/device/modbus/config/index.ts new file mode 100644 index 000000000..3ee1e4f10 --- /dev/null +++ b/apps/web-antd/src/api/iot/device/modbus/config/index.ts @@ -0,0 +1,30 @@ +import { requestClient } from '#/api/request'; + +export namespace IotDeviceModbusConfigApi { + /** Modbus 连接配置 VO */ + export interface ModbusConfig { + id?: number; // 主键 + deviceId: number; // 设备编号 + ip: string; // Modbus 服务器 IP 地址 + port: number; // Modbus 服务器端口 + slaveId: number; // 从站地址 + timeout: number; // 连接超时时间,单位:毫秒 + retryInterval: number; // 重试间隔,单位:毫秒 + mode: number; // 模式 + frameFormat: number; // 帧格式 + status: number; // 状态 + } +} + +/** 获取设备的 Modbus 连接配置 */ +export function getModbusConfig(deviceId: number) { + return requestClient.get( + '/iot/device-modbus-config/get', + { params: { deviceId } }, + ); +} + +/** 保存 Modbus 连接配置 */ +export function saveModbusConfig(data: IotDeviceModbusConfigApi.ModbusConfig) { + return requestClient.post('/iot/device-modbus-config/save', data); +} diff --git a/apps/web-antd/src/api/iot/device/modbus/point/index.ts b/apps/web-antd/src/api/iot/device/modbus/point/index.ts new file mode 100644 index 000000000..11b440fae --- /dev/null +++ b/apps/web-antd/src/api/iot/device/modbus/point/index.ts @@ -0,0 +1,52 @@ +import type { PageParam, PageResult } from '@vben/request'; + +import { requestClient } from '#/api/request'; + +export namespace IotDeviceModbusPointApi { + /** Modbus 点位配置 VO */ + export interface ModbusPoint { + id?: number; // 主键 + deviceId: number; // 设备编号 + thingModelId?: number; // 物模型属性编号 + identifier: string; // 属性标识符 + name: string; // 属性名称 + functionCode?: number; // Modbus 功能码 + registerAddress?: number; // 寄存器起始地址 + registerCount?: number; // 寄存器数量 + byteOrder?: string; // 字节序 + rawDataType?: string; // 原始数据类型 + scale: number; // 缩放因子 + pollInterval: number; // 轮询间隔,单位:毫秒 + status: number; // 状态 + } +} + +/** 获取设备的 Modbus 点位分页 */ +export function getModbusPointPage(params: PageParam) { + return requestClient.get>( + '/iot/device-modbus-point/page', + { params }, + ); +} + +/** 获取 Modbus 点位详情 */ +export function getModbusPoint(id: number) { + return requestClient.get( + `/iot/device-modbus-point/get?id=${id}`, + ); +} + +/** 创建 Modbus 点位配置 */ +export function createModbusPoint(data: IotDeviceModbusPointApi.ModbusPoint) { + return requestClient.post('/iot/device-modbus-point/create', data); +} + +/** 更新 Modbus 点位配置 */ +export function updateModbusPoint(data: IotDeviceModbusPointApi.ModbusPoint) { + return requestClient.put('/iot/device-modbus-point/update', data); +} + +/** 删除 Modbus 点位配置 */ +export function deleteModbusPoint(id: number) { + return requestClient.delete(`/iot/device-modbus-point/delete?id=${id}`); +} diff --git a/apps/web-antd/src/api/iot/product/product/index.ts b/apps/web-antd/src/api/iot/product/product/index.ts index 335819dd3..f77255f4d 100644 --- a/apps/web-antd/src/api/iot/product/product/index.ts +++ b/apps/web-antd/src/api/iot/product/product/index.ts @@ -10,7 +10,7 @@ export namespace IotProductApi { productKey?: string; // 产品标识 productSecret?: string; // 产品密钥 protocolId?: number; // 协议编号 - protocolType?: number; // 接入协议类型 + protocolType?: string; // 协议类型 categoryId?: number; // 产品所属品类标识符 categoryName?: string; // 产品所属品类名称 icon?: string; // 产品图标 @@ -19,7 +19,7 @@ export namespace IotProductApi { status?: number; // 产品状态 deviceType?: number; // 设备类型 netType?: number; // 联网方式 - codecType?: string; // 数据格式(编解码器类型) + serializeType?: string; // 序列化类型 dataFormat?: number; // 数据格式 validateType?: number; // 认证方式 registerEnabled?: boolean; // 是否开启动态注册 @@ -28,6 +28,25 @@ export namespace IotProductApi { } } +// IoT 协议类型枚举 +export enum ProtocolTypeEnum { + COAP = 'coap', + EMQX = 'emqx', + HTTP = 'http', + MODBUS_TCP_CLIENT = 'modbus_tcp_client', + MODBUS_TCP_SERVER = 'modbus_tcp_server', + MQTT = 'mqtt', + TCP = 'tcp', + UDP = 'udp', + WEBSOCKET = 'websocket', +} + +// IoT 序列化类型枚举 +export enum SerializeTypeEnum { + BINARY = 'binary', + JSON = 'json', +} + /** 查询产品分页 */ export function getProductPage(params: PageParam) { return requestClient.get>( 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 4b549a363..cbe9319e7 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 @@ -12,13 +12,14 @@ import { DeviceTypeEnum } from '@vben/constants'; import { message, Tabs } from 'ant-design-vue'; import { getDevice } from '#/api/iot/device/device'; -import { getProduct } from '#/api/iot/product/product'; +import { getProduct, ProtocolTypeEnum } from '#/api/iot/product/product'; import { getThingModelListByProductId } from '#/api/iot/thingmodel'; import DeviceDetailConfig from './modules/config.vue'; import DeviceDetailsHeader from './modules/header.vue'; import DeviceDetailsInfo from './modules/info.vue'; import DeviceDetailsMessage from './modules/message.vue'; +import DeviceModbusConfig from './modules/modbus-config.vue'; import DeviceDetailsSimulator from './modules/simulator.vue'; import DeviceDetailsSubDevice from './modules/sub-device.vue'; import DeviceDetailsThingModel from './modules/thing-model.vue'; @@ -141,6 +142,23 @@ onMounted(async () => { @success="() => getDeviceData(id)" /> + + + diff --git a/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-config-form.vue b/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-config-form.vue new file mode 100644 index 000000000..fb792d4e7 --- /dev/null +++ b/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-config-form.vue @@ -0,0 +1,222 @@ + + + + diff --git a/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-config.vue b/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-config.vue new file mode 100644 index 000000000..74f07130f --- /dev/null +++ b/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-config.vue @@ -0,0 +1,359 @@ + + + + diff --git a/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-point-form.vue b/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-point-form.vue new file mode 100644 index 000000000..db5fc0674 --- /dev/null +++ b/apps/web-antd/src/views/iot/device/device/detail/modules/modbus-point-form.vue @@ -0,0 +1,314 @@ + + + + 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 67bb69daa..3c1da17c6 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,5 +1,6 @@