作者 RuoYi

代码生成支持选择前端模板类型

@@ -41,6 +41,9 @@ public class GenTable extends BaseEntity @@ -41,6 +41,9 @@ public class GenTable extends BaseEntity
41 /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */ 41 /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */
42 private String tplCategory; 42 private String tplCategory;
43 43
  44 + /** 前端类型(element-ui模版 element-plus模版) */
  45 + private String tplWebType;
  46 +
44 /** 生成包路径 */ 47 /** 生成包路径 */
45 @NotBlank(message = "生成包路径不能为空") 48 @NotBlank(message = "生成包路径不能为空")
46 private String packageName; 49 private String packageName;
@@ -165,6 +168,16 @@ public class GenTable extends BaseEntity @@ -165,6 +168,16 @@ public class GenTable extends BaseEntity
165 this.tplCategory = tplCategory; 168 this.tplCategory = tplCategory;
166 } 169 }
167 170
  171 + public String getTplWebType()
  172 + {
  173 + return tplWebType;
  174 + }
  175 +
  176 + public void setTplWebType(String tplWebType)
  177 + {
  178 + this.tplWebType = tplWebType;
  179 + }
  180 +
168 public String getPackageName() 181 public String getPackageName()
169 { 182 {
170 return packageName; 183 return packageName;
@@ -206,7 +206,7 @@ public class GenTableServiceImpl implements IGenTableService @@ -206,7 +206,7 @@ public class GenTableServiceImpl implements IGenTableService
206 VelocityContext context = VelocityUtils.prepareContext(table); 206 VelocityContext context = VelocityUtils.prepareContext(table);
207 207
208 // 获取模板列表 208 // 获取模板列表
209 - List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); 209 + List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
210 for (String template : templates) 210 for (String template : templates)
211 { 211 {
212 // 渲染模板 212 // 渲染模板
@@ -254,7 +254,7 @@ public class GenTableServiceImpl implements IGenTableService @@ -254,7 +254,7 @@ public class GenTableServiceImpl implements IGenTableService
254 VelocityContext context = VelocityUtils.prepareContext(table); 254 VelocityContext context = VelocityUtils.prepareContext(table);
255 255
256 // 获取模板列表 256 // 获取模板列表
257 - List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); 257 + List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
258 for (String template : templates) 258 for (String template : templates)
259 { 259 {
260 if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) 260 if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
@@ -367,7 +367,7 @@ public class GenTableServiceImpl implements IGenTableService @@ -367,7 +367,7 @@ public class GenTableServiceImpl implements IGenTableService
367 VelocityContext context = VelocityUtils.prepareContext(table); 367 VelocityContext context = VelocityUtils.prepareContext(table);
368 368
369 // 获取模板列表 369 // 获取模板列表
370 - List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); 370 + List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
371 for (String template : templates) 371 for (String template : templates)
372 { 372 {
373 // 渲染模板 373 // 渲染模板
@@ -123,11 +123,17 @@ public class VelocityUtils @@ -123,11 +123,17 @@ public class VelocityUtils
123 123
124 /** 124 /**
125 * 获取模板信息 125 * 获取模板信息
126 - * 126 + * @param tplCategory 生成的模板
  127 + * @param tplWebType 前端类型
127 * @return 模板列表 128 * @return 模板列表
128 */ 129 */
129 - public static List<String> getTemplateList(String tplCategory) 130 + public static List<String> getTemplateList(String tplCategory, String tplWebType)
130 { 131 {
  132 + String useWebType = "vm/vue";
  133 + if ("element-plus".equals(tplWebType))
  134 + {
  135 + useWebType = "vm/vue/v3";
  136 + }
131 List<String> templates = new ArrayList<String>(); 137 List<String> templates = new ArrayList<String>();
132 templates.add("vm/java/domain.java.vm"); 138 templates.add("vm/java/domain.java.vm");
133 templates.add("vm/java/mapper.java.vm"); 139 templates.add("vm/java/mapper.java.vm");
@@ -139,15 +145,15 @@ public class VelocityUtils @@ -139,15 +145,15 @@ public class VelocityUtils
139 templates.add("vm/js/api.js.vm"); 145 templates.add("vm/js/api.js.vm");
140 if (GenConstants.TPL_CRUD.equals(tplCategory)) 146 if (GenConstants.TPL_CRUD.equals(tplCategory))
141 { 147 {
142 - templates.add("vm/vue/index.vue.vm"); 148 + templates.add(useWebType + "/index.vue.vm");
143 } 149 }
144 else if (GenConstants.TPL_TREE.equals(tplCategory)) 150 else if (GenConstants.TPL_TREE.equals(tplCategory))
145 { 151 {
146 - templates.add("vm/vue/index-tree.vue.vm"); 152 + templates.add(useWebType + "/index-tree.vue.vm");
147 } 153 }
148 else if (GenConstants.TPL_SUB.equals(tplCategory)) 154 else if (GenConstants.TPL_SUB.equals(tplCategory))
149 { 155 {
150 - templates.add("vm/vue/index.vue.vm"); 156 + templates.add(useWebType + "/index.vue.vm");
151 templates.add("vm/java/sub-domain.java.vm"); 157 templates.add("vm/java/sub-domain.java.vm");
152 } 158 }
153 return templates; 159 return templates;
@@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
12 <result property="subTableFkName" column="sub_table_fk_name" /> 12 <result property="subTableFkName" column="sub_table_fk_name" />
13 <result property="className" column="class_name" /> 13 <result property="className" column="class_name" />
14 <result property="tplCategory" column="tpl_category" /> 14 <result property="tplCategory" column="tpl_category" />
  15 + <result property="tplWebType" column="tpl_web_type" />
15 <result property="packageName" column="package_name" /> 16 <result property="packageName" column="package_name" />
16 <result property="moduleName" column="module_name" /> 17 <result property="moduleName" column="module_name" />
17 <result property="businessName" column="business_name" /> 18 <result property="businessName" column="business_name" />
@@ -54,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -54,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
54 </resultMap> 55 </resultMap>
55 56
56 <sql id="selectGenTableVo"> 57 <sql id="selectGenTableVo">
57 - select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table 58 + select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, tpl_web_type, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
58 </sql> 59 </sql>
59 60
60 <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> 61 <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
@@ -111,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -111,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
111 </select> 112 </select>
112 113
113 <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> 114 <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
114 - SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, 115 + SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
115 c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort 116 c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
116 FROM gen_table t 117 FROM gen_table t
117 LEFT JOIN gen_table_column c ON t.table_id = c.table_id 118 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
@@ -119,7 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -119,7 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
119 </select> 120 </select>
120 121
121 <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> 122 <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
122 - SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, 123 + SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
123 c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort 124 c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
124 FROM gen_table t 125 FROM gen_table t
125 LEFT JOIN gen_table_column c ON t.table_id = c.table_id 126 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
@@ -127,7 +128,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -127,7 +128,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
127 </select> 128 </select>
128 129
129 <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult"> 130 <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
130 - SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark, 131 + SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.tpl_web_type, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
131 c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort 132 c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
132 FROM gen_table t 133 FROM gen_table t
133 LEFT JOIN gen_table_column c ON t.table_id = c.table_id 134 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
@@ -140,6 +141,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -140,6 +141,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
140 <if test="tableComment != null and tableComment != ''">table_comment,</if> 141 <if test="tableComment != null and tableComment != ''">table_comment,</if>
141 <if test="className != null and className != ''">class_name,</if> 142 <if test="className != null and className != ''">class_name,</if>
142 <if test="tplCategory != null and tplCategory != ''">tpl_category,</if> 143 <if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
  144 + <if test="tplWebType != null and tplWebType != ''">tpl_web_type,</if>
143 <if test="packageName != null and packageName != ''">package_name,</if> 145 <if test="packageName != null and packageName != ''">package_name,</if>
144 <if test="moduleName != null and moduleName != ''">module_name,</if> 146 <if test="moduleName != null and moduleName != ''">module_name,</if>
145 <if test="businessName != null and businessName != ''">business_name,</if> 147 <if test="businessName != null and businessName != ''">business_name,</if>
@@ -155,6 +157,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -155,6 +157,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
155 <if test="tableComment != null and tableComment != ''">#{tableComment},</if> 157 <if test="tableComment != null and tableComment != ''">#{tableComment},</if>
156 <if test="className != null and className != ''">#{className},</if> 158 <if test="className != null and className != ''">#{className},</if>
157 <if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if> 159 <if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
  160 + <if test="tplWebType != null and tplWebType != ''">#{tplWebType},</if>
158 <if test="packageName != null and packageName != ''">#{packageName},</if> 161 <if test="packageName != null and packageName != ''">#{packageName},</if>
159 <if test="moduleName != null and moduleName != ''">#{moduleName},</if> 162 <if test="moduleName != null and moduleName != ''">#{moduleName},</if>
160 <if test="businessName != null and businessName != ''">#{businessName},</if> 163 <if test="businessName != null and businessName != ''">#{businessName},</if>
@@ -180,6 +183,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -180,6 +183,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
180 <if test="genType != null and genType != ''">gen_type = #{genType},</if> 183 <if test="genType != null and genType != ''">gen_type = #{genType},</if>
181 <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if> 184 <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
182 <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if> 185 <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
  186 + <if test="tplWebType != null and tplWebType != ''">tpl_web_type = #{tplWebType},</if>
183 <if test="packageName != null and packageName != ''">package_name = #{packageName},</if> 187 <if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
184 <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if> 188 <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
185 <if test="businessName != null and businessName != ''">business_name = #{businessName},</if> 189 <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
@@ -12,6 +12,15 @@ @@ -12,6 +12,15 @@
12 </el-form-item> 12 </el-form-item>
13 </el-col> 13 </el-col>
14 <el-col :span="12"> 14 <el-col :span="12">
  15 + <el-form-item prop="tplWebType">
  16 + <span slot="label">前端类型</span>
  17 + <el-select v-model="info.tplWebType">
  18 + <el-option label="Vue2 Element UI 模版" value="element-ui" />
  19 + <el-option label="Vue3 Element Plus 模版" value="element-plus" />
  20 + </el-select>
  21 + </el-form-item>
  22 + </el-col>
  23 + <el-col :span="12">
15 <el-form-item prop="packageName"> 24 <el-form-item prop="packageName">
16 <span slot="label"> 25 <span slot="label">
17 生成包路径 26 生成包路径
@@ -60,6 +69,19 @@ @@ -60,6 +69,19 @@
60 </el-col> 69 </el-col>
61 70
62 <el-col :span="12"> 71 <el-col :span="12">
  72 + <el-form-item prop="genType">
  73 + <span slot="label">
  74 + 生成代码方式
  75 + <el-tooltip content="默认为zip压缩包下载,也可以自定义生成路径" placement="top">
  76 + <i class="el-icon-question"></i>
  77 + </el-tooltip>
  78 + </span>
  79 + <el-radio v-model="info.genType" label="0">zip压缩包</el-radio>
  80 + <el-radio v-model="info.genType" label="1">自定义路径</el-radio>
  81 + </el-form-item>
  82 + </el-col>
  83 +
  84 + <el-col :span="12">
63 <el-form-item> 85 <el-form-item>
64 <span slot="label"> 86 <span slot="label">
65 上级菜单 87 上级菜单
@@ -78,19 +100,6 @@ @@ -78,19 +100,6 @@
78 </el-form-item> 100 </el-form-item>
79 </el-col> 101 </el-col>
80 102
81 - <el-col :span="12">  
82 - <el-form-item prop="genType">  
83 - <span slot="label">  
84 - 生成代码方式  
85 - <el-tooltip content="默认为zip压缩包下载,也可以自定义生成路径" placement="top">  
86 - <i class="el-icon-question"></i>  
87 - </el-tooltip>  
88 - </span>  
89 - <el-radio v-model="info.genType" label="0">zip压缩包</el-radio>  
90 - <el-radio v-model="info.genType" label="1">自定义路径</el-radio>  
91 - </el-form-item>  
92 - </el-col>  
93 -  
94 <el-col :span="24" v-if="info.genType == '1'"> 103 <el-col :span="24" v-if="info.genType == '1'">
95 <el-form-item prop="genPath"> 104 <el-form-item prop="genPath">
96 <span slot="label"> 105 <span slot="label">
@@ -255,10 +264,14 @@ export default { @@ -255,10 +264,14 @@ export default {
255 } 264 }
256 }; 265 };
257 }, 266 },
258 - created() {},  
259 watch: { 267 watch: {
260 'info.subTableName': function(val) { 268 'info.subTableName': function(val) {
261 this.setSubTableColumns(val); 269 this.setSubTableColumns(val);
  270 + },
  271 + 'info.tplWebType': function(val) {
  272 + if (val === '') {
  273 + this.info.tplWebType = "element-ui";
  274 + }
262 } 275 }
263 }, 276 },
264 methods: { 277 methods: {