From 86cb7555ebfd6c3e03aeeaf310df7523abcff8ce Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Thu, 02 Apr 2026 11:08:38 +0800
Subject: [PATCH] 代码生成支持表单布局选项
---
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 51 insertions(+), 2 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..132af1c 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 @@
/** 默认上级菜单,系统工具 */
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));
@@ -130,9 +137,15 @@
public static List<String> 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<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm");
@@ -142,7 +155,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");
@@ -214,6 +232,18 @@
else if (template.contains("api.js.vm"))
{
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"))
{
@@ -405,4 +435,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