From 63743b692922e5a1319303fb015636a0c429ea73 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 14 Feb 2026 11:02:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(iot)=EF=BC=9A=E5=A2=9E=E5=8A=A0=20modbus?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=20100%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/modules/modbus-config-form.vue | 41 +++-- .../device/detail/modules/modbus-config.vue | 17 +- .../detail/modules/modbus-point-form.vue | 155 ++++++------------ 3 files changed, 75 insertions(+), 138 deletions(-) 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 index 56b05adbb..fb792d4e7 100644 --- 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 @@ -13,6 +13,7 @@ import { message } from 'ant-design-vue'; import { useVbenForm, z } from '#/adapter/form'; import { saveModbusConfig } from '#/api/iot/device/modbus/config'; import { ProtocolTypeEnum } from '#/api/iot/product/product'; +import { $t } from '#/locales'; import { ModbusFrameFormatEnum, ModbusModeEnum, @@ -78,6 +79,7 @@ const [Form, formApi] = useVbenForm({ show: () => isClient.value, // Client 模式专有字段:端口 }, rules: z.number().min(1).max(65_535).optional(), + defaultValue: 502, }, { fieldName: 'slaveId', @@ -89,6 +91,7 @@ const [Form, formApi] = useVbenForm({ max: 247, }, rules: z.number().min(1, '请输入从站地址').max(247), + defaultValue: 1, }, { fieldName: 'timeout', @@ -104,6 +107,7 @@ const [Form, formApi] = useVbenForm({ show: () => isClient.value, // Client 模式专有字段:连接超时 }, rules: z.number().min(1000).optional(), + defaultValue: 3000, }, { fieldName: 'retryInterval', @@ -119,6 +123,7 @@ const [Form, formApi] = useVbenForm({ show: () => isClient.value, // Client 模式专有字段:重试间隔 }, rules: z.number().min(1000).optional(), + defaultValue: 10_000, }, { fieldName: 'mode', @@ -132,6 +137,7 @@ const [Form, formApi] = useVbenForm({ show: () => isServer.value, // Server 模式专有字段:工作模式 }, rules: 'required', + defaultValue: ModbusModeEnum.POLLING, }, { fieldName: 'frameFormat', @@ -145,6 +151,7 @@ const [Form, formApi] = useVbenForm({ show: () => isServer.value, // Server 模式专有字段:帧格式 }, rules: 'required', + defaultValue: ModbusFrameFormatEnum.MODBUS_TCP, }, { fieldName: 'status', @@ -167,16 +174,17 @@ const [Modal, modalApi] = useVbenModal({ if (!valid) { return; } - // TODO @AI:这里的处理,可以参考 /Users/yunai/Java/yudao-ui-admin-vben-v5/apps/web-antd/src/views/system/user/modules/form.vue 的注释风格; modalApi.lock(); + // 提交表单 const data = (await formApi.getValues()) as IotDeviceModbusConfigApi.ModbusConfig; try { data.deviceId = deviceId.value; await saveModbusConfig(data); - message.success('保存成功'); + // 关闭并提示 await modalApi.close(); emit('success'); + message.success($t('ui.actionMessage.operationSuccess')); } finally { modalApi.unlock(); } @@ -186,34 +194,23 @@ const [Modal, modalApi] = useVbenModal({ formData.value = undefined; return; } + // 加载数据 const data = modalApi.getData<{ config?: IotDeviceModbusConfigApi.ModbusConfig; deviceId: number; protocolType: string; }>(); - if (!data) return; - - // TODO @AI:这里的处理,可以参考 /Users/yunai/Java/yudao-ui-admin-vben-v5/apps/web-antd/src/views/system/user/modules/form.vue 的注释风格; + if (!data) { + return; + } deviceId.value = data.deviceId; protocolType.value = data.protocolType; - - if (data.config && data.config.id) { - // 编辑模式:加载已有配置 - formData.value = { ...data.config }; - await formApi.setValues(formData.value); - } else { - // 新增模式:设置默认值 - await formApi.setValues({ - ip: '', - port: 502, - slaveId: 1, - timeout: 3000, - retryInterval: 10_000, - mode: ModbusModeEnum.POLLING, - frameFormat: ModbusFrameFormatEnum.MODBUS_TCP, - status: 0, - }); + if (!data.config) { + return; } + // 设置到 values + formData.value = { ...data.config }; + await formApi.setValues(formData.value); }, }); 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 index 0b4648302..e0d366027 100644 --- 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 @@ -13,7 +13,7 @@ import { computed, h, onMounted, ref } from 'vue'; import { confirm, useVbenModal } from '@vben/common-ui'; import { DICT_TYPE } from '@vben/constants'; -import { Button, message, Tag } from 'ant-design-vue'; +import { Button, message } from 'ant-design-vue'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { getModbusConfig } from '#/api/iot/device/modbus/config'; @@ -180,7 +180,7 @@ function usePointColumns(): VxeTableGridOptions['columns'] { field: 'identifier', title: '标识符', minWidth: 100, - slots: { default: 'identifier' }, + cellRender: { name: 'CellTag', props: { color: 'blue' } }, }, { field: 'functionCode', @@ -199,7 +199,7 @@ function usePointColumns(): VxeTableGridOptions['columns'] { field: 'rawDataType', title: '数据类型', minWidth: 90, - slots: { default: 'rawDataType' }, + cellRender: { name: 'CellTag' }, }, { field: 'byteOrder', title: '字节序', minWidth: 80 }, { field: 'scale', title: '缩放因子', minWidth: 80 }, @@ -314,8 +314,7 @@ onMounted(async () => { - - + - - - -