diff --git a/apps/web-antd/src/views/infra/codegen/data.ts b/apps/web-antd/src/views/infra/codegen/data.ts index 8df317f3d..2f8536898 100644 --- a/apps/web-antd/src/views/infra/codegen/data.ts +++ b/apps/web-antd/src/views/infra/codegen/data.ts @@ -250,6 +250,7 @@ export function useTreeTableFormSchema(columns: InfraCodegenApi.CodegenColumn[] value: column.id, })), }, + rules: 'selectRequired', }, { component: 'Select', @@ -265,6 +266,7 @@ export function useTreeTableFormSchema(columns: InfraCodegenApi.CodegenColumn[] value: column.id, })), }, + rules: 'selectRequired', }, ]; } @@ -300,6 +302,7 @@ export function useSubTableFormSchema( value: table.id, })), }, + rules: 'selectRequired', }, { component: 'Select', @@ -315,6 +318,7 @@ export function useSubTableFormSchema( value: column.id, })), }, + rules: 'selectRequired', }, { component: 'RadioGroup', @@ -336,6 +340,7 @@ export function useSubTableFormSchema( }, ], }, + rules: 'required', }, ]; } diff --git a/apps/web-antd/src/views/infra/codegen/edit.vue b/apps/web-antd/src/views/infra/codegen/edit.vue index d9c2c481a..9620a37c6 100644 --- a/apps/web-antd/src/views/infra/codegen/edit.vue +++ b/apps/web-antd/src/views/infra/codegen/edit.vue @@ -43,23 +43,25 @@ const getDetail = async () => { // 提交表单 const submitForm = async () => { - try { - // 表单验证 - await basicInfoRef.value?.validate(); - await generateInfoRef.value?.validate(); - } catch { - message.warn('保存失败,原因:存在表单校验失败请检查!!!'); + // 表单验证 + const basicInfoValid = await basicInfoRef.value?.validate(); + if (!basicInfoValid) { + message.warn('保存失败,原因:基本信息表单校验失败请检查!!!'); + return; + } + const generateInfoValid = await generateInfoRef.value?.validate(); + if (!generateInfoValid) { + message.warn('保存失败,原因:生成信息表单校验失败请检查!!!'); return; } + // 提交 const hideLoading = message.loading({ content: $t('ui.actionMessage.updating'), duration: 0, key: 'action_process_msg', }); - try { - debugger; // 获取相关信息 const basicInfo = await basicInfoRef.value?.getValues(); const columns = columnInfoRef.value?.getData() || unref(formData).columns; @@ -71,7 +73,6 @@ const submitForm = async () => { }); close(); } catch (error) { - message.warn('保存失败!!!'); console.error('保存失败', error); } finally { hideLoading(); diff --git a/apps/web-antd/src/views/infra/codegen/modules/basic-info.vue b/apps/web-antd/src/views/infra/codegen/modules/basic-info.vue index 0ad411bcf..c333209dd 100644 --- a/apps/web-antd/src/views/infra/codegen/modules/basic-info.vue +++ b/apps/web-antd/src/views/infra/codegen/modules/basic-info.vue @@ -33,7 +33,10 @@ watch( /** 暴露出表单校验方法和表单值获取方法 */ defineExpose({ - validate: formApi.validate, + validate: async () => { + const { valid } = await formApi.validate(); + return valid; + }, getValues: formApi.getValues, }); diff --git a/apps/web-antd/src/views/infra/codegen/modules/generation-info.vue b/apps/web-antd/src/views/infra/codegen/modules/generation-info.vue index 8c7b05e94..d47e26ef3 100644 --- a/apps/web-antd/src/views/infra/codegen/modules/generation-info.vue +++ b/apps/web-antd/src/views/infra/codegen/modules/generation-info.vue @@ -85,14 +85,19 @@ async function getAllFormValues(): Promise> { /** 验证所有表单 */ async function validateAllForms() { + let validateResult: boolean; // 验证基础表单 - await baseFormApi.validate(); + const { valid: baseFormValid } = await baseFormApi.validate(); + validateResult = baseFormValid; // 根据模板类型验证对应的额外表单 if (isTreeTable.value) { - await treeFormApi.validate(); + const { valid: treeFormValid } = await treeFormApi.validate(); + validateResult = baseFormValid && treeFormValid; } else if (isSubTable.value) { - await subFormApi.validate(); + const { valid: subFormValid } = await subFormApi.validate(); + validateResult = baseFormValid && subFormValid; } + return validateResult; } /** 设置表单值 */