Просмотр исходного кода

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

RuoYi лет назад: 2
Родитель
Сommit
d0e9e07e9c

+ 13 - 0
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java

@@ -41,6 +41,9 @@ public class GenTable extends BaseEntity
41 41
     /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */
42 42
     private String tplCategory;
43 43
 
44
+    /** 前端类型(element-ui模版 element-plus模版) */
45
+    private String tplWebType;
46
+
44 47
     /** 生成包路径 */
45 48
     @NotBlank(message = "生成包路径不能为空")
46 49
     private String packageName;
@@ -165,6 +168,16 @@ public class GenTable extends BaseEntity
165 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 181
     public String getPackageName()
169 182
     {
170 183
         return packageName;

+ 3 - 3
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java

@@ -206,7 +206,7 @@ public class GenTableServiceImpl implements IGenTableService
206 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 210
         for (String template : templates)
211 211
         {
212 212
             // 渲染模板
@@ -254,7 +254,7 @@ public class GenTableServiceImpl implements IGenTableService
254 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 258
         for (String template : templates)
259 259
         {
260 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 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 371
         for (String template : templates)
372 372
         {
373 373
             // 渲染模板

+ 11 - 5
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java

@@ -123,11 +123,17 @@ public class VelocityUtils
123 123
 
124 124
     /**
125 125
      * 获取模板信息
126
-     *
126
+     * @param tplCategory 生成的模板
127
+     * @param tplWebType 前端类型
127 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 137
         List<String> templates = new ArrayList<String>();
132 138
         templates.add("vm/java/domain.java.vm");
133 139
         templates.add("vm/java/mapper.java.vm");
@@ -139,15 +145,15 @@ public class VelocityUtils
139 145
         templates.add("vm/js/api.js.vm");
140 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 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 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 157
             templates.add("vm/java/sub-domain.java.vm");
152 158
         }
153 159
         return templates;

+ 8 - 4
ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
12 12
 		<result property="subTableFkName" column="sub_table_fk_name" />
13 13
 		<result property="className"      column="class_name"        />
14 14
 		<result property="tplCategory"    column="tpl_category"      />
15
+		<result property="tplWebType"     column="tpl_web_type"      />
15 16
 		<result property="packageName"    column="package_name"      />
16 17
 		<result property="moduleName"     column="module_name"       />
17 18
 		<result property="businessName"   column="business_name"     />
@@ -54,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
54 55
     </resultMap>
55 56
 	
56 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 59
     </sql>
59 60
     
60 61
     <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
@@ -111,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
111 112
 	</select>
112 113
 	
113 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 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 117
 		FROM gen_table t
117 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 120
 	</select>
120 121
 	
121 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 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 125
 		FROM gen_table t
125 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 128
 	</select>
128 129
 	
129 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 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 133
 		FROM gen_table t
133 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 141
 			<if test="tableComment != null and tableComment != ''">table_comment,</if>
141 142
 			<if test="className != null and className != ''">class_name,</if>
142 143
 			<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
144
+			<if test="tplWebType != null and tplWebType != ''">tpl_web_type,</if>
143 145
 			<if test="packageName != null and packageName != ''">package_name,</if>
144 146
 			<if test="moduleName != null and moduleName != ''">module_name,</if>
145 147
 			<if test="businessName != null and businessName != ''">business_name,</if>
@@ -155,6 +157,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
155 157
 			<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
156 158
 			<if test="className != null and className != ''">#{className},</if>
157 159
 			<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
160
+			<if test="tplWebType != null and tplWebType != ''">#{tplWebType},</if>
158 161
 			<if test="packageName != null and packageName != ''">#{packageName},</if>
159 162
 			<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
160 163
 			<if test="businessName != null and businessName != ''">#{businessName},</if>
@@ -180,6 +183,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
180 183
             <if test="genType != null and genType != ''">gen_type = #{genType},</if>
181 184
             <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
182 185
             <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
186
+            <if test="tplWebType != null and tplWebType != ''">tpl_web_type = #{tplWebType},</if>
183 187
             <if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
184 188
             <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
185 189
             <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>

+ 0 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3/readme.txt

@@ -1 +0,0 @@
1
-如果使用的是RuoYi-Cloud-Vue3前端,那么需要覆盖一下此目录的模板index.vue.vm、index-tree.vue.vm文件到上级vue目录。

+ 27 - 14
ruoyi-ui/src/views/tool/gen/genInfoForm.vue

@@ -12,6 +12,15 @@
12 12
         </el-form-item>
13 13
       </el-col>
14 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 24
         <el-form-item prop="packageName">
16 25
           <span slot="label">
17 26
             生成包路径
@@ -60,6 +69,19 @@
60 69
       </el-col>
61 70
 
62 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 85
         <el-form-item>
64 86
           <span slot="label">
65 87
             上级菜单
@@ -78,19 +100,6 @@
78 100
         </el-form-item>
79 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 103
       <el-col :span="24" v-if="info.genType == '1'">
95 104
         <el-form-item prop="genPath">
96 105
           <span slot="label">
@@ -255,10 +264,14 @@ export default {
255 264
       }
256 265
     };
257 266
   },
258
-  created() {},
259 267
   watch: {
260 268
     'info.subTableName': function(val) {
261 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 277
   methods: {

+ 1 - 0
sql/ry_20230706.sql

@@ -647,6 +647,7 @@ create table gen_table (
647 647
   sub_table_fk_name varchar(64)     default null               comment '子表关联的外键名',
648 648
   class_name        varchar(100)    default ''                 comment '实体类名称',
649 649
   tpl_category      varchar(200)    default 'crud'             comment '使用的模板(crud单表操作 tree树表操作)',
650
+  tpl_web_type      varchar(30)     default ''                 comment '前端模板类型(element-ui模版 element-plus模版)',
650 651
   package_name      varchar(100)                               comment '生成包路径',
651 652
   module_name       varchar(30)                                comment '生成模块名',
652 653
   business_name     varchar(30)                                comment '生成业务名',