1. 新增代码生成器支持生成时预设基础封装组件(查询、表格、列表、编辑弹窗)
2. 新增模块与 Server 新增脚本方法
This commit is contained in:
@@ -0,0 +1,241 @@
|
||||
package cn.iocoder.yudao.framework.test.core.ut;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Scanner;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Yudao 模块代码生成器
|
||||
*
|
||||
* 使用方法:
|
||||
* 1. 在 IDE 中,右键运行 {@link #main(String[])} 方法
|
||||
* 2. 根据提示,输入模块名,例如 "order"
|
||||
* 3. 根据提示,输入作者名,例如 "yudao"
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public class ModuleGenerator {
|
||||
|
||||
private static final String TEMPLATE_PATH = "yudao-module-template";
|
||||
private static final String BASE_PACKAGE = "cn.iocoder.yudao.module.";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// 1. 获取用户输入
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("请输入新模块的名称(支持多个模块,用逗号分割,例如:order,userManagement,payment): ");
|
||||
String moduleNames = scanner.nextLine();
|
||||
System.out.print("请输入作者名称(例如:yudao): ");
|
||||
String author = scanner.nextLine();
|
||||
scanner.close();
|
||||
|
||||
// 分割模块名
|
||||
String[] modules = moduleNames.split(",");
|
||||
|
||||
// 2. 定义项目根路径
|
||||
Path projectRoot = Paths.get("").toAbsolutePath();
|
||||
Path templateDir = projectRoot.resolve(TEMPLATE_PATH);
|
||||
|
||||
if (!Files.exists(templateDir)) {
|
||||
System.err.println("错误:模板目录不存在: " + templateDir);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 批量创建模块
|
||||
for (String moduleName : modules) {
|
||||
moduleName = moduleName.trim(); // 去除空格
|
||||
if (moduleName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("\n=== 开始创建模块: " + moduleName + " ===");
|
||||
createSingleModule(templateDir, projectRoot, moduleName, author);
|
||||
}
|
||||
|
||||
System.out.println("\n所有模块创建完成!");
|
||||
System.out.println("请手动将以下模块添加到根 pom.xml 的 <modules> 标签中:");
|
||||
for (String moduleName : modules) {
|
||||
moduleName = moduleName.trim();
|
||||
if (!moduleName.isEmpty()) {
|
||||
String dashModuleName = camelToKebabCase(moduleName);
|
||||
System.out.println("<module>yudao-module-" + dashModuleName + "</module>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void createSingleModule(Path templateDir, Path projectRoot, String moduleName, String author) throws IOException {
|
||||
String packageName = moduleName.replace("-", "");
|
||||
String capitalizedModuleName = capitalize(packageName);
|
||||
|
||||
// 将小驼峰转换为短横线分割的模块名
|
||||
String dashModuleName = camelToKebabCase(moduleName);
|
||||
|
||||
// 定义新模块路径
|
||||
Path newModuleDir = projectRoot.resolve("yudao-module-" + dashModuleName);
|
||||
|
||||
if (Files.exists(newModuleDir)) {
|
||||
System.err.println("警告:模块 '" + dashModuleName + "' 已存在于 " + newModuleDir + ",跳过创建");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("将在以下位置创建新模块: " + newModuleDir);
|
||||
|
||||
// 复制并处理文件
|
||||
copyAndProcessDirectory(templateDir, newModuleDir, dashModuleName, packageName, capitalizedModuleName, author);
|
||||
|
||||
// 创建启动类
|
||||
createApplicationClass(newModuleDir, dashModuleName, packageName, capitalizedModuleName, author);
|
||||
|
||||
System.out.println("模块 '" + dashModuleName + "' 创建成功!");
|
||||
}
|
||||
|
||||
private static void copyAndProcessDirectory(Path sourceDir, Path targetDir, String moduleName, String packageName, String capitalizedModuleName, String author) throws IOException {
|
||||
try (Stream<Path> stream = Files.walk(sourceDir)) {
|
||||
stream.filter(path -> shouldIncludePath(sourceDir.relativize(path)))
|
||||
.forEach(sourcePath -> {
|
||||
try {
|
||||
Path relativePath = sourceDir.relativize(sourcePath);
|
||||
Path targetPath = targetDir.resolve(relativePath);
|
||||
String targetPathStr = targetPath.toString();
|
||||
|
||||
// 替换路径中的 'template'
|
||||
targetPathStr = targetPathStr.replace("template", moduleName);
|
||||
// 替换包名路径
|
||||
targetPathStr = targetPathStr.replace(java.io.File.separator + "template" + java.io.File.separator, java.io.File.separator + packageName + java.io.File.separator);
|
||||
targetPath = Paths.get(targetPathStr);
|
||||
|
||||
if (Files.isDirectory(sourcePath)) {
|
||||
Files.createDirectories(targetPath);
|
||||
} else {
|
||||
// 确保父目录存在
|
||||
Files.createDirectories(targetPath.getParent());
|
||||
String content = new String(Files.readAllBytes(sourcePath));
|
||||
String newContent = processFileContent(content, sourcePath.getFileName().toString(), moduleName, packageName, capitalizedModuleName, author);
|
||||
Files.write(targetPath, newContent.getBytes());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("处理文件失败: " + sourcePath, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldIncludePath(Path relativePath) {
|
||||
String pathStr = relativePath.toString();
|
||||
|
||||
// 排除 target 目录
|
||||
if (pathStr.contains("target")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 排除 .flattened-pom.xml 文件
|
||||
if (pathStr.contains(".flattened-pom.xml")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果是根目录或者包含 example 的路径,则包含
|
||||
if (relativePath.getNameCount() <= 3) { // 根目录和基础包结构
|
||||
return true;
|
||||
}
|
||||
|
||||
// 只包含 example 相关的文件和目录
|
||||
return pathStr.contains("example") || pathStr.contains("ErrorCodeConstants");
|
||||
}
|
||||
|
||||
private static String processFileContent(String content, String fileName, String moduleName, String packageName, String capitalizedModuleName, String author) {
|
||||
// 如果是 ErrorCodeConstants 文件,特殊处理
|
||||
if (fileName.equals("ErrorCodeConstants.java")) {
|
||||
return processErrorCodeConstants(content, moduleName, packageName, author);
|
||||
}
|
||||
|
||||
return content.replace("yudao-module-template", "yudao-module-" + moduleName)
|
||||
.replace("cn.iocoder.yudao.module.template", BASE_PACKAGE + packageName)
|
||||
.replace("TemplateServerApplication", capitalizedModuleName + "ServerApplication")
|
||||
.replace("样例模块", moduleName + "模块")
|
||||
.replace("周迪", author) // 替换作者
|
||||
.replace("template", moduleName) // 最后替换纯 "template"
|
||||
.replace("Example", capitalize(moduleName) + "Example");
|
||||
}
|
||||
|
||||
private static String processErrorCodeConstants(String content, String moduleName, String packageName, String author) {
|
||||
// 构建新的 ErrorCodeConstants 内容,只保留基本结构,移除具体的错误码常量
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("package ").append(BASE_PACKAGE).append(packageName).append(".enums;\n\n");
|
||||
sb.append("import cn.iocoder.yudao.framework.common.exception.ErrorCode;\n\n");
|
||||
sb.append("/**\n");
|
||||
sb.append(" * ").append(moduleName).append(" 错误码枚举类\n");
|
||||
sb.append(" *\n");
|
||||
sb.append(" * ").append(moduleName).append(" 系统,使用 1-xxx-xxx-xxx 段\n");
|
||||
sb.append(" *\n");
|
||||
sb.append(" * @author ").append(author).append("\n");
|
||||
sb.append(" */\n");
|
||||
sb.append("public interface ErrorCodeConstants {\n\n");
|
||||
sb.append(" // ========== 示例模块 1-001-000-000 ==========\n");
|
||||
sb.append(" // ErrorCode EXAMPLE_NOT_EXISTS = new ErrorCode(1_001_000_001, \"示例不存在\");\n\n");
|
||||
sb.append("}\n");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建启动类
|
||||
*/
|
||||
private static void createApplicationClass(Path moduleDir, String dashModuleName, String packageName, String capitalizedModuleName, String author) throws IOException {
|
||||
// 创建启动类目录
|
||||
Path applicationDir = moduleDir.resolve("yudao-module-" + dashModuleName + "-server")
|
||||
.resolve("src/main/java/cn/iocoder/yudao/module/" + packageName);
|
||||
Files.createDirectories(applicationDir);
|
||||
|
||||
// 创建启动类文件
|
||||
Path applicationFile = applicationDir.resolve(capitalizedModuleName + "ServerApplication.java");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("package ").append(BASE_PACKAGE).append(packageName).append(";\n\n");
|
||||
sb.append("import org.springframework.boot.SpringApplication;\n");
|
||||
sb.append("import org.springframework.boot.autoconfigure.SpringBootApplication;\n\n");
|
||||
sb.append("/**\n");
|
||||
sb.append(" * ").append(dashModuleName).append(" 模块的启动类\n");
|
||||
sb.append(" *\n");
|
||||
sb.append(" * @author ").append(author).append("\n");
|
||||
sb.append(" */\n");
|
||||
sb.append("@SpringBootApplication\n");
|
||||
sb.append("public class ").append(capitalizedModuleName).append("ServerApplication {\n\n");
|
||||
sb.append(" public static void main(String[] args) {\n");
|
||||
sb.append(" SpringApplication.run(").append(capitalizedModuleName).append("ServerApplication.class, args);\n");
|
||||
sb.append(" }\n\n");
|
||||
sb.append("}\n");
|
||||
|
||||
Files.write(applicationFile, sb.toString().getBytes());
|
||||
System.out.println("创建启动类: " + applicationFile);
|
||||
}
|
||||
|
||||
private static String capitalize(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return str;
|
||||
}
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将小驼峰命名转换为短横线分割的命名
|
||||
* 例如:orderManagement -> order-management
|
||||
*/
|
||||
private static String camelToKebabCase(String camelCase) {
|
||||
if (camelCase == null || camelCase.isEmpty()) {
|
||||
return camelCase;
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < camelCase.length(); i++) {
|
||||
char c = camelCase.charAt(i);
|
||||
if (Character.isUpperCase(c) && i > 0) {
|
||||
result.append('-');
|
||||
}
|
||||
result.append(Character.toLowerCase(c));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package cn.iocoder.yudao.framework.test.core.ut;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Yudao Server 代码生成器
|
||||
*
|
||||
* 使用方法:
|
||||
* 1. 在 IDE 中,右键运行 {@link #main(String[])} 方法
|
||||
* 2. 根据提示,输入新 Server 的名称,例如 "demo-server"
|
||||
* 3. 根据提示,输入作者名,例如 "yudao"
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public class ServerGenerator {
|
||||
|
||||
private static final String TEMPLATE_PATH = "yudao-server";
|
||||
private static final String BASE_PACKAGE_PREFIX = "cn.iocoder.yudao.";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// 1. 获取用户输入
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("请输入新 Server 的基础名称(小写短横线,例如:demo): ");
|
||||
String baseName = scanner.nextLine();
|
||||
String serverName = baseName + "-server";
|
||||
System.out.print("请输入作者名称(例如:yudao): ");
|
||||
String author = scanner.nextLine();
|
||||
scanner.close();
|
||||
|
||||
// 2. 定义项目根路径
|
||||
// 注意:请在项目的根目录(例如 ztcloud)下运行该生成器
|
||||
Path projectRoot = Paths.get("").toAbsolutePath();
|
||||
Path templateDir = projectRoot.resolve(TEMPLATE_PATH);
|
||||
|
||||
if (!Files.exists(templateDir)) {
|
||||
System.err.println("错误:模板目录 '" + templateDir + "' 不存在。");
|
||||
System.err.println("请确保在项目根目录下运行此生成器。");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("\n=== 开始创建 Server: " + serverName + " ===");
|
||||
createSingleServer(templateDir, projectRoot, serverName, author);
|
||||
|
||||
System.out.println("\nServer '" + serverName + "' 创建成功!");
|
||||
System.out.println("请手动将以下模块添加到根 pom.xml 的 <modules> 标签中:");
|
||||
System.out.println("<module>" + serverName + "</module>");
|
||||
}
|
||||
|
||||
private static void createSingleServer(Path templateDir, Path projectRoot, String serverName, String author) throws IOException {
|
||||
String packageName = serverName.replace("-", "");
|
||||
String capitalizedName = toPascalCase(serverName);
|
||||
|
||||
// 定义新 Server 路径
|
||||
Path newServerDir = projectRoot.resolve(serverName);
|
||||
|
||||
if (Files.exists(newServerDir)) {
|
||||
System.err.println("警告:Server '" + serverName + "' 已存在于 '" + newServerDir + "',跳过创建。");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("将在以下位置创建新 Server: " + newServerDir);
|
||||
|
||||
// 复制并处理文件
|
||||
copyAndProcessDirectory(templateDir, newServerDir, serverName, packageName, capitalizedName, author);
|
||||
}
|
||||
|
||||
private static void copyAndProcessDirectory(Path sourceDir, Path targetDir, String serverName, String packageName, String capitalizedName, String author) throws IOException {
|
||||
try (Stream<Path> stream = Files.walk(sourceDir)) {
|
||||
stream.forEach(sourcePath -> {
|
||||
try {
|
||||
Path relativePath = sourceDir.relativize(sourcePath);
|
||||
if (!shouldIncludePath(relativePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理路径和文件名
|
||||
String javaPackagePath = "src" + java.io.File.separator + "main" + java.io.File.separator + "java" + java.io.File.separator
|
||||
+ "cn" + java.io.File.separator + "iocoder" + java.io.File.separator + "yudao" + java.io.File.separator;
|
||||
String targetPathStr = relativePath.toString()
|
||||
.replace(javaPackagePath + "server", javaPackagePath + packageName)
|
||||
.replace("YudaoServerApplication.java", capitalizedName + "Application.java");
|
||||
|
||||
Path targetPath = targetDir.resolve(targetPathStr);
|
||||
|
||||
if (Files.isDirectory(sourcePath)) {
|
||||
Files.createDirectories(targetPath);
|
||||
} else {
|
||||
Files.createDirectories(targetPath.getParent());
|
||||
String content = new String(Files.readAllBytes(sourcePath));
|
||||
String newContent = processFileContent(content, sourcePath.getFileName().toString(), serverName, packageName, capitalizedName, author);
|
||||
Files.write(targetPath, newContent.getBytes());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("处理文件失败: " + sourcePath, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldIncludePath(Path relativePath) {
|
||||
String pathStr = relativePath.toString();
|
||||
// 排除 target, .idea, .git 等目录和 .iml, .flattened-pom.xml 等文件
|
||||
return !pathStr.startsWith("target")
|
||||
&& !pathStr.startsWith(".idea")
|
||||
&& !pathStr.startsWith(".git")
|
||||
&& !pathStr.endsWith(".iml")
|
||||
&& !pathStr.contains(".flattened-pom.xml");
|
||||
}
|
||||
|
||||
private static String processFileContent(String content, String fileName, String serverName, String packageName, String capitalizedName, String author) {
|
||||
String newContent = content.replace("芋道源码", author);
|
||||
|
||||
switch (fileName) {
|
||||
case "pom.xml":
|
||||
// 替换 artifactId
|
||||
newContent = newContent.replace("<artifactId>yudao-server</artifactId>", "<artifactId>" + serverName + "</artifactId>");
|
||||
// 移除对 yudao-module-xxx-server 的依赖,但保留 system-server 和 infra-server
|
||||
return newContent.replaceAll("(?m)^\\s*<dependency>\\s*<groupId>cn\\.iocoder\\.cloud</groupId>\\s*<artifactId>yudao-module-(?!system-server|infra-server).*-server</artifactId>[\\s\\S]*?</dependency>\\s*", "");
|
||||
case "application.yaml":
|
||||
return newContent.replace("name: yudao-server", "name: " + serverName);
|
||||
case "YudaoServerApplication.java":
|
||||
return newContent.replace("package cn.iocoder.yudao.server;", "package " + BASE_PACKAGE_PREFIX + packageName + ";")
|
||||
.replace("YudaoServerApplication", capitalizedName + "Application");
|
||||
case "Dockerfile":
|
||||
return newContent.replace("yudao-server.jar", serverName + ".jar")
|
||||
.replace("/yudao-server", "/" + serverName);
|
||||
default:
|
||||
return newContent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 kebab-case 转换为 PascalCase
|
||||
* 例如:demo-server -> DemoServer
|
||||
*/
|
||||
private static String toPascalCase(String kebabCase) {
|
||||
if (kebabCase == null || kebabCase.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return Arrays.stream(kebabCase.split("-"))
|
||||
.map(s -> {
|
||||
if (s.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
||||
})
|
||||
.collect(Collectors.joining());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
<template>
|
||||
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
v-loading="formLoading"
|
||||
<FormDialog
|
||||
ref="formDialogRef"
|
||||
:form-data="formData"
|
||||
:form-rules="formRules"
|
||||
:create-api="${simpleClassName}Api.create${simpleClassName}"
|
||||
:update-api="${simpleClassName}Api.update${simpleClassName}"
|
||||
:get-api="${simpleClassName}Api.get${simpleClassName}"
|
||||
create-title="新增${table.classComment}"
|
||||
update-title="修改${table.classComment}"
|
||||
@success="handleSuccess"
|
||||
>
|
||||
<template #form-items="{ formData }">
|
||||
#foreach($column in $columns)
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
#set ($dictType = $column.dictType)
|
||||
@@ -48,6 +52,7 @@
|
||||
#elseif($column.htmlType == "fileUpload")## 文件上传
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<UploadFile v-model="formData.${javaField}" />
|
||||
</el-form-item>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "editor")## 文本编辑器
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
@@ -120,11 +125,13 @@
|
||||
<UploadFile v-model="formData.files" />
|
||||
</el-form-item>
|
||||
#end
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
<!-- 子表的表单 -->
|
||||
<el-tabs v-model="subTabsName">
|
||||
<template #footer="{ submit, cancel, loading }">
|
||||
<el-tabs v-model="subTabsName" style="margin-bottom: 20px;">
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
@@ -135,16 +142,16 @@
|
||||
</el-tab-pane>
|
||||
#end
|
||||
</el-tabs>
|
||||
#end
|
||||
<template #footer>
|
||||
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
<el-button @click="submit" type="primary" :disabled="loading">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
#end
|
||||
</FormDialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}'
|
||||
import FormDialog from '@/components/FormDialog/index.vue'
|
||||
## 特殊:树表专属逻辑
|
||||
#if ( $table.templateType == 2 )
|
||||
import { defaultProps, handleTree } from '@/utils/tree'
|
||||
@@ -162,10 +169,13 @@ defineOptions({ name: '${simpleClassName}Form' })
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
/** 成功事件 */
|
||||
const emit = defineEmits(['success'])
|
||||
|
||||
/** 组件引用 */
|
||||
const formDialogRef = ref()
|
||||
|
||||
/** 表单数据 */
|
||||
const formData = ref({
|
||||
#foreach ($column in $columns)
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
@@ -180,6 +190,8 @@ const formData = ref({
|
||||
files: undefined
|
||||
#end
|
||||
})
|
||||
|
||||
/** 表单验证规则 */
|
||||
const formRules = reactive({
|
||||
#foreach ($column in $columns)
|
||||
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
|
||||
@@ -188,6 +200,7 @@ const formRules = reactive({
|
||||
#end
|
||||
#end
|
||||
})
|
||||
|
||||
const formRef = ref() // 表单 Ref
|
||||
## 特殊:树表专属逻辑
|
||||
#if ( $table.templateType == 2 )
|
||||
@@ -205,97 +218,17 @@ const ${subClassNameVar}FormRef = ref()
|
||||
#end
|
||||
#end
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await ${simpleClassName}Api.get${simpleClassName}(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
## 特殊:树表专属逻辑
|
||||
#if ( $table.templateType == 2 )
|
||||
await get${simpleClassName}Tree()
|
||||
#end
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
await formRef.value.validate()
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
#if ( $subTables && $subTables.size() > 0 )
|
||||
// 校验子表单
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
try {
|
||||
await ${subClassNameVar}FormRef.value.validate()
|
||||
} catch (e) {
|
||||
subTabsName.value = '${subClassNameVar}'
|
||||
return
|
||||
}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as ${simpleClassName}VO
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
#if ( $subTables && $subTables.size() > 0 )
|
||||
// 拼接子表的数据
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData()
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
if (formType.value === 'create') {
|
||||
await ${simpleClassName}Api.create${simpleClassName}(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await ${simpleClassName}Api.update${simpleClassName}(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
/** 处理成功事件 */
|
||||
const handleSuccess = () => {
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
#foreach ($column in $columns)
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
#if ($column.htmlType == "checkbox")
|
||||
$column.javaField: [],
|
||||
#else
|
||||
$column.javaField: undefined,
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($isFileUpload && $isFileUpload == true)
|
||||
files: undefined
|
||||
#end
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
/** 暴露组件方法 */
|
||||
defineExpose({
|
||||
open: (type: string, id?: number) => {
|
||||
formDialogRef.value?.open(type, id)
|
||||
}
|
||||
})
|
||||
## 特殊:树表专属逻辑
|
||||
#if ( $table.templateType == 2 )
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
<template>
|
||||
<ContentWrap>
|
||||
<!-- 搜索工作栏 -->
|
||||
<el-form
|
||||
class="-mb-15px"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="68px"
|
||||
<!-- 搜索区域 -->
|
||||
<SearchForm
|
||||
v-model="queryParams"
|
||||
@search="handleQuery"
|
||||
@reset="resetQuery"
|
||||
>
|
||||
<template #search-items="{ form }">
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
#set ($dictType = $column.dictType)
|
||||
@@ -26,7 +24,7 @@
|
||||
#if ($column.htmlType == "input")
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<el-input
|
||||
v-model="queryParams.${javaField}"
|
||||
v-model="form.${javaField}"
|
||||
placeholder="请输入${comment}"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
@@ -36,7 +34,7 @@
|
||||
#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<el-select
|
||||
v-model="queryParams.${javaField}"
|
||||
v-model="form.${javaField}"
|
||||
placeholder="请选择${comment}"
|
||||
clearable
|
||||
class="!w-240px"
|
||||
@@ -57,7 +55,7 @@
|
||||
#if ($column.listOperationCondition != "BETWEEN")## 非范围
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<el-date-picker
|
||||
v-model="queryParams.${javaField}"
|
||||
v-model="form.${javaField}"
|
||||
value-format="YYYY-MM-DD"
|
||||
type="date"
|
||||
placeholder="选择${comment}"
|
||||
@@ -68,7 +66,7 @@
|
||||
#else## 范围
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<el-date-picker
|
||||
v-model="queryParams.${javaField}"
|
||||
v-model="form.${javaField}"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
type="daterange"
|
||||
start-placeholder="开始日期"
|
||||
@@ -81,9 +79,9 @@
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
<el-form-item>
|
||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||
</template>
|
||||
|
||||
<template #action-buttons>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@@ -107,7 +105,7 @@
|
||||
plain
|
||||
@click="handleBatchDelete"
|
||||
:disabled="selectRecords.length === 0"
|
||||
v-hasPermi="['template:demo-virtualized-table:delete']"
|
||||
v-hasPermi="['${permissionPrefix}:delete']"
|
||||
>
|
||||
<Icon icon="ep:delete" class="mr-5px" /> 批量删除({{ selectRecords.length }})
|
||||
</el-button>
|
||||
@@ -118,14 +116,13 @@
|
||||
<Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
|
||||
</el-button>
|
||||
#end
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
</template>
|
||||
</SearchForm>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
## 特殊:主子表专属逻辑
|
||||
<!-- 列表区域 -->
|
||||
#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
|
||||
<!-- 特殊:主子表使用传统表格 -->
|
||||
<ContentWrap>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="list"
|
||||
@@ -134,8 +131,9 @@
|
||||
highlight-current-row
|
||||
@current-change="handleCurrentChange"
|
||||
>
|
||||
## 特殊:树表专属逻辑
|
||||
#elseif ( $table.templateType == 2 )
|
||||
<!-- 特殊:树表使用传统表格 -->
|
||||
<ContentWrap>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="list"
|
||||
@@ -145,9 +143,47 @@
|
||||
:default-expand-all="isExpandAll"
|
||||
v-if="refreshTable"
|
||||
>
|
||||
###else
|
||||
## <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||
#elseif ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
|
||||
<!-- 特殊:主子表展开使用传统表格 -->
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||
#else
|
||||
<!-- 普通表格使用 DataTable 组件 -->
|
||||
<DataTable
|
||||
:data="list"
|
||||
:total="total"
|
||||
:loading="loading"
|
||||
:current-page="queryParams.pageNo"
|
||||
:page-size="queryParams.pageSize"
|
||||
:columns="tableColumns"
|
||||
@pagination="handlePagination"
|
||||
@selection-change="onSelectionChange"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', row.id)"
|
||||
v-hasPermi="['${permissionPrefix}:update']"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(row.id)"
|
||||
v-hasPermi="['${permissionPrefix}:delete']"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
#if($isFileUpload && $isFileUpload == true)
|
||||
<el-button link @click="openBusinessFile(row.id)">附件</el-button>
|
||||
#end
|
||||
</template>
|
||||
</DataTable>
|
||||
#end
|
||||
## 特殊表格依然使用 element table
|
||||
#if ( $table.templateType == 12 || $table.templateType == 11 || $table.templateType == 2 )
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
|
||||
<!-- 子表的列表 -->
|
||||
@@ -167,8 +203,6 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
#end
|
||||
## 特殊表格依然使用 element table
|
||||
#if ( $table.templateType == 12 || $table.templateType == 11 || $table.templateType == 2 )
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperationResult)
|
||||
#set ($dictType=$column.dictType)
|
||||
@@ -218,36 +252,6 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
#else
|
||||
## 普通表格使用 Vxe table 支持大数据量渲染
|
||||
<vxe-grid
|
||||
ref="gridRef"
|
||||
v-bind="gridOptions"
|
||||
@checkbox-change="onCheckboxChange"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', row.id)"
|
||||
v-hasPermi="['${permissionPrefix}:update']"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(row.id)"
|
||||
v-hasPermi="['${permissionPrefix}:delete']"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
#if($isFileUpload && $isFileUpload == true)
|
||||
<el-button link @click="openBusinessFile(row.id)">附件</el-button>
|
||||
#end
|
||||
</template>
|
||||
</vxe-grid>
|
||||
#end
|
||||
<!-- 分页 -->
|
||||
<Pagination
|
||||
:total="total"
|
||||
@@ -257,6 +261,7 @@
|
||||
:page-sizes="[10, 20, 50, 100, 200, 500, 700,5000, 10000]"
|
||||
/>
|
||||
</ContentWrap>
|
||||
#end
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<${simpleClassName}Form ref="formRef" @success="getList" />
|
||||
@@ -286,10 +291,16 @@ import { dateFormatter } from '@/utils/formatTime'
|
||||
#if ( $table.templateType == 2 )
|
||||
import { handleTree } from '@/utils/tree'
|
||||
#end
|
||||
#if ( $table.templateType != 12 && $table.templateType != 11 && $table.templateType != 2 )
|
||||
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
|
||||
#end
|
||||
import download from '@/utils/download'
|
||||
import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}'
|
||||
import ${simpleClassName}Form from './${simpleClassName}Form.vue'
|
||||
import SearchForm from '@/components/SearchForm/index.vue'
|
||||
#if ( $table.templateType != 12 && $table.templateType != 11 && $table.templateType != 2 )
|
||||
import DataTable from '@/components/DataTable/index.vue'
|
||||
#end
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType != 10 )
|
||||
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||
@@ -319,7 +330,9 @@ const list = ref<${simpleClassName}VO[]>([]) // 列表的数据
|
||||
#if ( $table.templateType != 2 )
|
||||
const total = ref(0) // 列表的总页数
|
||||
#end
|
||||
#if ( $table.templateType == 12 || $table.templateType == 11 || $table.templateType == 2 )
|
||||
const gridRef = ref() // vxe-grid 的引用
|
||||
#end
|
||||
const selectRecords = ref<${simpleClassName}VO[]>([]) // 选中的记录
|
||||
const queryParams = reactive({
|
||||
## 特殊:树表专属逻辑(树不需要分页接口)
|
||||
@@ -338,10 +351,67 @@ const queryParams = reactive({
|
||||
#end
|
||||
#end
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
|
||||
#if ( $table.templateType != 12 && $table.templateType != 11 && $table.templateType != 2 )
|
||||
// 表格列配置
|
||||
const tableColumns = [
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperationResult)
|
||||
#set ($dictType=$column.dictType)
|
||||
#set ($javaField = $column.javaField)
|
||||
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#set ($comment=$column.columnComment)
|
||||
#if ($column.javaType == "LocalDateTime")## 时间类型
|
||||
{
|
||||
field: '${javaField}',
|
||||
title: '${comment}',
|
||||
width: 180,
|
||||
align: 'center',
|
||||
formatter: ({ row, column, cellValue }) => cellValue ? dateFormatter(row, column, cellValue) : ''
|
||||
},
|
||||
#elseif($column.dictType && "" != $column.dictType)## 数据字典
|
||||
{
|
||||
field: '${javaField}',
|
||||
title: '${comment}',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
formatter: ({ cellValue }) => {
|
||||
const dict = getStrDictOptions(DICT_TYPE.${dictType.toUpperCase()}).find(item => item.value === cellValue)
|
||||
return dict ? dict.label : cellValue
|
||||
}
|
||||
},
|
||||
#else
|
||||
{
|
||||
field: '${javaField}',
|
||||
title: '${comment}',
|
||||
minWidth: 120,
|
||||
align: 'center'
|
||||
},
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
{
|
||||
title: '操作',
|
||||
width: 200,
|
||||
align: 'center',
|
||||
fixed: 'right', // 固定在右侧
|
||||
slots: { default: 'action' }
|
||||
}
|
||||
]
|
||||
|
||||
/** DataTable 选择变化事件 */
|
||||
const onSelectionChange = (records: ${simpleClassName}VO[]) => {
|
||||
selectRecords.value = records
|
||||
}
|
||||
|
||||
/** 分页处理 */
|
||||
const handlePagination = ({ page, limit }: { page: number; limit: number }) => {
|
||||
queryParams.pageNo = page
|
||||
queryParams.pageSize = limit
|
||||
getList()
|
||||
}
|
||||
#else
|
||||
/** vxe-grid 复选框事件 */
|
||||
const onCheckboxChange = ({ records }) => {
|
||||
selectRecords.value = records
|
||||
@@ -424,14 +494,18 @@ const getList = async () => {
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
#if ( $table.templateType != 2 )
|
||||
queryParams.pageNo = 1
|
||||
#end
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value.resetFields()
|
||||
handleQuery()
|
||||
#if ( $table.templateType != 2 )
|
||||
queryParams.pageNo = 1
|
||||
#end
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 添加/修改操作 */
|
||||
@@ -467,7 +541,11 @@ const handleBatchDelete = async () => {
|
||||
await ${simpleClassName}Api.delete${simpleClassName}List(ids)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 清空选中状态
|
||||
#if ( $table.templateType != 12 && $table.templateType != 11 && $table.templateType != 2 )
|
||||
// DataTable 组件会自动处理选中状态
|
||||
#else
|
||||
gridRef.value?.clearCheckboxRow()
|
||||
#end
|
||||
selectRecords.value = []
|
||||
// 刷新列表
|
||||
await getList()
|
||||
|
||||
@@ -36,6 +36,12 @@
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
<artifactId>yudao-module-infra-server</artifactId>
|
||||
<version>${revision}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
|
||||
@@ -5,35 +5,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 项目的启动类
|
||||
*
|
||||
* 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
* 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
* 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package}
|
||||
@SpringBootApplication(scanBasePackages = {"${yudao.info.base-package}.server", "${yudao.info.base-package}.module"},
|
||||
excludeName = {
|
||||
// RPC 相关
|
||||
// "org.springframework.cloud.openfeign.FeignAutoConfiguration",
|
||||
// "cn.iocoder.yudao.module.system.framework.rpc.config.RpcConfiguration"
|
||||
})
|
||||
excludeName = {})
|
||||
public class YudaoServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
// 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
// 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
|
||||
SpringApplication.run(YudaoServerApplication.class, args);
|
||||
// new SpringApplicationBuilder(YudaoServerApplication.class)
|
||||
// .applicationStartup(new BufferingApplicationStartup(20480))
|
||||
// .run(args);
|
||||
|
||||
// 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
// 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
// 如果你碰到启动的问题,请认真阅读 https://doc.iocoder.cn/quick-start/ 文章
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user