refactor: enhance code generation forms by replacing ApiDict with ApiSelect and improving validation rules

pull/58/head
chenminjie 2024-12-12 19:36:42 +08:00
parent 38c37e37b8
commit 12df9f8ef3
2 changed files with 28 additions and 33 deletions

View File

@ -2,7 +2,7 @@ import type { VxeGridProps } from '#/adapter/vxe-table';
import type { CodegenApi } from '#/api/infra/codegen'; import type { CodegenApi } from '#/api/infra/codegen';
import { type VbenFormProps, z } from '@vben/common-ui'; import { type VbenFormProps, z } from '@vben/common-ui';
import { useUserStore } from '@vben/stores'; import { useDictStore, useUserStore } from '@vben/stores';
import { getDataSourceConfigList } from '#/api/infra/data-source-config'; import { getDataSourceConfigList } from '#/api/infra/data-source-config';
import { $t } from '#/locales'; import { $t } from '#/locales';
@ -88,21 +88,11 @@ export namespace CodegenImportTableModalData {
fieldName: 'dataSourceConfigId', fieldName: 'dataSourceConfigId',
component: 'ApiSelect', component: 'ApiSelect',
componentProps: { componentProps: {
defaultSelectedFirst: true,
allowClear: true,
placeholder: '请选择数据源', placeholder: '请选择数据源',
api: getDataSourceConfigList, api: getDataSourceConfigList,
labelField: 'name', labelField: 'name',
valueField: 'id', valueField: 'id',
}, },
componentEvents: (events, formApi) => {
return {
optionsChange: (value: any) => {
// 设置默认选中第一个
formApi.setFieldValue('dataSourceConfigId', value[0].id);
},
};
},
}, },
{ {
label: '表名称', label: '表名称',
@ -169,37 +159,47 @@ export namespace CodegenOptionsModalData {
{ {
label: '生成模版', label: '生成模版',
fieldName: 'template', fieldName: 'template',
component: 'ApiDict', component: 'ApiSelect',
componentProps: { componentProps: {
code: DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE,
class: 'w-full', class: 'w-full',
placeholder: '请选择生成模版', placeholder: '请选择生成模版',
api: () => {
return useDictStore().getDictOptions(
DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE,
);
},
}, },
rules: z.string().min(1, { message: '生成模版不能为空' }), rules: 'required',
defaultValue: '1', defaultValue: '1',
}, },
{ {
label: '前端类型', label: '前端类型',
fieldName: 'frontType', fieldName: 'frontType',
component: 'ApiDict', component: 'ApiSelect',
componentProps: { componentProps: {
code: DICT_TYPE.INFRA_CODEGEN_FRONT_TYPE,
class: 'w-full', class: 'w-full',
placeholder: '请选择前端类型', placeholder: '请选择前端类型',
api: () => {
return useDictStore().getDictOptions(
DICT_TYPE.INFRA_CODEGEN_FRONT_TYPE,
);
},
}, },
rules: z.string().min(1, { message: '前端类型不能为空' }), rules: 'required',
defaultValue: '31', defaultValue: '31',
}, },
{ {
label: '生成场景', label: '生成场景',
fieldName: 'scene', fieldName: 'scene',
component: 'ApiDict', component: 'ApiSelect',
componentProps: { componentProps: {
code: DICT_TYPE.INFRA_CODEGEN_SCENE,
class: 'w-full', class: 'w-full',
placeholder: '请选择生成场景', placeholder: '请选择生成场景',
api: () => {
return useDictStore().getDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE);
},
}, },
rules: z.string().min(1, { message: '生成场景不能为空' }), rules: 'required',
defaultValue: '1', defaultValue: '1',
}, },
{ {
@ -214,16 +214,17 @@ export namespace CodegenOptionsModalData {
}, },
labelField: 'name', labelField: 'name',
valueField: 'id', valueField: 'id',
childrenField: 'children',
placeholder: '请选择上级菜单', placeholder: '请选择上级菜单',
}, },
rules: z.number().min(1, { message: '上级菜单不能为空' }), rules: 'required',
defaultValue: null, defaultValue: null,
}, },
{ {
label: '模块名', label: '模块名',
fieldName: 'moduleName', fieldName: 'moduleName',
component: 'Input', component: 'Input',
rules: z.string().min(1, { message: '模块名不能为空' }), rules: 'required',
componentProps: { componentProps: {
placeholder: '请输入模块名', placeholder: '请输入模块名',
}, },
@ -232,22 +233,19 @@ export namespace CodegenOptionsModalData {
label: '业务名', label: '业务名',
fieldName: 'businessName', fieldName: 'businessName',
component: 'Input', component: 'Input',
rules: z.string().min(1, { message: '业务名不能为空' }), rules: 'required',
componentProps: { componentProps: {
placeholder: '请输入业务名', placeholder: '请输入业务名',
}, },
}, },
{
label: '类名',
fieldName: 'className',
component: 'Input',
rules: z.string().min(1, { message: '类名不能为空' }),
},
{ {
label: '类描述', label: '类描述',
fieldName: 'classComment', fieldName: 'classComment',
component: 'Input', component: 'Input',
rules: z.string().min(1, { message: '类描述不能为空' }), rules: 'required',
componentProps: {
placeholder: '请输入类描述',
},
}, },
]; ];
} }

View File

@ -85,9 +85,6 @@ const [Modal, modalApi] = useVbenModal({
confirmLoading: confirmLoading.value, confirmLoading: confirmLoading.value,
closeOnClickModal: false, closeOnClickModal: false,
closeOnPressEscape: false, closeOnPressEscape: false,
onOpened: async () => {
gridApi.reload(await gridApi.formApi.getValues());
},
onConfirm: async () => { onConfirm: async () => {
modalApi.setState({ confirmLoading: true }); modalApi.setState({ confirmLoading: true });
const formValues = await gridApi.formApi.getValues(); const formValues = await gridApi.formApi.getValues();