Commit e0b0350165d6710ebc764e6edd44fc62909b214c

Authored by ww
1 parent 0c9006bd

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

1 <script lang="ts" setup> 1 <script lang="ts" setup>
2 import { Button } from 'ant-design-vue'; 2 import { Button } from 'ant-design-vue';
3 import { nextTick, ref, watch } from 'vue'; 3 import { nextTick, ref, watch } from 'vue';
  4 + import { findDictItemByCode } from '/@/api/system/dict';
4 import { BasicForm, useForm } from '/@/components/Form'; 5 import { BasicForm, useForm } from '/@/components/Form';
5 import { BasicModal } from '/@/components/Modal'; 6 import { BasicModal } from '/@/components/Modal';
6 - 7 + import { DictEnum } from '/@/enums/dictEnum';
  8 + import { PlusCircleOutlined } from '@ant-design/icons-vue';
7 const show = ref(false); 9 const show = ref(false);
8 10
9 const props = withDefaults( 11 const props = withDefaults(
@@ -18,28 +20,48 @@ @@ -18,28 +20,48 @@
18 20
19 const emit = defineEmits(['update:value']); 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 const handleClick = async () => { 55 const handleClick = async () => {
36 show.value = true; 56 show.value = true;
37 await nextTick(); 57 await nextTick();
  58 + resetFields();
38 setProps({ disabled: props.disabled }); 59 setProps({ disabled: props.disabled });
39 setFieldsValue(props.value); 60 setFieldsValue(props.value);
40 }; 61 };
41 62
42 - const handleSubmit = () => { 63 + const handleSubmit = async () => {
  64 + await validate();
43 const value = getFieldsValue(); 65 const value = getFieldsValue();
44 emit('update:value', value); 66 emit('update:value', value);
45 show.value = false; 67 show.value = false;
@@ -55,9 +77,17 @@ @@ -55,9 +77,17 @@
55 77
56 <template> 78 <template>
57 <section> 79 <section>
58 - <Button type="link" @click="handleClick">新增扩展描述</Button> 80 + <Button type="link" @click="handleClick"><PlusCircleOutlined />新增扩展描述</Button>
59 <BasicModal title="扩展描述" v-model:visible="show" @ok="handleSubmit"> 81 <BasicModal title="扩展描述" v-model:visible="show" @ok="handleSubmit">
60 - <BasicForm @register="registerForm" /> 82 + <BasicForm class="extension-form" @register="registerForm" />
61 </BasicModal> 83 </BasicModal>
62 </section> 84 </section>
63 </template> 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,7 +286,8 @@ export const formSchemas = (hasStructForm: boolean, isTcp = false): FormSchema[]
286 message: '请输入扩展描述', 286 message: '请输入扩展描述',
287 required: true, 287 required: true,
288 validator(_rule, value, _callback) { 288 validator(_rule, value, _callback) {
289 - if (!value?.['registerAddress']) return Promise.reject('请输入寄存器地址'); 289 + if (isNullOrUnDef(value?.['registerAddress']))
  290 + return Promise.reject('请输入寄存器地址');
290 return Promise.resolve(); 291 return Promise.resolve();
291 }, 292 },
292 }, 293 },
@@ -17,4 +17,6 @@ export enum DictEnum { @@ -17,4 +17,6 @@ export enum DictEnum {
17 DISABLED_TENANT_AUTH = 'disabled_tenant_auth', 17 DISABLED_TENANT_AUTH = 'disabled_tenant_auth',
18 // 客户禁用的权限 18 // 客户禁用的权限
19 DISABLE_CUSTOMER_AUTH = 'disabled_customer_auth', 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,7 +83,7 @@ export const usePlatform = async () => {
83 }; 83 };
84 84
85 const setTitle = () => { 85 const setTitle = () => {
86 - document.title = platformInfo.name; 86 + document.title = platformInfo.name || '';
87 }; 87 };
88 88
89 const bootstrap = () => { 89 const bootstrap = () => {
@@ -41,7 +41,7 @@ export const composeModbusModalData = (record: ModbusCommandValueType): GenModbu @@ -41,7 +41,7 @@ export const composeModbusModalData = (record: ModbusCommandValueType): GenModbu
41 return { 41 return {
42 crc, 42 crc,
43 deviceCode, 43 deviceCode,
44 - method: Number(method).toString(16).padStart(2, '0'), 44 + method: Number(method).toString(16).padStart(2, '0').toUpperCase(),
45 registerAddr, 45 registerAddr,
46 ...registerInfo(record), 46 ...registerInfo(record),
47 }; 47 };