Commit 995a69bbac4b808d7d176139f1ed8656fb8de84a

Authored by ww
1 parent 8eb71406

perf: 优化物模型绑定,输入参数验证,拓展描述符

1 1 <script lang="ts" setup>
2 2 import { Button } from 'ant-design-vue';
3   - import { nextTick, ref, unref, watch } from 'vue';
  3 + import { nextTick, ref, watch } from 'vue';
4 4 import { BasicForm, useForm } from '/@/components/Form';
5 5 import { BasicModal } from '/@/components/Modal';
6 6 import { PlusCircleOutlined } from '@ant-design/icons-vue';
... ... @@ -19,8 +19,6 @@
19 19 }
20 20 );
21 21
22   - const dataType = ref(props.dataType); //获取数据类型
23   -
24 22 const emit = defineEmits(['update:value']);
25 23
26 24 const [
... ... @@ -46,15 +44,17 @@
46 44 show.value = false;
47 45 };
48 46
49   - watch(
50   - () => props.dataType,
51   - (value) => {
52   - dataType.value = value;
  47 + watch(show, async (value) => {
  48 + if (value) {
  49 + await nextTick();
53 50 updateSchema([
54   - { field: FormFieldsEnum.ZOOM_FACTOR, ifShow: unref(dataType) == 'BOOL' ? false : true },
  51 + {
  52 + field: FormFieldsEnum.ZOOM_FACTOR,
  53 + ifShow: props.dataType == DataTypeEnum.IS_BOOL ? false : true,
  54 + },
55 55 ]);
56 56 }
57   - );
  57 + });
58 58
59 59 watch(
60 60 () => props.value,
... ...
... ... @@ -89,7 +89,9 @@
89 89 functionJson: {
90 90 inputData,
91 91 outputData,
92   - ...(serviceCommand ? { inputData: [{ serviceCommand }] } : {}),
  92 + ...(serviceCommand
  93 + ? { inputData: [{ serviceCommand: serviceCommand.replaceAll(/\s/g, '').toUpperCase() }] }
  94 + : {}),
93 95 },
94 96 } as ModelOfMatterParams;
95 97
... ...
... ... @@ -117,7 +117,18 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => {
117 117 field: FormField.SERVICE_COMMAND,
118 118 label: '输入参数',
119 119 component: 'Input',
120   - rules: [{ message: '输入参数为必填项', required: true }],
  120 + rules: [
  121 + { message: '输入参数为必填项', required: true },
  122 + {
  123 + message: '请输入ASCII或HEX服务命令(0~9/A~F)',
  124 + validator(_rule, value, _callback) {
  125 + const reg = /^[\s0-9a-fA-F]+$/;
  126 +
  127 + if (reg.test(value)) return Promise.resolve();
  128 + return Promise.reject('请输入ASCII或HEX服务命令(0~9/A~F)');
  129 + },
  130 + },
  131 + ],
121 132 ifShow: tcpDeviceFlag,
122 133 componentProps: {
123 134 placeholder: '请输入ASCII或HEX服务命令',
... ...
... ... @@ -354,7 +354,6 @@ export const useDataFetch = (
354 354 props: { config: ComponentPropsConfigType },
355 355 updateFn: DataFetchUpdateFn
356 356 ) => {
357   - console.log(props, 'props');
358 357 const getBindAttribute = computed(() => {
359 358 const { config } = props;
360 359 const { option } = config as ComponentPropsConfigType<Recordable, DataSource>;
... ...