diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java index fe07f59b1..ea9cebf84 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.web.controller.BaseController; @@ -104,12 +105,12 @@ public class GenController extends BaseController @RequiresPermissions("tool:gen:import") @Log(title = "代码生成", businessType = BusinessType.IMPORT) @PostMapping("/importTable") - public AjaxResult importTableSave(String tables) + public AjaxResult importTableSave(@RequestParam("tables") String tables, @RequestParam("tplWebType") String tplWebType) { String[] tableNames = Convert.toStrArray(tables); // 查询表信息 List tableList = genTableService.selectDbTableListByNames(tableNames); - genTableService.importGenTable(tableList); + genTableService.importGenTable(tableList, tplWebType); return success(); } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java index 43b7d0dd7..657cfe75b 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java @@ -41,7 +41,7 @@ public class GenTable extends BaseEntity /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */ private String tplCategory; - /** 前端类型(element-ui模版 element-plus模版) */ + /** 前端类型(element-ui模版 element-plus模版 element-plus-typescript模版) */ private String tplWebType; /** 生成包路径 */ @@ -267,6 +267,7 @@ public class GenTable extends BaseEntity { this.subTable = subTable; } + public List getColumns() { return columns; @@ -346,6 +347,7 @@ public class GenTable extends BaseEntity { return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory); } + public boolean isTree() { return isTree(this.tplCategory); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java index 6031be171..f6be881d9 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java @@ -157,7 +157,7 @@ public class GenTableServiceImpl implements IGenTableService */ @Override @Transactional(rollbackFor = Exception.class) - public void importGenTable(List tableList) + public void importGenTable(List tableList, String tplWebType) { String operName = SecurityUtils.getUsername(); try @@ -165,6 +165,7 @@ public class GenTableServiceImpl implements IGenTableService for (GenTable table : tableList) { String tableName = table.getTableName(); + table.setTplWebType(tplWebType); GenUtils.initTable(table, operName); int row = genTableMapper.insertGenTable(table); if (row > 0) diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java index 3d6e0ff69..3237b11c9 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java @@ -70,8 +70,9 @@ public interface IGenTableService * 导入表结构 * * @param tableList 导入表列表 + * @param tplWebType 前端类型 */ - public void importGenTable(List tableList); + public void importGenTable(List tableList, String tplWebType); /** * 预览代码 diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java index 2c8dcb1ca..574122757 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java @@ -29,6 +29,12 @@ public class VelocityUtils /** 默认上级菜单,系统工具 */ private static final String DEFAULT_PARENT_MENU_ID = "3"; + /** Vue3 Element Plus 模版 */ + private static final String ELEMENT_PLUS = "element-plus"; + + /** Vue3 Element Plus TypeScript 模版 */ + private static final String ELEMENT_PLUS_TYPESSRIPT = "element-plus-typescript"; + /** * 设置模板变量信息 * @@ -130,10 +136,16 @@ public class VelocityUtils public static List getTemplateList(String tplCategory, String tplWebType) { String useWebType = "vm/vue"; - if ("element-plus".equals(tplWebType)) + String apiTemplate = "vm/js/api.js.vm"; + if (StringUtils.equals(ELEMENT_PLUS, tplWebType)) { useWebType = "vm/vue/v3"; } + else if (StringUtils.equals(ELEMENT_PLUS_TYPESSRIPT, tplWebType)) + { + useWebType = "vm/vue/v3ts"; + apiTemplate = "vm/ts/api.ts.vm"; + } List templates = new ArrayList(); templates.add("vm/java/domain.java.vm"); templates.add("vm/java/mapper.java.vm"); @@ -142,7 +154,12 @@ public class VelocityUtils templates.add("vm/java/controller.java.vm"); templates.add("vm/xml/mapper.xml.vm"); templates.add("vm/sql/sql.vm"); - templates.add("vm/js/api.js.vm"); + templates.add(apiTemplate); + if (StringUtils.equals(ELEMENT_PLUS_TYPESSRIPT, tplWebType)) + { + templates.add("vm/ts/type.ts.vm"); + templates.add("vm/ts/index.ts.vm"); + } if (GenConstants.TPL_CRUD.equals(tplCategory)) { templates.add(useWebType + "/index.vue.vm"); @@ -215,6 +232,18 @@ public class VelocityUtils { fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); } + else if (template.contains("api.ts.vm")) + { + fileName = StringUtils.format("{}/api/{}/{}.ts", vuePath, moduleName, businessName); + } + else if (template.contains("type.ts.vm")) + { + fileName = StringUtils.format("{}/types/api/{}/{}.ts", vuePath, moduleName, businessName); + } + else if (template.contains("index.ts.vm")) + { + fileName = StringUtils.format("{}/types/api/index-bak.ts", vuePath); + } else if (template.contains("index.vue.vm")) { fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm index 363979bdb..0d07ac04e 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm @@ -1,7 +1,6 @@ package ${packageName}.controller; import java.util.List; -import java.io.IOException; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/api.ts.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/api.ts.vm new file mode 100644 index 000000000..8ed5122bb --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/api.ts.vm @@ -0,0 +1,51 @@ +import request from '@/utils/request' +import type { AjaxResult, TableDataInfo, ${BusinessName}QueryParams, ${ClassName} } from '@/types' + +// 查询${functionName}列表 +#if($table.tree) +export function list${BusinessName}(query?: ${BusinessName}QueryParams): Promise> { +#else +export function list${BusinessName}(query: ${BusinessName}QueryParams): Promise> { +#end + return request({ + url: '/${moduleName}/${businessName}/list', + method: 'get', + params: query + }) +} + +// 查询${functionName}详细 +export function get${BusinessName}(${pkColumn.javaField}: number): Promise> { + return request({ + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, + method: 'get' + }) +} + +// 新增${functionName} +export function add${BusinessName}(data: ${ClassName}): Promise { + return request({ + url: '/${moduleName}/${businessName}', + method: 'post', + data: data + }) +} + +// 修改${functionName} +export function update${BusinessName}(data: ${ClassName}): Promise { + return request({ + url: '/${moduleName}/${businessName}', + method: 'put', + data: data + }) +} + +// 删除${functionName} +export function del${BusinessName}(${pkColumn.javaField}: number | number[]): Promise { + return request({ + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, + method: 'delete' + }) +} + + diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/index.ts.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/index.ts.vm new file mode 100644 index 000000000..e51ef151e --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/index.ts.vm @@ -0,0 +1,9 @@ +/** + * API 类型统一导出 + */ +.... + +// 防止覆盖,需手动追加下面代码到index.ts文件中,追加好后此文件可删除 + +// ${moduleName} 模块 +export * from "./${moduleName}/${businessName}"; \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/type.ts.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/type.ts.vm new file mode 100644 index 000000000..fff1d4cab --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/ts/type.ts.vm @@ -0,0 +1,51 @@ +import type { PageDomain, BaseEntity } from "../common"; + +/** ${functionName}配置分页查询参数 */ +export interface ${BusinessName}QueryParams extends PageDomain { +#foreach($column in $columns) +#if($column.query) +#set($type = "string") +#if($column.javaType == "Long" || $column.javaType == "Integer") + #set($type = "number") +#elseif($column.javaType == "Boolean") + #set($type = "boolean") +#end + /** ${column.columnComment} */ + ${column.javaField}?: ${type}; +#end +#end +} + +/** ${functionName}配置信息 */ +export interface ${ClassName} extends BaseEntity { +#foreach($column in $columns) +#set($type = "string") +#if($column.javaType == "Long" || $column.javaType == "Integer") + #set($type = "number") +#elseif($column.javaType == "Boolean") + #set($type = "boolean") +#end + /** ${column.columnComment} */ + ${column.javaField}?: ${type}; +#end +#if($table.sub) + /** $table.subTable.functionName信息 */ + ${subclassName}List?: ${subClassName}[]; +#end +} +#if($table.sub) + +/** ${subTable.functionName}配置信息 */ +export interface ${subClassName} extends BaseEntity { +#foreach ($column in $subTable.columns) +#set($type = "string") +#if($column.javaType == "Long" || $column.javaType == "Integer") + #set($type = "number") +#elseif($column.javaType == "Boolean") + #set($type = "boolean") +#end + /** ${column.columnComment} */ + ${column.javaField}?: ${type}; +#end +} +#end diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3ts/index-tree.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3ts/index-tree.vue.vm new file mode 100644 index 000000000..f1bc586f9 --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3ts/index-tree.vue.vm @@ -0,0 +1,476 @@ + + + diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3ts/index.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3ts/index.vue.vm new file mode 100644 index 000000000..d0fa278aa --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3ts/index.vue.vm @@ -0,0 +1,594 @@ + + +