From 790736c98d8a7d6d1194d1e642946bc8219edcfb Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 12 Apr 2026 10:40:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E8=AF=A6=E6=83=85=E9=A1=B5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/constant/GenConstants.java | 3 + .../java/com/ruoyi/gen/domain/GenTable.java | 13 +++ .../gen/service/GenTableServiceImpl.java | 10 ++- .../com/ruoyi/gen/util/VelocityUtils.java | 39 ++++++++- .../main/resources/vm/vue/index-tree.vue.vm | 25 ++++++ .../src/main/resources/vm/vue/index.vue.vm | 25 ++++++ .../resources/vm/vue/v3/index-tree.vue.vm | 23 ++++- .../src/main/resources/vm/vue/v3/index.vue.vm | 27 ++++-- .../src/main/resources/vm/vue/v3/view.vue.vm | 83 ++++++++++++++++++ .../resources/vm/vue/v3ts/index-tree.vue.vm | 21 ++++- .../main/resources/vm/vue/v3ts/index.vue.vm | 25 +++++- .../main/resources/vm/vue/v3ts/view.vue.vm | 84 ++++++++++++++++++ .../src/main/resources/vm/vue/view.vue.vm | 86 +++++++++++++++++++ ruoyi-ui/src/views/tool/gen/editTable.vue | 1 + ruoyi-ui/src/views/tool/gen/genInfoForm.vue | 9 +- 15 files changed, 453 insertions(+), 21 deletions(-) create mode 100644 ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3/view.vue.vm create mode 100644 ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/v3ts/view.vue.vm create mode 100644 ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/view.vue.vm diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java index b008e65e2..e867dfced 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java @@ -31,6 +31,9 @@ public class GenConstants /** 上级菜单名称字段 */ public static final String PARENT_MENU_NAME = "parentMenuName"; + /** 生成详情页开关 */ + public static final String GEN_VIEW = "genView"; + /** 数据库字符串类型 */ public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" }; 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 f682cfa03..1d46fc4db 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 @@ -101,6 +101,9 @@ public class GenTable extends BaseEntity /** 上级菜单名称字段 */ private String parentMenuName; + /** 是否生成详情页 */ + private boolean isView; + public Long getTableId() { return tableId; @@ -351,6 +354,16 @@ public class GenTable extends BaseEntity this.parentMenuName = parentMenuName; } + public boolean isView() + { + return isView; + } + + public void setView(boolean isView) + { + this.isView = isView; + } + public boolean isSub() { return isSub(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 30af466dc..4498e1328 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 @@ -209,7 +209,7 @@ public class GenTableServiceImpl implements IGenTableService VelocityContext context = VelocityUtils.prepareContext(table); // 获取模板列表 - List templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); + List templates = VelocityUtils.getTemplateList(table); for (String template : templates) { // 渲染模板 @@ -253,10 +253,10 @@ public class GenTableServiceImpl implements IGenTableService VelocityContext context = VelocityUtils.prepareContext(table); // 获取模板列表 - List templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); + List templates = VelocityUtils.getTemplateList(table); for (String template : templates) { - if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) + if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "api.ts.vm", "type.ts.vm", "index.ts.vm", "index.vue.vm", "index-tree.vue.vm", "view.vue.vm")) { // 渲染模板 StringWriter sw = new StringWriter(); @@ -371,7 +371,7 @@ public class GenTableServiceImpl implements IGenTableService VelocityContext context = VelocityUtils.prepareContext(table); // 获取模板列表 - List templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); + List templates = VelocityUtils.getTemplateList(table); for (String template : templates) { // 渲染模板 @@ -524,12 +524,14 @@ public class GenTableServiceImpl implements IGenTableService String treeName = paramsObj.getString(GenConstants.TREE_NAME); Long parentMenuId = paramsObj.getLongValue(GenConstants.PARENT_MENU_ID); String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); + boolean isView = paramsObj.getBooleanValue(GenConstants.GEN_VIEW); genTable.setTreeCode(treeCode); genTable.setTreeParentCode(treeParentCode); genTable.setTreeName(treeName); genTable.setParentMenuId(parentMenuId); genTable.setParentMenuName(parentMenuName); + genTable.setView(isView); } } 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 132af1c9a..5704b073b 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 @@ -14,7 +14,7 @@ import com.ruoyi.gen.domain.GenTable; import com.ruoyi.gen.domain.GenTableColumn; /** - * 模板工具类 + * 模板处理工具类 * * @author ruoyi */ @@ -68,6 +68,7 @@ public class VelocityUtils velocityContext.put("columns", genTable.getColumns()); velocityContext.put("table", genTable); velocityContext.put("dicts", getDicts(genTable)); + setExtensionsContext(velocityContext, genTable.getOptions()); setMenuVelocityContext(velocityContext, genTable); if (GenConstants.TPL_TREE.equals(tplCategory)) { @@ -80,6 +81,13 @@ public class VelocityUtils return velocityContext; } + public static void setExtensionsContext(VelocityContext context, String options) + { + JSONObject paramsObj = JSONObject.parseObject(options); + boolean genView = genView(paramsObj); + context.put("genView", genView); + } + public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { String options = genTable.getOptions(); @@ -134,8 +142,12 @@ public class VelocityUtils * @param tplWebType 前端类型 * @return 模板列表 */ - public static List getTemplateList(String tplCategory, String tplWebType) + public static List getTemplateList(GenTable table) { + String tplWebType = table.getTplWebType(); + String tplCategory = table.getTplCategory(); + JSONObject paramsObj = JSONObject.parseObject(table.getOptions()); + boolean isView = genView(paramsObj); String useWebType = "vm/vue"; String apiTemplate = "vm/js/api.js.vm"; if (StringUtils.equals(ELEMENT_PLUS, tplWebType)) @@ -174,6 +186,10 @@ public class VelocityUtils templates.add(useWebType + "/index.vue.vm"); templates.add("vm/java/sub-domain.java.vm"); } + if (isView) + { + templates.add(useWebType + "/view.vue.vm"); + } return templates; } @@ -253,6 +269,10 @@ public class VelocityUtils { fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); } + else if (template.contains("view.vue.vm")) + { + fileName = StringUtils.format("{}/views/{}/{}/view.vue", vuePath, moduleName, businessName); + } return fileName; } @@ -394,6 +414,21 @@ public class VelocityUtils return StringUtils.EMPTY; } + /** + * 扩展功能/生成详情页 + * + * @param paramsObj 生成其他选项 + * @return 是否生成详细页 + */ + public static boolean genView(JSONObject paramsObj) + { + if (StringUtils.isNotNull(paramsObj) && paramsObj.containsKey(GenConstants.GEN_VIEW)) + { + return paramsObj.getBoolean(GenConstants.GEN_VIEW); + } + return false; + } + /** * 获取树名称 * diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm index 9cd31a4fa..b26d70dd5 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm @@ -139,6 +139,15 @@ #end