Commit 42dbd4e21ab011b31a8846bed7e058cb9900c41b

Authored by YunaiV
1 parent f83d93bd

【代码评审】INFRA:代码生成在 vben5 的模版

yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenFrontTypeEnum.java
... ... @@ -12,10 +12,10 @@ import lombok.Getter;
12 12 @Getter
13 13 public enum CodegenFrontTypeEnum {
14 14  
15   - VUE2(10), // Vue2 Element UI 标准模版
16   - VUE3(20), // Vue3 Element Plus 标准模版
17   - VUE3_VBEN(30), // Vue3 VBEN 模版
18   - VUE3_VBEN_NEXT_SCHEMA(40), // Vue3 vben5 schema 模版
  15 + VUE2_ELEMENT_UI(10), // Vue2 Element UI 标准模版
  16 + VUE3_ELEMENT_PLUS(20), // Vue3 Element Plus 标准模版
  17 + VUE3_VBEN2_ANTD_SCHEMA(30), // Vue3 VBEN2 + ANTD + Schema 模版
  18 + VUE3_VBEN5_ANTD_SCHEMA(40), // Vue3 VBEN5 + ANTD + schema 模版
19 19 ;
20 20  
21 21 /**
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
... ... @@ -101,57 +101,58 @@ public class CodegenEngine {
101 101 * value:生成的路径
102 102 */
103 103 private static final Table<Integer, String, String> FRONT_TEMPLATES = ImmutableTable.<Integer, String, String>builder()
104   - // Vue2 标准模版
105   - .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/index.vue"),
  104 + // VUE2_ELEMENT_UI
  105 + .put(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType(), vueTemplatePath("views/index.vue"),
106 106 vueFilePath("views/${table.moduleName}/${table.businessName}/index.vue"))
107   - .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("api/api.js"),
  107 + .put(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType(), vueTemplatePath("api/api.js"),
108 108 vueFilePath("api/${table.moduleName}/${table.businessName}/index.js"))
109   - .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/form.vue"),
  109 + .put(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType(), vueTemplatePath("views/form.vue"),
110 110 vueFilePath("views/${table.moduleName}/${table.businessName}/${simpleClassName}Form.vue"))
111   - .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/form_sub_normal.vue"), // 特殊:主子表专属逻辑
  111 + .put(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType(), vueTemplatePath("views/components/form_sub_normal.vue"), // 特殊:主子表专属逻辑
112 112 vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
113   - .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/form_sub_inner.vue"), // 特殊:主子表专属逻辑
  113 + .put(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType(), vueTemplatePath("views/components/form_sub_inner.vue"), // 特殊:主子表专属逻辑
114 114 vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
115   - .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/form_sub_erp.vue"), // 特殊:主子表专属逻辑
  115 + .put(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType(), vueTemplatePath("views/components/form_sub_erp.vue"), // 特殊:主子表专属逻辑
116 116 vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
117   - .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/list_sub_inner.vue"), // 特殊:主子表专属逻辑
  117 + .put(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType(), vueTemplatePath("views/components/list_sub_inner.vue"), // 特殊:主子表专属逻辑
118 118 vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue"))
119   - .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/list_sub_erp.vue"), // 特殊:主子表专属逻辑
  119 + .put(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType(), vueTemplatePath("views/components/list_sub_erp.vue"), // 特殊:主子表专属逻辑
120 120 vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue"))
121   - // Vue3 标准模版
122   - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/index.vue"),
  121 + // VUE3_ELEMENT_PLUS
  122 + .put(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), vue3TemplatePath("views/index.vue"),
123 123 vue3FilePath("views/${table.moduleName}/${table.businessName}/index.vue"))
124   - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/form.vue"),
  124 + .put(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), vue3TemplatePath("views/form.vue"),
125 125 vue3FilePath("views/${table.moduleName}/${table.businessName}/${simpleClassName}Form.vue"))
126   - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/form_sub_normal.vue"), // 特殊:主子表专属逻辑
  126 + .put(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), vue3TemplatePath("views/components/form_sub_normal.vue"), // 特殊:主子表专属逻辑
127 127 vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
128   - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/form_sub_inner.vue"), // 特殊:主子表专属逻辑
  128 + .put(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), vue3TemplatePath("views/components/form_sub_inner.vue"), // 特殊:主子表专属逻辑
129 129 vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
130   - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/form_sub_erp.vue"), // 特殊:主子表专属逻辑
  130 + .put(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), vue3TemplatePath("views/components/form_sub_erp.vue"), // 特殊:主子表专属逻辑
131 131 vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue"))
132   - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/list_sub_inner.vue"), // 特殊:主子表专属逻辑
  132 + .put(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), vue3TemplatePath("views/components/list_sub_inner.vue"), // 特殊:主子表专属逻辑
133 133 vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue"))
134   - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/components/list_sub_erp.vue"), // 特殊:主子表专属逻辑
  134 + .put(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), vue3TemplatePath("views/components/list_sub_erp.vue"), // 特殊:主子表专属逻辑
135 135 vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue"))
136   - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("api/api.ts"),
  136 + .put(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), vue3TemplatePath("api/api.ts"),
137 137 vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts"))
138   - // Vue3 vben 模版
139   - .put(CodegenFrontTypeEnum.VUE3_VBEN.getType(), vue3VbenTemplatePath("views/data.ts"),
  138 + // VUE3_VBEN2_ANTD_SCHEMA
  139 + .put(CodegenFrontTypeEnum.VUE3_VBEN2_ANTD_SCHEMA.getType(), vue3VbenTemplatePath("views/data.ts"),
140 140 vue3FilePath("views/${table.moduleName}/${table.businessName}/${classNameVar}.data.ts"))
141   - .put(CodegenFrontTypeEnum.VUE3_VBEN.getType(), vue3VbenTemplatePath("views/index.vue"),
  141 + .put(CodegenFrontTypeEnum.VUE3_VBEN2_ANTD_SCHEMA.getType(), vue3VbenTemplatePath("views/index.vue"),
142 142 vue3FilePath("views/${table.moduleName}/${table.businessName}/index.vue"))
143   - .put(CodegenFrontTypeEnum.VUE3_VBEN.getType(), vue3VbenTemplatePath("views/form.vue"),
  143 + .put(CodegenFrontTypeEnum.VUE3_VBEN2_ANTD_SCHEMA.getType(), vue3VbenTemplatePath("views/form.vue"),
144 144 vue3FilePath("views/${table.moduleName}/${table.businessName}/${simpleClassName}Modal.vue"))
145   - .put(CodegenFrontTypeEnum.VUE3_VBEN.getType(), vue3VbenTemplatePath("api/api.ts"),
  145 + .put(CodegenFrontTypeEnum.VUE3_VBEN2_ANTD_SCHEMA.getType(), vue3VbenTemplatePath("api/api.ts"),
146 146 vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts"))
147   - // Vue3 vben5 schema 模版
148   - .put(CodegenFrontTypeEnum.VUE3_VBEN_NEXT_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("views/data.ts"),
  147 + // VUE3_VBEN5_ANTD_SCHEMA
  148 + // TODO @puhui999:目录改成 vue3_vben5_antd;然后里面有 schema(目前我们在写的)和 general(你微信里提的,原生的,感觉也要搞!)
  149 + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("views/data.ts"),
149 150 vue3FilePath("views/${table.moduleName}/${table.businessName}/data.ts"))
150   - .put(CodegenFrontTypeEnum.VUE3_VBEN_NEXT_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("views/index.vue"),
  151 + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("views/index.vue"),
151 152 vue3FilePath("views/${table.moduleName}/${table.businessName}/index.vue"))
152   - .put(CodegenFrontTypeEnum.VUE3_VBEN_NEXT_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("views/form.vue"),
  153 + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("views/form.vue"),
153 154 vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/form.vue"))
154   - .put(CodegenFrontTypeEnum.VUE3_VBEN_NEXT_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("api/api.ts"),
  155 + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("api/api.ts"),
155 156 vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts"))
156 157 // 主子表模板配置 - Vue3 vben5 schema 模版
157 158 //.put(CodegenFrontTypeEnum.VUE3_VBEN_NEXT_SCHEMA.getType(), vue3VbenNextSchemaTemplatePath("views/master_slave_data.ts"),
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben_next/schema/views/data.ts.vm
... ... @@ -9,7 +9,6 @@ import { get${simpleClassName}List } from &#39;#/api/${table.moduleName}/${simpleCla
9 9 import { handleTree } from '#/utils/tree';
10 10 #end
11 11 import { DICT_TYPE, getDictOptions } from '#/utils/dict';
12   -import { CommonStatusEnum } from '#/utils/constants';
13 12 import { useAccess } from '@vben/access';
14 13  
15 14 const { hasAccessByCodes } = useAccess();
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben_next/schema/views/form.vue.vm
... ... @@ -14,15 +14,14 @@ import { useFormSchema } from &#39;../data&#39;;
14 14 const emit = defineEmits(['success']);
15 15 const formData = ref<${simpleClassName}Api.${simpleClassName}>();
16 16 #if (${table.templateType} == 2)## 树表特有:父ID处理
17   -// 新增下级时的父级ID
18   -const parentId = ref<number>();
  17 +const parentId = ref<number>(); // 新增下级时的父级 ID
19 18  
20 19 const getTitle = computed(() => {
21 20 if (formData.value?.id) {
22 21 return $t('ui.actionTitle.edit', ['${table.classComment}']);
23 22 }
24   - return parentId.value
25   - ? $t('ui.actionTitle.create', ['下级${table.classComment}'])
  23 + return parentId.value
  24 + ? $t('ui.actionTitle.create', ['下级${table.classComment}'])
26 25 : $t('ui.actionTitle.create', ['${table.classComment}']);
27 26 });
28 27 #else## 标准表标题
... ... @@ -36,10 +35,7 @@ const getTitle = computed(() =&gt; {
36 35 const [Form, formApi] = useVbenForm({
37 36 layout: 'horizontal',
38 37 schema: useFormSchema(),
39   - showDefaultActions: false,
40   - commonConfig: {
41   - labelWidth: 120
42   - }
  38 + showDefaultActions: false
43 39 });
44 40  
45 41 const [Modal, modalApi] = useVbenModal({
... ... @@ -77,7 +73,7 @@ const [Modal, modalApi] = useVbenModal({
77 73 if (!data) {
78 74 return;
79 75 }
80   -
  76 +
81 77 #if (${table.templateType} == 2)## 树表特有:处理新增下级的情况
82 78 // 处理新增下级的情况
83 79 if (!data.id && data.${treeParentColumn.javaField}) {
... ... @@ -87,7 +83,7 @@ const [Modal, modalApi] = useVbenModal({
87 83 return;
88 84 }
89 85 #end
90   -
  86 +
91 87 if (data.id) {
92 88 // 编辑
93 89 modalApi.lock();
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben_next/schema/views/index.vue.vm
... ... @@ -6,7 +6,6 @@ import { Page, useVbenModal } from &#39;@vben/common-ui&#39;;
6 6 import { Button, message } from 'ant-design-vue';
7 7 import { Download, Plus } from '@vben/icons';
8 8 import Form from './modules/form.vue';
9   -import { DocAlert } from '#/components/doc-alert';
10 9  
11 10 import { ref } from 'vue';
12 11 import { $t } from '#/locales';
... ... @@ -159,8 +158,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
159 158  
160 159 <template>
161 160 <Page auto-content-height>
162   - <DocAlert title="${table.classComment}" url="https://doc.iocoder.cn/${table.moduleName}/" />
163   -
164 161 <FormModal @success="onRefresh" />
165 162  
166 163 <Grid table-title="${table.classComment}列表">
... ...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImplTest.java
... ... @@ -105,7 +105,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
105 105 when(codegenBuilder.buildColumns(eq(table.getId()), same(fields)))
106 106 .thenReturn(columns);
107 107 // mock 方法(CodegenProperties)
108   - when(codegenProperties.getFrontType()).thenReturn(CodegenFrontTypeEnum.VUE3.getType());
  108 + when(codegenProperties.getFrontType()).thenReturn(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType());
109 109  
110 110 // 调用
111 111 List<Long> result = codegenService.createCodegenList(userId, reqVO);
... ... @@ -116,7 +116,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
116 116 assertPojoEquals(table, dbTable);
117 117 assertEquals(1L, dbTable.getDataSourceConfigId());
118 118 assertEquals(CodegenSceneEnum.ADMIN.getScene(), dbTable.getScene());
119   - assertEquals(CodegenFrontTypeEnum.VUE3.getType(), dbTable.getFrontType());
  119 + assertEquals(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), dbTable.getFrontType());
120 120 assertEquals("芋头", dbTable.getAuthor());
121 121 // 断言(CodegenColumnDO)
122 122 List<CodegenColumnDO> dbColumns = codegenColumnMapper.selectList();
... ...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java
... ... @@ -23,7 +23,7 @@ public class CodegenEngineVue2Test extends CodegenEngineAbstractTest {
23 23 public void testExecute_vue2_one() {
24 24 // 准备参数
25 25 CodegenTableDO table = getTable("student")
26   - .setFrontType(CodegenFrontTypeEnum.VUE2.getType())
  26 + .setFrontType(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType())
27 27 .setTemplateType(CodegenTemplateTypeEnum.ONE.getType());
28 28 List<CodegenColumnDO> columns = getColumnList("student");
29 29  
... ... @@ -39,7 +39,7 @@ public class CodegenEngineVue2Test extends CodegenEngineAbstractTest {
39 39 public void testExecute_vue2_tree() {
40 40 // 准备参数
41 41 CodegenTableDO table = getTable("category")
42   - .setFrontType(CodegenFrontTypeEnum.VUE2.getType())
  42 + .setFrontType(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType())
43 43 .setTemplateType(CodegenTemplateTypeEnum.TREE.getType());
44 44 List<CodegenColumnDO> columns = getColumnList("category");
45 45  
... ... @@ -71,19 +71,19 @@ public class CodegenEngineVue2Test extends CodegenEngineAbstractTest {
71 71 String path) {
72 72 // 准备参数
73 73 CodegenTableDO table = getTable("student")
74   - .setFrontType(CodegenFrontTypeEnum.VUE2.getType())
  74 + .setFrontType(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType())
75 75 .setTemplateType(templateType.getType());
76 76 List<CodegenColumnDO> columns = getColumnList("student");
77 77 // 准备参数(子表)
78 78 CodegenTableDO contactTable = getTable("contact")
79 79 .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
80   - .setFrontType(CodegenFrontTypeEnum.VUE2.getType())
  80 + .setFrontType(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType())
81 81 .setSubJoinColumnId(100L).setSubJoinMany(true);
82 82 List<CodegenColumnDO> contactColumns = getColumnList("contact");
83 83 // 准备参数(班主任)
84 84 CodegenTableDO teacherTable = getTable("teacher")
85 85 .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
86   - .setFrontType(CodegenFrontTypeEnum.VUE2.getType())
  86 + .setFrontType(CodegenFrontTypeEnum.VUE2_ELEMENT_UI.getType())
87 87 .setSubJoinColumnId(200L).setSubJoinMany(false);
88 88 List<CodegenColumnDO> teacherColumns = getColumnList("teacher");
89 89  
... ...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue3Test.java
... ... @@ -23,7 +23,7 @@ public class CodegenEngineVue3Test extends CodegenEngineAbstractTest {
23 23 public void testExecute_vue3_one() {
24 24 // 准备参数
25 25 CodegenTableDO table = getTable("student")
26   - .setFrontType(CodegenFrontTypeEnum.VUE3.getType())
  26 + .setFrontType(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType())
27 27 .setTemplateType(CodegenTemplateTypeEnum.ONE.getType());
28 28 List<CodegenColumnDO> columns = getColumnList("student");
29 29  
... ... @@ -39,7 +39,7 @@ public class CodegenEngineVue3Test extends CodegenEngineAbstractTest {
39 39 public void testExecute_vue3_tree() {
40 40 // 准备参数
41 41 CodegenTableDO table = getTable("category")
42   - .setFrontType(CodegenFrontTypeEnum.VUE3.getType())
  42 + .setFrontType(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType())
43 43 .setTemplateType(CodegenTemplateTypeEnum.TREE.getType());
44 44 List<CodegenColumnDO> columns = getColumnList("category");
45 45  
... ... @@ -71,19 +71,19 @@ public class CodegenEngineVue3Test extends CodegenEngineAbstractTest {
71 71 String path) {
72 72 // 准备参数
73 73 CodegenTableDO table = getTable("student")
74   - .setFrontType(CodegenFrontTypeEnum.VUE3.getType())
  74 + .setFrontType(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType())
75 75 .setTemplateType(templateType.getType());
76 76 List<CodegenColumnDO> columns = getColumnList("student");
77 77 // 准备参数(子表)
78 78 CodegenTableDO contactTable = getTable("contact")
79 79 .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
80   - .setFrontType(CodegenFrontTypeEnum.VUE3.getType())
  80 + .setFrontType(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType())
81 81 .setSubJoinColumnId(100L).setSubJoinMany(true);
82 82 List<CodegenColumnDO> contactColumns = getColumnList("contact");
83 83 // 准备参数(班主任)
84 84 CodegenTableDO teacherTable = getTable("teacher")
85 85 .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
86   - .setFrontType(CodegenFrontTypeEnum.VUE3.getType())
  86 + .setFrontType(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType())
87 87 .setSubJoinColumnId(200L).setSubJoinMany(false);
88 88 List<CodegenColumnDO> teacherColumns = getColumnList("teacher");
89 89  
... ...