Commit 3742f3caa6d8a2e11add7bd14795598c6bc9c287
1 parent
7b53f85e
perf: data board component info modal add validate
Showing
4 changed files
with
29 additions
and
7 deletions
... | ... | @@ -26,10 +26,6 @@ |
26 | 26 | |
27 | 27 | const { createMessage } = useMessage(); |
28 | 28 | |
29 | - // const componentRecord = reactive<DataBoardLayoutInfo>({ | |
30 | - // ...props.record, | |
31 | - // } as unknown as DataBoardLayoutInfo); | |
32 | - | |
33 | 29 | const dataSource = ref<DataSourceEl[]>([ |
34 | 30 | { id: buildUUID(), componentInfo: props.defaultConfig || {} } as unknown as DataSourceEl, |
35 | 31 | ]); |
... | ... | @@ -49,6 +45,11 @@ |
49 | 45 | } |
50 | 46 | }; |
51 | 47 | |
48 | + const validate = async () => { | |
49 | + await basicMethod.validate(); | |
50 | + await validateDataSourceField(); | |
51 | + }; | |
52 | + | |
52 | 53 | const getAllDataSourceFieldValue = () => { |
53 | 54 | const _dataSource = getDataSourceField(); |
54 | 55 | const basicInfo = basicMethod.getFieldsValue(); |
... | ... | @@ -58,6 +59,16 @@ |
58 | 59 | }; |
59 | 60 | }; |
60 | 61 | |
62 | + const validateDataSourceField = async () => { | |
63 | + const hasExistEl = Object.keys(dataSourceEl).filter((key) => dataSourceEl[key]); | |
64 | + const _dataSource: boolean[] = []; | |
65 | + for (const id of hasExistEl) { | |
66 | + const flag = (await (dataSourceEl[id] as FormActionType).validate()) as boolean; | |
67 | + _dataSource.push(flag); | |
68 | + } | |
69 | + return _dataSource; | |
70 | + }; | |
71 | + | |
61 | 72 | const getDataSourceField = () => { |
62 | 73 | const hasExistEl = Object.keys(dataSourceEl).filter((key) => dataSourceEl[key]); |
63 | 74 | const _dataSource: DataSource[] = []; |
... | ... | @@ -90,6 +101,7 @@ |
90 | 101 | }); |
91 | 102 | await nextTick(); |
92 | 103 | (dataSourceEl[copyRecordId] as FormActionType).setFieldsValue(value); |
104 | + (dataSourceEl[copyRecordId] as FormActionType).clearValidate(); | |
93 | 105 | }; |
94 | 106 | |
95 | 107 | const [registerVisualOptionModal, { openModal }] = useModal(); |
... | ... | @@ -128,6 +140,7 @@ |
128 | 140 | |
129 | 141 | const echoDataSource = () => { |
130 | 142 | basicMethod.setFieldsValue(props.record.record); |
143 | + basicMethod.clearValidate(); | |
131 | 144 | dataSource.value = []; |
132 | 145 | dataSource.value = props.record.record.dataSource.map((item) => { |
133 | 146 | const id = buildUUID(); |
... | ... | @@ -139,6 +152,7 @@ |
139 | 152 | |
140 | 153 | nextTick(() => { |
141 | 154 | (dataSourceEl[id] as FormActionType).setFieldsValue(item); |
155 | + (dataSourceEl[id] as FormActionType).clearValidate(); | |
142 | 156 | }); |
143 | 157 | return { |
144 | 158 | id, |
... | ... | @@ -165,6 +179,7 @@ |
165 | 179 | |
166 | 180 | defineExpose({ |
167 | 181 | getAllDataSourceFieldValue, |
182 | + validate, | |
168 | 183 | }); |
169 | 184 | </script> |
170 | 185 | ... | ... |
... | ... | @@ -44,6 +44,7 @@ |
44 | 44 | |
45 | 45 | const basicConfigurationEl = ref<{ |
46 | 46 | getAllDataSourceFieldValue: Fn<any, Recordable>; |
47 | + validate: Fn; | |
47 | 48 | }>(); |
48 | 49 | |
49 | 50 | const resetForm = () => { |
... | ... | @@ -53,8 +54,9 @@ |
53 | 54 | componentDefaultConfig.value = {}; |
54 | 55 | }; |
55 | 56 | |
56 | - const handleSubmit = () => { | |
57 | - const { getAllDataSourceFieldValue } = unref(basicConfigurationEl)!; | |
57 | + const handleSubmit = async () => { | |
58 | + const { getAllDataSourceFieldValue, validate } = unref(basicConfigurationEl)!; | |
59 | + await validate(); | |
58 | 60 | const value = getAllDataSourceFieldValue(); |
59 | 61 | unref(isEdit) ? handleUpdateComponent(value) : handleAddComponent(value); |
60 | 62 | resetForm(); | ... | ... |
... | ... | @@ -32,6 +32,7 @@ export const basicSchema: FormSchema[] = [ |
32 | 32 | field: BasicConfigField.NAME, |
33 | 33 | label: '组件名称', |
34 | 34 | component: 'Input', |
35 | + rules: [{ required: true, message: '组件名称为必填项' }], | |
35 | 36 | componentProps: { |
36 | 37 | placeholder: '请输入组件名称', |
37 | 38 | }, |
... | ... | @@ -40,6 +41,7 @@ export const basicSchema: FormSchema[] = [ |
40 | 41 | field: BasicConfigField.REMARK, |
41 | 42 | label: '组件备注', |
42 | 43 | component: 'InputTextArea', |
44 | + // rules: [{ required: true, message: '组件备注为必填项' }], | |
43 | 45 | componentProps: { |
44 | 46 | placeholder: '请输入组件备注', |
45 | 47 | }, |
... | ... | @@ -64,6 +66,7 @@ export const dataSourceSchema: FormSchema[] = [ |
64 | 66 | component: 'ApiTreeSelect', |
65 | 67 | label: '组织', |
66 | 68 | colProps: { span: 8 }, |
69 | + rules: [{ required: true, message: '组织为必填项' }], | |
67 | 70 | componentProps({ formActionType }) { |
68 | 71 | const { setFieldsValue } = formActionType; |
69 | 72 | return { |
... | ... | @@ -90,6 +93,7 @@ export const dataSourceSchema: FormSchema[] = [ |
90 | 93 | component: 'ApiSelect', |
91 | 94 | label: '设备', |
92 | 95 | colProps: { span: 8 }, |
96 | + rules: [{ required: true, message: '设备名称为必填项' }], | |
93 | 97 | componentProps({ formModel, formActionType }) { |
94 | 98 | const { setFieldsValue } = formActionType; |
95 | 99 | const organizationId = formModel[DataSourceField.ORIGINATION_ID]; |
... | ... | @@ -126,6 +130,7 @@ export const dataSourceSchema: FormSchema[] = [ |
126 | 130 | label: '网关子设备', |
127 | 131 | component: 'ApiSelect', |
128 | 132 | colProps: { span: 8 }, |
133 | + rules: [{ required: true, message: '网关子设备为必填项' }], | |
129 | 134 | ifShow({ model }) { |
130 | 135 | return model[DataSourceField.IS_GATEWAY_DEVICE]; |
131 | 136 | }, |
... | ... | @@ -168,6 +173,7 @@ export const dataSourceSchema: FormSchema[] = [ |
168 | 173 | component: 'ApiSelect', |
169 | 174 | label: '属性', |
170 | 175 | colProps: { span: 8 }, |
176 | + rules: [{ required: true, message: '属性为必填项' }], | |
171 | 177 | componentProps({ formModel }) { |
172 | 178 | const organizationId = formModel[DataSourceField.ORIGINATION_ID]; |
173 | 179 | const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE]; | ... | ... |