Commit a0b21cb2a10bc290dc121df67421dc4a899ef749
Merge branch 'fix/task-center-gen-modbus' into 'main_dev'
fix: 多个线圈寄存器值修改为必填 See merge request yunteng/thingskit-front!912
Showing
2 changed files
with
9 additions
and
3 deletions
@@ -2,18 +2,19 @@ | @@ -2,18 +2,19 @@ | ||
2 | import { Button, Spin } from 'ant-design-vue'; | 2 | import { Button, Spin } from 'ant-design-vue'; |
3 | import { BasicForm, useForm } from '/@/components/Form'; | 3 | import { BasicForm, useForm } from '/@/components/Form'; |
4 | import { BasicModal, useModal } from '/@/components/Modal'; | 4 | import { BasicModal, useModal } from '/@/components/Modal'; |
5 | - import { formSchemas } from './config'; | 5 | + import { formSchemas, FormFieldsEnum } from './config'; |
6 | import { ref } from 'vue'; | 6 | import { ref } from 'vue'; |
7 | import { unref } from 'vue'; | 7 | import { unref } from 'vue'; |
8 | import { composeModbusModalData } from './util'; | 8 | import { composeModbusModalData } from './util'; |
9 | import { ModbusCommandValueType } from './type'; | 9 | import { ModbusCommandValueType } from './type'; |
10 | import { genModbusCommand } from '/@/api/task'; | 10 | import { genModbusCommand } from '/@/api/task'; |
11 | + import { isNullOrUnDef } from '/@/utils/is'; | ||
11 | 12 | ||
12 | const emit = defineEmits(['update:value']); | 13 | const emit = defineEmits(['update:value']); |
13 | 14 | ||
14 | const [registerModal] = useModal(); | 15 | const [registerModal] = useModal(); |
15 | 16 | ||
16 | - const [registerForm, { getFieldsValue }] = useForm({ | 17 | + const [registerForm, { getFieldsValue, validate }] = useForm({ |
17 | schemas: formSchemas, | 18 | schemas: formSchemas, |
18 | showActionButtonGroup: false, | 19 | showActionButtonGroup: false, |
19 | rowProps: { gutter: 10 }, | 20 | rowProps: { gutter: 10 }, |
@@ -25,8 +26,12 @@ | @@ -25,8 +26,12 @@ | ||
25 | const loading = ref(false); | 26 | const loading = ref(false); |
26 | const handleGetValue = async () => { | 27 | const handleGetValue = async () => { |
27 | try { | 28 | try { |
29 | + await validate(); | ||
28 | const value = getFieldsValue(); | 30 | const value = getFieldsValue(); |
29 | const record = composeModbusModalData(value as ModbusCommandValueType); | 31 | const record = composeModbusModalData(value as ModbusCommandValueType); |
32 | + | ||
33 | + if (record[FormFieldsEnum.REGISTER_VALUES]?.some((item) => isNullOrUnDef(item))) return; | ||
34 | + | ||
30 | loading.value = true; | 35 | loading.value = true; |
31 | const result = await genModbusCommand(record); | 36 | const result = await genModbusCommand(record); |
32 | commandValue.value = result; | 37 | commandValue.value = result; |
@@ -46,7 +51,7 @@ | @@ -46,7 +51,7 @@ | ||
46 | return arr.reduce((prev, next) => `${prev} ${next.join('')}`, ''); | 51 | return arr.reduce((prev, next) => `${prev} ${next.join('')}`, ''); |
47 | }; | 52 | }; |
48 | 53 | ||
49 | - const handleOk = () => { | 54 | + const handleOk = async () => { |
50 | emit('update:value', unref(commandValue)); | 55 | emit('update:value', unref(commandValue)); |
51 | }; | 56 | }; |
52 | </script> | 57 | </script> |
@@ -212,6 +212,7 @@ export const formSchemas: FormSchema[] = [ | @@ -212,6 +212,7 @@ export const formSchemas: FormSchema[] = [ | ||
212 | showTotalControl: false, | 212 | showTotalControl: false, |
213 | itemProps: () => { | 213 | itemProps: () => { |
214 | return { | 214 | return { |
215 | + required: true, | ||
215 | valueField: 'value', | 216 | valueField: 'value', |
216 | changeEvent: 'update:value', | 217 | changeEvent: 'update:value', |
217 | } as FormSchema; | 218 | } as FormSchema; |