Commit e0b0350165d6710ebc764e6edd44fc62909b214c

Authored by ww
1 parent 0c9006bd

fix: 产品创建时tcp设备新增字段扩展描述

1 1 <script lang="ts" setup>
2 2 import { Button } from 'ant-design-vue';
3 3 import { nextTick, ref, watch } from 'vue';
  4 + import { findDictItemByCode } from '/@/api/system/dict';
4 5 import { BasicForm, useForm } from '/@/components/Form';
5 6 import { BasicModal } from '/@/components/Modal';
6   -
  7 + import { DictEnum } from '/@/enums/dictEnum';
  8 + import { PlusCircleOutlined } from '@ant-design/icons-vue';
7 9 const show = ref(false);
8 10
9 11 const props = withDefaults(
... ... @@ -18,28 +20,48 @@
18 20
19 21 const emit = defineEmits(['update:value']);
20 22
21   - const [registerForm, { setFieldsValue, getFieldsValue, setProps }] = useForm({
22   - schemas: [
23   - {
24   - field: 'registerAddress',
25   - component: 'Input',
26   - label: '寄存器地址',
27   - componentProps: {
28   - placeholder: '请输入寄存器地址',
  23 + const [registerForm, { setFieldsValue, getFieldsValue, setProps, validate, resetFields }] =
  24 + useForm({
  25 + schemas: [
  26 + {
  27 + field: 'registerAddress',
  28 + component: 'InputNumber',
  29 + label: '寄存器地址',
  30 + rules: [{ message: '请输入寄存器地址', required: true }],
  31 + componentProps: {
  32 + max: parseInt('ffff', 16),
  33 + placeholder: '请输入寄存器地址',
  34 + },
  35 + },
  36 + {
  37 + field: 'dataType',
  38 + component: 'ApiSelect',
  39 + label: '数据格式',
  40 + rules: [{ message: '请选择数据格式', required: true }],
  41 + componentProps: {
  42 + api: findDictItemByCode,
  43 + params: {
  44 + dictCode: DictEnum.REGISTER_DATA_FORMAT,
  45 + },
  46 + labelField: 'itemText',
  47 + valueField: 'itemValue',
  48 + placeholder: '请选择数据格式',
  49 + },
29 50 },
30   - },
31   - ],
32   - showActionButtonGroup: false,
33   - });
  51 + ],
  52 + showActionButtonGroup: false,
  53 + });
34 54
35 55 const handleClick = async () => {
36 56 show.value = true;
37 57 await nextTick();
  58 + resetFields();
38 59 setProps({ disabled: props.disabled });
39 60 setFieldsValue(props.value);
40 61 };
41 62
42   - const handleSubmit = () => {
  63 + const handleSubmit = async () => {
  64 + await validate();
43 65 const value = getFieldsValue();
44 66 emit('update:value', value);
45 67 show.value = false;
... ... @@ -55,9 +77,17 @@
55 77
56 78 <template>
57 79 <section>
58   - <Button type="link" @click="handleClick">新增扩展描述</Button>
  80 + <Button type="link" @click="handleClick"><PlusCircleOutlined />新增扩展描述</Button>
59 81 <BasicModal title="扩展描述" v-model:visible="show" @ok="handleSubmit">
60   - <BasicForm @register="registerForm" />
  82 + <BasicForm class="extension-form" @register="registerForm" />
61 83 </BasicModal>
62 84 </section>
63 85 </template>
  86 +
  87 +<style lang="less" scoped>
  88 + .extension-form {
  89 + :deep(.ant-input-number) {
  90 + width: 100%;
  91 + }
  92 + }
  93 +</style>
... ...
... ... @@ -286,7 +286,8 @@ export const formSchemas = (hasStructForm: boolean, isTcp = false): FormSchema[]
286 286 message: '请输入扩展描述',
287 287 required: true,
288 288 validator(_rule, value, _callback) {
289   - if (!value?.['registerAddress']) return Promise.reject('请输入寄存器地址');
  289 + if (isNullOrUnDef(value?.['registerAddress']))
  290 + return Promise.reject('请输入寄存器地址');
290 291 return Promise.resolve();
291 292 },
292 293 },
... ...
... ... @@ -17,4 +17,6 @@ export enum DictEnum {
17 17 DISABLED_TENANT_AUTH = 'disabled_tenant_auth',
18 18 // 客户禁用的权限
19 19 DISABLE_CUSTOMER_AUTH = 'disabled_customer_auth',
  20 + // 寄存器数据格式
  21 + REGISTER_DATA_FORMAT = 'register_data_format',
20 22 }
... ...
... ... @@ -83,7 +83,7 @@ export const usePlatform = async () => {
83 83 };
84 84
85 85 const setTitle = () => {
86   - document.title = platformInfo.name;
  86 + document.title = platformInfo.name || '';
87 87 };
88 88
89 89 const bootstrap = () => {
... ...
... ... @@ -41,7 +41,7 @@ export const composeModbusModalData = (record: ModbusCommandValueType): GenModbu
41 41 return {
42 42 crc,
43 43 deviceCode,
44   - method: Number(method).toString(16).padStart(2, '0'),
  44 + method: Number(method).toString(16).padStart(2, '0').toUpperCase(),
45 45 registerAddr,
46 46 ...registerInfo(record),
47 47 };
... ...