From 790736c98d8a7d6d1194d1e642946bc8219edcfb Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Sun, 12 Apr 2026 10:40:37 +0800
Subject: [PATCH] 新增代码生成详情页功能
---
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java | 92 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 88 insertions(+), 4 deletions(-)
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 2c8dcb1..5704b07 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.GenTableColumn;
/**
- * 模板工具类
+ * 模板处理工具类
*
* @author ruoyi
*/
@@ -28,6 +28,12 @@
/** 默认上级菜单,系统工具 */
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";
/**
* 设置模板变量信息
@@ -54,6 +60,7 @@
velocityContext.put("basePackage", getPackagePrefix(packageName));
velocityContext.put("packageName", packageName);
velocityContext.put("author", genTable.getFunctionAuthor());
+ velocityContext.put("colSpan", getColSpan(genTable.getFormColNum()));
velocityContext.put("datetime", DateUtils.getDate());
velocityContext.put("pkColumn", genTable.getPkColumn());
velocityContext.put("importList", getImportList(genTable));
@@ -61,6 +68,7 @@
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))
{
@@ -71,6 +79,13 @@
setSubVelocityContext(velocityContext, genTable);
}
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)
@@ -127,12 +142,22 @@
* @param tplWebType 前端类型
* @return 模板列表
*/
- public static List<String> getTemplateList(String tplCategory, String tplWebType)
+ public static List<String> 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";
- 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<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm");
@@ -142,7 +167,12 @@
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");
@@ -155,6 +185,10 @@
{
templates.add(useWebType + "/index.vue.vm");
templates.add("vm/java/sub-domain.java.vm");
+ }
+ if (isView)
+ {
+ templates.add(useWebType + "/view.vue.vm");
}
return templates;
}
@@ -215,6 +249,18 @@
{
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);
@@ -222,6 +268,10 @@
else if (template.contains("index-tree.vue.vm"))
{
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;
}
@@ -365,6 +415,21 @@
}
/**
+ * 扩展功能/生成详情页
+ *
+ * @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;
+ }
+
+ /**
* 获取树名称
*
* @param paramsObj 生成其他选项
@@ -405,4 +470,23 @@
}
return num;
}
+
+ /**
+ * 获取表单 el-col span
+ *
+ * @param formColNum 表单布局方式(1单列 2双列 3三列)
+ * @return span 数值字符串
+ */
+ public static String getColSpan(int formColNum)
+ {
+ if (formColNum == 2)
+ {
+ return "12";
+ }
+ else if (formColNum == 3)
+ {
+ return "8";
+ }
+ return "24";
+ }
}
--
Gitblit v1.9.3