feat: add CodegenOptionsModal for editing code generation configurations

- Introduced a new modal component for modifying code generation settings.
- Updated codegen.data.ts to include form schema for the new modal.
pull/54/head
chenminjie 2024-11-29 18:37:15 +08:00
parent 3e0c0af119
commit 2b04e1e4ef
3 changed files with 185 additions and 10 deletions

View File

@ -1,10 +1,11 @@
import type { VbenFormProps } from '@vben/common-ui';
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { CodegenApi } from '#/api/infra/codegen';
import { type VbenFormProps, z } from '@vben/common-ui';
import { getDataSourceConfigList } from '#/api/infra/data-source-config';
import { $t } from '#/locales';
import { DICT_TYPE } from '#/utils/dict';
export namespace CodegenDefaultData {
/**
@ -114,3 +115,131 @@ export namespace CodegenImportTableModalData {
},
];
}
//* ****************************** CodegenOptionsModal.vue *******************************//
export namespace CodegenOptionsModalData {
export const formSchema: VbenFormProps['schema'] = [
{
label: '表名称',
fieldName: 'tableName',
component: 'Input',
componentProps: {
placeholder: '请输入表名称',
},
rules: z.string().min(1, { message: '表名称不能为空' }),
},
{
label: '表描述',
fieldName: 'tableComment',
component: 'Input',
componentProps: {
placeholder: '请输入表描述',
},
rules: z.string().min(1, { message: '表描述不能为空' }),
},
{
label: '实体类名',
fieldName: 'className',
component: 'Input',
rules: z.string().min(1, { message: '实体类名不能为空' }),
componentProps: {
tooltip:
'默认去除表名的前缀。如果存在重复,则需要手动添加前缀,避免 MyBatis 报 Alias 重复的问题。',
placeholder: '请输入实体类名',
},
},
{
label: '作者',
fieldName: 'author',
component: 'Input',
rules: z.string().min(1, { message: '作者不能为空' }),
componentProps: {
placeholder: '请输入作者',
},
},
{
label: '备注',
fieldName: 'remark',
component: 'Input',
componentProps: {
placeholder: '请输入备注',
},
},
{
label: '生成模版',
fieldName: 'template',
component: 'ApiDict',
componentProps: {
code: DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE,
class: 'w-full',
placeholder: '请选择生成模版',
},
rules: z.string().min(1, { message: '生成模版不能为空' }),
defaultValue: '1',
},
{
label: '前端类型',
fieldName: 'frontType',
component: 'ApiDict',
componentProps: {
code: DICT_TYPE.INFRA_CODEGEN_FRONT_TYPE,
class: 'w-full',
placeholder: '请选择前端类型',
},
rules: z.string().min(1, { message: '前端类型不能为空' }),
defaultValue: '31',
},
{
label: '生成场景',
fieldName: 'scene',
component: 'ApiDict',
componentProps: {
code: DICT_TYPE.INFRA_CODEGEN_SCENE,
class: 'w-full',
placeholder: '请选择生成场景',
},
rules: z.string().min(1, { message: '生成场景不能为空' }),
defaultValue: '1',
},
{
label: '上级菜单',
fieldName: 'parentMenuId',
component: 'ApiTreeSelect',
componentProps: {
class: 'w-full',
placeholder: '请选择上级菜单',
},
rules: z.string().min(1, { message: '上级菜单不能为空' }),
},
{
label: '模块名',
fieldName: 'moduleName',
component: 'Input',
rules: z.string().min(1, { message: '模块名不能为空' }),
componentProps: {
placeholder: '请输入模块名',
},
},
{
label: '业务名',
fieldName: 'businessName',
component: 'Input',
rules: z.string().min(1, { message: '业务名不能为空' }),
componentProps: {
placeholder: '请输入业务名',
},
},
{
label: '类名',
fieldName: 'className',
component: 'Input',
rules: z.string().min(1, { message: '类名不能为空' }),
},
{
label: '类描述',
fieldName: 'classComment',
component: 'Input',
rules: z.string().min(1, { message: '类描述不能为空' }),
},
];
}

View File

@ -0,0 +1,37 @@
<script setup lang="ts">
import { useVbenForm, useVbenModal } from '@vben/common-ui';
import { CodegenOptionsModalData } from '../codegen.data';
defineOptions({
name: 'CodegenOptionsModal',
});
// 使
const [Form] = useVbenForm({
commonConfig: {
labelWidth: 120,
wrapperClass: 'w-full',
},
schema: CodegenOptionsModalData.formSchema,
// 321
wrapperClass: 'grid-cols-1 md:grid-cols-2',
});
// 使
const [Modal] = useVbenModal({
title: '修改代码生成配置',
class: 'w-[90%] h-[90%]',
onOpenChange(isOpen) {
if (isOpen) {
// TODO:
}
},
});
</script>
<template>
<Modal>
<Form />
</Modal>
</template>

View File

@ -16,13 +16,6 @@ import { CodegenDefaultData } from './codegen.data';
// checked
const checkedStatus = ref<boolean>(false);
/**
* 编辑
*/
const handleEdit = (_row: CodegenApi.CodegenTableRespVO) => {
// console.log('', row);
};
/**
* 删除
*/
@ -145,6 +138,13 @@ const [PreviewCodeModal, previewCodeModalApi] = useVbenModal({
),
});
// 使
const [CodegenOptionsModal, codegenOptionsModalApi] = useVbenModal({
connectedComponent: defineAsyncComponent(
() => import('./components/codegen-options-modal.vue'),
),
});
/**
* 打开导入表弹窗
*/
@ -159,6 +159,14 @@ const handleOpenPreviewCodeModal = (row: CodegenApi.CodegenTableRespVO) => {
previewCodeModalApi.setData(row);
previewCodeModalApi.open();
};
/**
* 打开修改代码生成配置弹窗
*/
const handleOpenCodegenOptionsModal = (row: CodegenApi.CodegenTableRespVO) => {
codegenOptionsModalApi.setData(row);
codegenOptionsModalApi.open();
};
</script>
<template>
@ -214,7 +222,7 @@ const handleOpenPreviewCodeModal = (row: CodegenApi.CodegenTableRespVO) => {
type: 'link',
label: '编辑',
icon: 'ant-design:edit-outlined',
onClick: handleEdit.bind(null, row),
onClick: handleOpenCodegenOptionsModal.bind(null, row),
},
{
type: 'link',
@ -241,5 +249,6 @@ const handleOpenPreviewCodeModal = (row: CodegenApi.CodegenTableRespVO) => {
</Grid>
<ImportTableModal />
<PreviewCodeModal />
<CodegenOptionsModal />
</Page>
</template>