作者 RuoYi

代码生成支持自定义路径

@@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest; @@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
14 * 14 *
15 * @author ruoyi 15 * @author ruoyi
16 */ 16 */
17 -public class FileUtils 17 +public class FileUtils extends org.apache.commons.io.FileUtils
18 { 18 {
19 public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+"; 19 public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
20 20
@@ -17,7 +17,6 @@ import java.util.List; @@ -17,7 +17,6 @@ import java.util.List;
17 import java.util.Map; 17 import java.util.Map;
18 import java.util.UUID; 18 import java.util.UUID;
19 import java.util.stream.Collectors; 19 import java.util.stream.Collectors;
20 -  
21 import org.apache.poi.hssf.usermodel.HSSFDateUtil; 20 import org.apache.poi.hssf.usermodel.HSSFDateUtil;
22 import org.apache.poi.ss.usermodel.BorderStyle; 21 import org.apache.poi.ss.usermodel.BorderStyle;
23 import org.apache.poi.ss.usermodel.Cell; 22 import org.apache.poi.ss.usermodel.Cell;
@@ -41,7 +40,6 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook; @@ -41,7 +40,6 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook;
41 import org.apache.poi.xssf.usermodel.XSSFDataValidation; 40 import org.apache.poi.xssf.usermodel.XSSFDataValidation;
42 import org.slf4j.Logger; 41 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory; 42 import org.slf4j.LoggerFactory;
44 -  
45 import com.ruoyi.common.annotation.Excel; 43 import com.ruoyi.common.annotation.Excel;
46 import com.ruoyi.common.annotation.Excel.ColumnType; 44 import com.ruoyi.common.annotation.Excel.ColumnType;
47 import com.ruoyi.common.annotation.Excel.Type; 45 import com.ruoyi.common.annotation.Excel.Type;
@@ -148,18 +148,30 @@ public class GenController extends BaseController @@ -148,18 +148,30 @@ public class GenController extends BaseController
148 } 148 }
149 149
150 /** 150 /**
151 - * 生成代码 151 + * 生成代码(下载方式)
152 */ 152 */
153 @PreAuthorize("@ss.hasPermi('tool:gen:code')") 153 @PreAuthorize("@ss.hasPermi('tool:gen:code')")
154 @Log(title = "代码生成", businessType = BusinessType.GENCODE) 154 @Log(title = "代码生成", businessType = BusinessType.GENCODE)
155 - @GetMapping("/genCode/{tableName}")  
156 - public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException 155 + @GetMapping("/download/{tableName}")
  156 + public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
157 { 157 {
158 - byte[] data = genTableService.generatorCode(tableName); 158 + byte[] data = genTableService.downloadCode(tableName);
159 genCode(response, data); 159 genCode(response, data);
160 } 160 }
161 161
162 /** 162 /**
  163 + * 生成代码(自定义路径)
  164 + */
  165 + @PreAuthorize("@ss.hasPermi('tool:gen:code')")
  166 + @Log(title = "代码生成", businessType = BusinessType.GENCODE)
  167 + @GetMapping("/genCode/{tableName}")
  168 + public AjaxResult genCode(HttpServletResponse response, @PathVariable("tableName") String tableName)
  169 + {
  170 + genTableService.generatorCode(tableName);
  171 + return AjaxResult.success();
  172 + }
  173 +
  174 + /**
163 * 批量生成代码 175 * 批量生成代码
164 */ 176 */
165 @PreAuthorize("@ss.hasPermi('tool:gen:code')") 177 @PreAuthorize("@ss.hasPermi('tool:gen:code')")
@@ -168,7 +180,7 @@ public class GenController extends BaseController @@ -168,7 +180,7 @@ public class GenController extends BaseController
168 public void batchGenCode(HttpServletResponse response, String tables) throws IOException 180 public void batchGenCode(HttpServletResponse response, String tables) throws IOException
169 { 181 {
170 String[] tableNames = Convert.toStrArray(tables); 182 String[] tableNames = Convert.toStrArray(tables);
171 - byte[] data = genTableService.generatorCode(tableNames); 183 + byte[] data = genTableService.downloadCode(tableNames);
172 genCode(response, data); 184 genCode(response, data);
173 } 185 }
174 186
@@ -55,6 +55,12 @@ public class GenTable extends BaseEntity @@ -55,6 +55,12 @@ public class GenTable extends BaseEntity
55 @NotBlank(message = "作者不能为空") 55 @NotBlank(message = "作者不能为空")
56 private String functionAuthor; 56 private String functionAuthor;
57 57
  58 + /** 生成代码方式(0zip压缩包 1自定义路径) */
  59 + private String genType;
  60 +
  61 + /** 生成路径(不填默认项目路径) */
  62 + private String genPath;
  63 +
58 /** 主键信息 */ 64 /** 主键信息 */
59 private GenTableColumn pkColumn; 65 private GenTableColumn pkColumn;
60 66
@@ -180,6 +186,26 @@ public class GenTable extends BaseEntity @@ -180,6 +186,26 @@ public class GenTable extends BaseEntity
180 this.functionAuthor = functionAuthor; 186 this.functionAuthor = functionAuthor;
181 } 187 }
182 188
  189 + public String getGenType()
  190 + {
  191 + return genType;
  192 + }
  193 +
  194 + public void setGenType(String genType)
  195 + {
  196 + this.genType = genType;
  197 + }
  198 +
  199 + public String getGenPath()
  200 + {
  201 + return genPath;
  202 + }
  203 +
  204 + public void setGenPath(String genPath)
  205 + {
  206 + this.genPath = genPath;
  207 + }
  208 +
183 public GenTableColumn getPkColumn() 209 public GenTableColumn getPkColumn()
184 { 210 {
185 return pkColumn; 211 return pkColumn;
1 package com.ruoyi.generator.service; 1 package com.ruoyi.generator.service;
2 2
3 import java.io.ByteArrayOutputStream; 3 import java.io.ByteArrayOutputStream;
  4 +import java.io.File;
4 import java.io.IOException; 5 import java.io.IOException;
5 import java.io.StringWriter; 6 import java.io.StringWriter;
6 import java.util.LinkedHashMap; 7 import java.util.LinkedHashMap;
@@ -21,9 +22,11 @@ import com.alibaba.fastjson.JSON; @@ -21,9 +22,11 @@ import com.alibaba.fastjson.JSON;
21 import com.alibaba.fastjson.JSONObject; 22 import com.alibaba.fastjson.JSONObject;
22 import com.ruoyi.common.constant.Constants; 23 import com.ruoyi.common.constant.Constants;
23 import com.ruoyi.common.constant.GenConstants; 24 import com.ruoyi.common.constant.GenConstants;
  25 +import com.ruoyi.common.core.text.CharsetKit;
24 import com.ruoyi.common.exception.CustomException; 26 import com.ruoyi.common.exception.CustomException;
25 import com.ruoyi.common.utils.SecurityUtils; 27 import com.ruoyi.common.utils.SecurityUtils;
26 import com.ruoyi.common.utils.StringUtils; 28 import com.ruoyi.common.utils.StringUtils;
  29 +import com.ruoyi.common.utils.file.FileUtils;
27 import com.ruoyi.generator.domain.GenTable; 30 import com.ruoyi.generator.domain.GenTable;
28 import com.ruoyi.generator.domain.GenTableColumn; 31 import com.ruoyi.generator.domain.GenTableColumn;
29 import com.ruoyi.generator.mapper.GenTableColumnMapper; 32 import com.ruoyi.generator.mapper.GenTableColumnMapper;
@@ -202,13 +205,13 @@ public class GenTableServiceImpl implements IGenTableService @@ -202,13 +205,13 @@ public class GenTableServiceImpl implements IGenTableService
202 } 205 }
203 206
204 /** 207 /**
205 - * 生成代码 208 + * 生成代码(下载方式)
206 * 209 *
207 * @param tableName 表名称 210 * @param tableName 表名称
208 * @return 数据 211 * @return 数据
209 */ 212 */
210 @Override 213 @Override
211 - public byte[] generatorCode(String tableName) 214 + public byte[] downloadCode(String tableName)
212 { 215 {
213 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 216 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
214 ZipOutputStream zip = new ZipOutputStream(outputStream); 217 ZipOutputStream zip = new ZipOutputStream(outputStream);
@@ -218,13 +221,55 @@ public class GenTableServiceImpl implements IGenTableService @@ -218,13 +221,55 @@ public class GenTableServiceImpl implements IGenTableService
218 } 221 }
219 222
220 /** 223 /**
221 - * 批量生成代码 224 + * 生成代码(自定义路径)
  225 + *
  226 + * @param tableName 表名称
  227 + * @return 数据
  228 + */
  229 + @Override
  230 + public void generatorCode(String tableName)
  231 + {
  232 + // 查询表信息
  233 + GenTable table = genTableMapper.selectGenTableByName(tableName);
  234 + // 查询列信息
  235 + List<GenTableColumn> columns = table.getColumns();
  236 + setPkColumn(table, columns);
  237 +
  238 + VelocityInitializer.initVelocity();
  239 +
  240 + VelocityContext context = VelocityUtils.prepareContext(table);
  241 +
  242 + // 获取模板列表
  243 + List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
  244 + for (String template : templates)
  245 + {
  246 + if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
  247 + {
  248 + // 渲染模板
  249 + StringWriter sw = new StringWriter();
  250 + Template tpl = Velocity.getTemplate(template, Constants.UTF8);
  251 + tpl.merge(context, sw);
  252 + try
  253 + {
  254 + String path = getGenPath(table, template);
  255 + FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
  256 + }
  257 + catch (IOException e)
  258 + {
  259 + throw new CustomException("渲染模板失败,表名:" + table.getTableName());
  260 + }
  261 + }
  262 + }
  263 + }
  264 +
  265 + /**
  266 + * 批量生成代码(下载方式)
222 * 267 *
223 * @param tableNames 表数组 268 * @param tableNames 表数组
224 * @return 数据 269 * @return 数据
225 */ 270 */
226 @Override 271 @Override
227 - public byte[] generatorCode(String[] tableNames) 272 + public byte[] downloadCode(String[] tableNames)
228 { 273 {
229 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 274 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
230 ZipOutputStream zip = new ZipOutputStream(outputStream); 275 ZipOutputStream zip = new ZipOutputStream(outputStream);
@@ -347,4 +392,21 @@ public class GenTableServiceImpl implements IGenTableService @@ -347,4 +392,21 @@ public class GenTableServiceImpl implements IGenTableService
347 genTable.setParentMenuName(parentMenuName); 392 genTable.setParentMenuName(parentMenuName);
348 } 393 }
349 } 394 }
  395 +
  396 + /**
  397 + * 获取代码生成地址
  398 + *
  399 + * @param table 业务表信息
  400 + * @param template 模板文件路径
  401 + * @return 生成地址
  402 + */
  403 + public static String getGenPath(GenTable table, String template)
  404 + {
  405 + String genPath = table.getGenPath();
  406 + if (StringUtils.equals(genPath, "/"))
  407 + {
  408 + return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
  409 + }
  410 + return genPath + File.separator + VelocityUtils.getFileName(template, table);
  411 + }
350 } 412 }
@@ -75,20 +75,28 @@ public interface IGenTableService @@ -75,20 +75,28 @@ public interface IGenTableService
75 public Map<String, String> previewCode(Long tableId); 75 public Map<String, String> previewCode(Long tableId);
76 76
77 /** 77 /**
78 - * 生成代码 78 + * 生成代码(下载方式)
79 * 79 *
80 * @param tableName 表名称 80 * @param tableName 表名称
81 * @return 数据 81 * @return 数据
82 */ 82 */
83 - public byte[] generatorCode(String tableName); 83 + public byte[] downloadCode(String tableName);
84 84
85 /** 85 /**
86 - * 批量生成代码 86 + * 生成代码(自定义路径)
  87 + *
  88 + * @param tableName 表名称
  89 + * @return 数据
  90 + */
  91 + public void generatorCode(String tableName);
  92 +
  93 + /**
  94 + * 批量生成代码(下载方式)
87 * 95 *
88 * @param tableNames 表数组 96 * @param tableNames 表数组
89 * @return 数据 97 * @return 数据
90 */ 98 */
91 - public byte[] generatorCode(String[] tableNames); 99 + public byte[] downloadCode(String[] tableNames);
92 100
93 /** 101 /**
94 * 修改保存参数校验 102 * 修改保存参数校验
@@ -15,6 +15,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -15,6 +15,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
15 <result property="businessName" column="business_name" /> 15 <result property="businessName" column="business_name" />
16 <result property="functionName" column="function_name" /> 16 <result property="functionName" column="function_name" />
17 <result property="functionAuthor" column="function_author" /> 17 <result property="functionAuthor" column="function_author" />
  18 + <result property="genType" column="gen_type" />
  19 + <result property="genPath" column="gen_path" />
18 <result property="options" column="options" /> 20 <result property="options" column="options" />
19 <result property="createBy" column="create_by" /> 21 <result property="createBy" column="create_by" />
20 <result property="createTime" column="create_time" /> 22 <result property="createTime" column="create_time" />
@@ -50,7 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -50,7 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
50 </resultMap> 52 </resultMap>
51 53
52 <sql id="selectGenTableVo"> 54 <sql id="selectGenTableVo">
53 - select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, options, create_by, create_time, update_by, update_time, remark from gen_table 55 + select table_id, table_name, table_comment, 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
54 </sql> 56 </sql>
55 57
56 <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> 58 <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
@@ -106,7 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -106,7 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
106 </select> 108 </select>
107 109
108 <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> 110 <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
109 - SELECT t.table_id, t.table_name, t.table_comment, 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, 111 + SELECT t.table_id, t.table_name, t.table_comment, 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,
110 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 112 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
111 FROM gen_table t 113 FROM gen_table t
112 LEFT JOIN gen_table_column c ON t.table_id = c.table_id 114 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
@@ -114,7 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -114,7 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
114 </select> 116 </select>
115 117
116 <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> 118 <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
117 - SELECT t.table_id, t.table_name, t.table_comment, 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, 119 + SELECT t.table_id, t.table_name, t.table_comment, 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,
118 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 120 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
119 FROM gen_table t 121 FROM gen_table t
120 LEFT JOIN gen_table_column c ON t.table_id = c.table_id 122 LEFT JOIN gen_table_column c ON t.table_id = c.table_id
@@ -132,6 +134,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -132,6 +134,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
132 <if test="businessName != null and businessName != ''">business_name,</if> 134 <if test="businessName != null and businessName != ''">business_name,</if>
133 <if test="functionName != null and functionName != ''">function_name,</if> 135 <if test="functionName != null and functionName != ''">function_name,</if>
134 <if test="functionAuthor != null and functionAuthor != ''">function_author,</if> 136 <if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
  137 + <if test="genType != null and genType != ''">gen_type,</if>
  138 + <if test="genPath != null and genPath != ''">gen_path,</if>
135 <if test="remark != null and remark != ''">remark,</if> 139 <if test="remark != null and remark != ''">remark,</if>
136 <if test="createBy != null and createBy != ''">create_by,</if> 140 <if test="createBy != null and createBy != ''">create_by,</if>
137 create_time 141 create_time
@@ -145,6 +149,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -145,6 +149,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
145 <if test="businessName != null and businessName != ''">#{businessName},</if> 149 <if test="businessName != null and businessName != ''">#{businessName},</if>
146 <if test="functionName != null and functionName != ''">#{functionName},</if> 150 <if test="functionName != null and functionName != ''">#{functionName},</if>
147 <if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if> 151 <if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
  152 + <if test="genType != null and genType != ''">#{genType},</if>
  153 + <if test="genPath != null and genPath != ''">#{genPath},</if>
148 <if test="remark != null and remark != ''">#{remark},</if> 154 <if test="remark != null and remark != ''">#{remark},</if>
149 <if test="createBy != null and createBy != ''">#{createBy},</if> 155 <if test="createBy != null and createBy != ''">#{createBy},</if>
150 sysdate() 156 sysdate()
@@ -158,6 +164,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -158,6 +164,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
158 <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> 164 <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
159 <if test="className != null and className != ''">class_name = #{className},</if> 165 <if test="className != null and className != ''">class_name = #{className},</if>
160 <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> 166 <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
  167 + <if test="genType != null and genType != ''">gen_type = #{genType},</if>
  168 + <if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
161 <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if> 169 <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
162 <if test="packageName != null and packageName != ''">package_name = #{packageName},</if> 170 <if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
163 <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if> 171 <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
@@ -42,6 +42,7 @@ export function importTable(data) { @@ -42,6 +42,7 @@ export function importTable(data) {
42 params: data 42 params: data
43 }) 43 })
44 } 44 }
  45 +
45 // 预览生成代码 46 // 预览生成代码
46 export function previewTable(tableId) { 47 export function previewTable(tableId) {
47 return request({ 48 return request({
@@ -49,6 +50,7 @@ export function previewTable(tableId) { @@ -49,6 +50,7 @@ export function previewTable(tableId) {
49 method: 'get' 50 method: 'get'
50 }) 51 })
51 } 52 }
  53 +
52 // 删除表数据 54 // 删除表数据
53 export function delTable(tableId) { 55 export function delTable(tableId) {
54 return request({ 56 return request({
@@ -57,3 +59,11 @@ export function delTable(tableId) { @@ -57,3 +59,11 @@ export function delTable(tableId) {
57 }) 59 })
58 } 60 }
59 61
  62 +// 生成代码(自定义路径)
  63 +export function genCode(tableName) {
  64 + return request({
  65 + url: '/tool/gen/genCode/' + tableName,
  66 + method: 'get'
  67 + })
  68 +}
  69 +
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <span slot="label">生成模板</span> 6 <span slot="label">生成模板</span>
7 <el-select v-model="info.tplCategory"> 7 <el-select v-model="info.tplCategory">
8 <el-option label="单表(增删改查)" value="crud" /> 8 <el-option label="单表(增删改查)" value="crud" />
9 - <el-option label="树表(增删改查)" value="tree"/> 9 + <el-option label="树表(增删改查)" value="tree" />
10 </el-select> 10 </el-select>
11 </el-form-item> 11 </el-form-item>
12 </el-col> 12 </el-col>
@@ -60,14 +60,56 @@ @@ -60,14 +60,56 @@
60 </el-col> 60 </el-col>
61 61
62 <el-col :span="12"> 62 <el-col :span="12">
63 - <el-form-item prop="functionName"> 63 + <el-form-item>
64 <span slot="label"> 64 <span slot="label">
65 上级菜单 65 上级菜单
66 <el-tooltip content="分配到指定菜单下,例如 系统管理" placement="top"> 66 <el-tooltip content="分配到指定菜单下,例如 系统管理" placement="top">
67 <i class="el-icon-question"></i> 67 <i class="el-icon-question"></i>
68 </el-tooltip> 68 </el-tooltip>
69 </span> 69 </span>
70 - <treeselect :append-to-body="true" v-model="info.parentMenuId" :options="menus" :normalizer="normalizer" :show-count="true" placeholder="请选择系统菜单"/> 70 + <treeselect
  71 + :append-to-body="true"
  72 + v-model="info.parentMenuId"
  73 + :options="menus"
  74 + :normalizer="normalizer"
  75 + :show-count="true"
  76 + placeholder="请选择系统菜单"
  77 + />
  78 + </el-form-item>
  79 + </el-col>
  80 +
  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'">
  95 + <el-form-item prop="genPath">
  96 + <span slot="label">
  97 + 自定义路径
  98 + <el-tooltip content="填写磁盘绝对路径,若不填写,则生成到当前Web项目下" placement="top">
  99 + <i class="el-icon-question"></i>
  100 + </el-tooltip>
  101 + </span>
  102 + <el-input v-model="info.genPath">
  103 + <el-dropdown slot="append">
  104 + <el-button type="primary">
  105 + 最近路径快速选择
  106 + <i class="el-icon-arrow-down el-icon--right"></i>
  107 + </el-button>
  108 + <el-dropdown-menu slot="dropdown">
  109 + <el-dropdown-item @click.native="info.genPath = '/'">恢复默认的生成基础路径</el-dropdown-item>
  110 + </el-dropdown-menu>
  111 + </el-dropdown>
  112 + </el-input>
71 </el-form-item> 113 </el-form-item>
72 </el-col> 114 </el-col>
73 </el-row> 115 </el-row>
@@ -165,7 +207,7 @@ export default { @@ -165,7 +207,7 @@ export default {
165 ], 207 ],
166 functionName: [ 208 functionName: [
167 { required: true, message: "请输入生成功能名", trigger: "blur" } 209 { required: true, message: "请输入生成功能名", trigger: "blur" }
168 - ] 210 + ],
169 } 211 }
170 }; 212 };
171 }, 213 },
@@ -166,7 +166,7 @@ @@ -166,7 +166,7 @@
166 </template> 166 </template>
167 167
168 <script> 168 <script>
169 -import { listTable, previewTable, delTable } from "@/api/tool/gen"; 169 +import { listTable, previewTable, delTable, genCode } from "@/api/tool/gen";
170 import importTable from "./importTable"; 170 import importTable from "./importTable";
171 import { downLoadZip } from "@/utils/zipdownload"; 171 import { downLoadZip } from "@/utils/zipdownload";
172 export default { 172 export default {
@@ -241,7 +241,13 @@ export default { @@ -241,7 +241,13 @@ export default {
241 this.msgError("请选择要生成的数据"); 241 this.msgError("请选择要生成的数据");
242 return; 242 return;
243 } 243 }
  244 + if(row.genType === "1") {
  245 + genCode(row.tableName).then(response => {
  246 + this.msgSuccess("成功生成到自定义路径:" + row.genPath);
  247 + });
  248 + } else {
244 downLoadZip("/tool/gen/batchGenCode?tables=" + tableNames, "ruoyi"); 249 downLoadZip("/tool/gen/batchGenCode?tables=" + tableNames, "ruoyi");
  250 + }
245 }, 251 },
246 /** 打开导入表弹窗 */ 252 /** 打开导入表弹窗 */
247 openImportTable() { 253 openImportTable() {
@@ -635,6 +635,8 @@ create table gen_table ( @@ -635,6 +635,8 @@ create table gen_table (
635 business_name varchar(30) comment '生成业务名', 635 business_name varchar(30) comment '生成业务名',
636 function_name varchar(50) comment '生成功能名', 636 function_name varchar(50) comment '生成功能名',
637 function_author varchar(50) comment '生成功能作者', 637 function_author varchar(50) comment '生成功能作者',
  638 + gen_type char(1) default '0' comment '生成代码方式(0zip压缩包 1自定义路径)',
  639 + gen_path varchar(200) default '/' comment '生成路径(不填默认项目路径)',
638 options varchar(1000) comment '其它生成选项', 640 options varchar(1000) comment '其它生成选项',
639 create_by varchar(64) default '' comment '创建者', 641 create_by varchar(64) default '' comment '创建者',
640 create_time datetime comment '创建时间', 642 create_time datetime comment '创建时间',