refactor: 完善代码生成器保存校验

pull/69/head
puhui999 2025-04-09 17:56:36 +08:00
parent 0f9ccbb955
commit 26c168afc3
4 changed files with 27 additions and 13 deletions

View File

@ -250,6 +250,7 @@ export function useTreeTableFormSchema(columns: InfraCodegenApi.CodegenColumn[]
value: column.id, value: column.id,
})), })),
}, },
rules: 'selectRequired',
}, },
{ {
component: 'Select', component: 'Select',
@ -265,6 +266,7 @@ export function useTreeTableFormSchema(columns: InfraCodegenApi.CodegenColumn[]
value: column.id, value: column.id,
})), })),
}, },
rules: 'selectRequired',
}, },
]; ];
} }
@ -300,6 +302,7 @@ export function useSubTableFormSchema(
value: table.id, value: table.id,
})), })),
}, },
rules: 'selectRequired',
}, },
{ {
component: 'Select', component: 'Select',
@ -315,6 +318,7 @@ export function useSubTableFormSchema(
value: column.id, value: column.id,
})), })),
}, },
rules: 'selectRequired',
}, },
{ {
component: 'RadioGroup', component: 'RadioGroup',
@ -336,6 +340,7 @@ export function useSubTableFormSchema(
}, },
], ],
}, },
rules: 'required',
}, },
]; ];
} }

View File

@ -43,23 +43,25 @@ const getDetail = async () => {
// //
const submitForm = async () => { const submitForm = async () => {
try {
// //
await basicInfoRef.value?.validate(); const basicInfoValid = await basicInfoRef.value?.validate();
await generateInfoRef.value?.validate(); if (!basicInfoValid) {
} catch { message.warn('保存失败,原因:基本信息表单校验失败请检查!!!');
message.warn('保存失败,原因:存在表单校验失败请检查!!!'); return;
}
const generateInfoValid = await generateInfoRef.value?.validate();
if (!generateInfoValid) {
message.warn('保存失败,原因:生成信息表单校验失败请检查!!!');
return; return;
} }
//
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.updating'), content: $t('ui.actionMessage.updating'),
duration: 0, duration: 0,
key: 'action_process_msg', key: 'action_process_msg',
}); });
try { try {
debugger;
// //
const basicInfo = await basicInfoRef.value?.getValues(); const basicInfo = await basicInfoRef.value?.getValues();
const columns = columnInfoRef.value?.getData() || unref(formData).columns; const columns = columnInfoRef.value?.getData() || unref(formData).columns;
@ -71,7 +73,6 @@ const submitForm = async () => {
}); });
close(); close();
} catch (error) { } catch (error) {
message.warn('保存失败!!!');
console.error('保存失败', error); console.error('保存失败', error);
} finally { } finally {
hideLoading(); hideLoading();

View File

@ -33,7 +33,10 @@ watch(
/** 暴露出表单校验方法和表单值获取方法 */ /** 暴露出表单校验方法和表单值获取方法 */
defineExpose({ defineExpose({
validate: formApi.validate, validate: async () => {
const { valid } = await formApi.validate();
return valid;
},
getValues: formApi.getValues, getValues: formApi.getValues,
}); });
</script> </script>

View File

@ -85,14 +85,19 @@ async function getAllFormValues(): Promise<Record<string, any>> {
/** 验证所有表单 */ /** 验证所有表单 */
async function validateAllForms() { async function validateAllForms() {
let validateResult: boolean;
// //
await baseFormApi.validate(); const { valid: baseFormValid } = await baseFormApi.validate();
validateResult = baseFormValid;
// //
if (isTreeTable.value) { if (isTreeTable.value) {
await treeFormApi.validate(); const { valid: treeFormValid } = await treeFormApi.validate();
validateResult = baseFormValid && treeFormValid;
} else if (isSubTable.value) { } else if (isSubTable.value) {
await subFormApi.validate(); const { valid: subFormValid } = await subFormApi.validate();
validateResult = baseFormValid && subFormValid;
} }
return validateResult;
} }
/** 设置表单值 */ /** 设置表单值 */