diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java index 03df3213f..9276363ec 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java @@ -37,7 +37,7 @@ public class CodegenUpdateReqVO { @Schema(description = "编号", required = true, example = "1") private Long id; - @AssertTrue(message = "上级菜单不能为空") + @AssertTrue(message = "上级菜单不能为空,请前往 [修改生成配置 -> 生成信息] 界面,设置“上级菜单”字段") public boolean isParentMenuIdValid() { // 生成场景为管理后台时,必须设置上级菜单,不然生成的菜单 SQL 是无父级菜单的 return ObjectUtil.notEqual(getScene(), CodegenSceneEnum.ADMIN.getScene()) @@ -57,4 +57,4 @@ public class CodegenUpdateReqVO { } -} \ No newline at end of file +} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableBaseVO.java index 4c05c10f2..0ea3ccdfd 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableBaseVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableBaseVO.java @@ -51,7 +51,11 @@ public class CodegenTableBaseVO { @NotNull(message = "模板类型不能为空") private Integer templateType; + @Schema(description = "前端类型,参见 CodegenFrontTypeEnum 枚举", required = true, example = "20") + @NotNull(message = "前端类型不能为空") + private Integer frontType; + @Schema(description = "父菜单编号", example = "1024") private Long parentMenuId; -} \ No newline at end of file +} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java index fc1f161b6..fcad02354 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.infra.dal.dataobject.codegen; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO; +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; import com.baomidou.mybatisplus.annotation.IdType; @@ -100,6 +101,12 @@ public class CodegenTableDO extends BaseDO { * 枚举 {@link CodegenTemplateTypeEnum} */ private Integer templateType; + /** + * 代码生成的前端类型 + * + * 枚举 {@link CodegenFrontTypeEnum} + */ + private Integer frontType; // ========== 菜单相关字段 ========== diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenFrontTypeEnum.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenFrontTypeEnum.java new file mode 100644 index 000000000..1d03c42e8 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenFrontTypeEnum.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.infra.enums.codegen; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 代码生成的前端类型枚举 + * + * @author 芋道源码 + */ +@AllArgsConstructor +@Getter +public enum CodegenFrontTypeEnum { + + VUE2(10), // Vue2 Element UI 标准模版 + VUE3(20), // Vue3 Element Plus 标准模版 + VUE3_SCHEMA(21), // Vue3 Element Plus Schema 模版 + ; + + /** + * 类型 + */ + private final Integer type; + +} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java index a8649dc23..4039a70d6 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.infra.framework.codegen.config; +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; @@ -25,4 +26,12 @@ public class CodegenProperties { @NotEmpty(message = "数据库不能为空") private Collection dbSchemas; + /** + * 代码生成的前端类型(默认) + * + * 枚举 {@link CodegenFrontTypeEnum#getType()} + */ + @NotNull(message = "代码生成的前端类型不能为空") + private Integer frontType; + } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index 1a9fdf581..029fe4162 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenColumnMapper; import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenTableMapper; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; +import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder; import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine; import cn.iocoder.yudao.module.infra.service.db.DatabaseTableService; @@ -58,6 +59,9 @@ public class CodegenServiceImpl implements CodegenService { @Resource private CodegenEngine codegenEngine; + @Resource + private CodegenProperties codegenProperties; + @Override @Transactional(rollbackFor = Exception.class) public List createCodegenList(Long userId, CodegenCreateListReqVO reqVO) { @@ -87,6 +91,7 @@ public class CodegenServiceImpl implements CodegenService { CodegenTableDO table = codegenBuilder.buildTable(tableInfo); table.setDataSourceConfigId(dataSourceConfigId); table.setScene(CodegenSceneEnum.ADMIN.getScene()); // 默认配置下,使用管理后台的模板 + table.setFrontType(codegenProperties.getFrontType()); table.setAuthor(userApi.getUser(userId).getCheckedData().getNickname()); codegenTableMapper.insert(table); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java index ae485f62b..f5509dd21 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java @@ -23,9 +23,12 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum; import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; +import com.google.common.collect.ImmutableTable; import com.google.common.collect.Maps; +import com.google.common.collect.Table; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -50,11 +53,12 @@ import static cn.hutool.core.text.CharSequenceUtil.*; public class CodegenEngine { /** - * 模板配置 + * 后端的模板配置 + * * key:模板在 resources 的地址 * value:生成的路径 */ - private static final Map TEMPLATES = MapUtil.builder(new LinkedHashMap<>()) // 有序 + private static final Map SERVER_TEMPLATES = MapUtil.builder(new LinkedHashMap<>()) // 有序 // Java module-biz Main .put(javaTemplatePath("controller/vo/baseVO"), javaModuleImplVOFilePath("BaseVO")) .put(javaTemplatePath("controller/vo/createReqVO"), javaModuleImplVOFilePath("CreateReqVO")) @@ -80,25 +84,40 @@ public class CodegenEngine { javaModuleImplTestFilePath("service/${table.businessName}/${table.className}ServiceImplTest")) // Java module-api Main .put(javaTemplatePath("enums/errorcode"), javaModuleApiMainFilePath("enums/ErrorCodeConstants_手动操作")) - // Vue2 - .put(vueTemplatePath("views/index.vue"), - vueFilePath("views/${table.moduleName}/${classNameVar}/index.vue")) - .put(vueTemplatePath("api/api.js"), - vueFilePath("api/${table.moduleName}/${classNameVar}.js")) - // Vue3 - .put(vue3TemplatePath("views/index.vue"), - vue3FilePath("views/${table.moduleName}/${classNameVar}/index.vue")) - .put(vue3TemplatePath("views/data.ts"), - vue3FilePath("views/${table.moduleName}/${classNameVar}/${classNameVar}.data.ts")) - .put(vue3TemplatePath("api/api.ts"), - vue3FilePath("api/${table.moduleName}/${classNameVar}/index.ts")) - .put(vue3TemplatePath("api/types.ts"), - vue3FilePath("api/${table.moduleName}/${classNameVar}/types.ts")) // SQL .put("codegen/sql/sql.vm", "sql/sql.sql") .put("codegen/sql/h2.vm", "sql/h2.sql") .build(); + /** + * 后端的配置模版 + * + * key1:UI 模版的类型 {@link CodegenFrontTypeEnum#getType()} + * key2:模板在 resources 的地址 + * value:生成的路径 + */ + private static final Table FRONT_TEMPLATES = ImmutableTable.builder() + // Vue2 标准模版 + .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/index.vue"), + vueFilePath("views/${table.moduleName}/${classNameVar}/index.vue")) + .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("api/api.js"), + vueFilePath("api/${table.moduleName}/${classNameVar}.js")) + // Vue3 标准模版 + .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/index.vue"), + vue3FilePath("views/${table.moduleName}/${classNameVar}/index.vue")) + .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/form.vue"), + vue3FilePath("views/${table.moduleName}/${classNameVar}/${simpleClassName}Form.vue")) + .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("api/api.ts"), + vue3FilePath("api/${table.moduleName}/${classNameVar}/index.ts")) + // Vue3 Schema 模版 + .put(CodegenFrontTypeEnum.VUE3_SCHEMA.getType(), vue3SchemaTemplatePath("views/data.ts"), + vue3FilePath("views/${table.moduleName}/${classNameVar}/${classNameVar}.data.ts")) + .put(CodegenFrontTypeEnum.VUE3_SCHEMA.getType(), vue3SchemaTemplatePath("views/index.vue"), + vue3FilePath("views/${table.moduleName}/${classNameVar}/index.vue")) + .put(CodegenFrontTypeEnum.VUE3_SCHEMA.getType(), vue3SchemaTemplatePath("views/form.vue"), + vue3FilePath("views/${table.moduleName}/${classNameVar}/${simpleClassName}Form.vue")) + .build(); + @Resource private CodegenProperties codegenProperties; @@ -167,20 +186,32 @@ public class CodegenEngine { bindingMap.put("permissionPrefix", table.getModuleName() + ":" + simpleClassNameStrikeCase); // 执行生成 - final Map result = Maps.newLinkedHashMapWithExpectedSize(TEMPLATES.size()); // 有序 - TEMPLATES.forEach((vmPath, filePath) -> { + Map templates = getTemplates(table.getFrontType()); + Map result = Maps.newLinkedHashMapWithExpectedSize(templates.size()); // 有序 + templates.forEach((vmPath, filePath) -> { filePath = formatFilePath(filePath, bindingMap); String content = templateEngine.getTemplate(vmPath).render(bindingMap); + // 去除字段后面多余的 , 逗号 + content = content.replaceAll(",\n}", "\n}").replaceAll(",\n }", "\n }"); result.put(filePath, content); }); return result; } + private Map getTemplates(Integer frontType) { + Map templates = new LinkedHashMap<>(); + templates.putAll(SERVER_TEMPLATES); + templates.putAll(FRONT_TEMPLATES.row(frontType)); + return templates; + } + private String formatFilePath(String filePath, Map bindingMap) { filePath = StrUtil.replace(filePath, "${basePackage}", getStr(bindingMap, "basePackage").replaceAll("\\.", "/")); filePath = StrUtil.replace(filePath, "${classNameVar}", getStr(bindingMap, "classNameVar")); + filePath = StrUtil.replace(filePath, "${simpleClassName}", + getStr(bindingMap, "simpleClassName")); // sceneEnum 包含的字段 CodegenSceneEnum sceneEnum = (CodegenSceneEnum) bindingMap.get("sceneEnum"); filePath = StrUtil.replace(filePath, "${sceneEnum.prefixClass}", sceneEnum.getPrefixClass()); @@ -239,6 +270,7 @@ public class CodegenEngine { return "yudao-ui-${sceneEnum.basePackage}/" + // 顶级目录 "src/" + path; } + private static String vue3TemplatePath(String path) { return "codegen/vue3/" + path + ".vm"; } @@ -247,4 +279,8 @@ public class CodegenEngine { return "yudao-ui-${sceneEnum.basePackage}-vue3/" + // 顶级目录 "src/" + path; } + + private static String vue3SchemaTemplatePath(String path) { + return "codegen/vue3_schema/" + path + ".vm"; + } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml index 3cd28d3f3..4401de904 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml @@ -128,6 +128,7 @@ yudao: codegen: base-package: cn.iocoder.yudao db-schemas: ${spring.datasource.dynamic.datasource.master.name} + front-type: 10 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类 error-code: # 错误码相关配置项 constants-class-list: - cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm index 03fbbbb3b..a8c1f62c5 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm @@ -1,17 +1,17 @@ -## @formatter:off package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; #if ($sceneEnum.scene == 1)import org.springframework.security.access.prepost.PreAuthorize;#end -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; import java.util.*; import java.io.IOException; @@ -24,7 +24,6 @@ import ${ExcelUtilsClassName}; import ${OperateLogClassName}; import static ${OperateTypeEnumClassName}.*; -import ${basePackage}.framework.operatelog.core.annotations.OperateLog; import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; import ${basePackage}.module.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; @@ -42,18 +41,16 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { @PostMapping("/create") @Operation(summary = "创建${table.classComment}") - #if ($sceneEnum.scene == 1) - @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')") - #end +#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")#end + public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) { return success(${classNameVar}Service.create${simpleClassName}(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新${table.classComment}") - #if ($sceneEnum.scene == 1) - @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')") - #end +#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")#end + public CommonResult update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) { ${classNameVar}Service.update${simpleClassName}(updateReqVO); return success(true); @@ -62,9 +59,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { @DeleteMapping("/delete") @Operation(summary = "删除${table.classComment}") @Parameter(name = "id", description = "编号", required = true) - #if ($sceneEnum.scene == 1) - @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") - #end +#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")#end + public CommonResult delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { ${classNameVar}Service.delete${simpleClassName}(id); return success(true); @@ -73,9 +69,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { @GetMapping("/get") @Operation(summary = "获得${table.classComment}") @Parameter(name = "id", description = "编号", required = true, example = "1024") - #if ($sceneEnum.scene == 1) - @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") - #end +#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end + public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id); return success(${table.className}Convert.INSTANCE.convert(${classNameVar})); @@ -84,9 +79,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { @GetMapping("/list") @Operation(summary = "获得${table.classComment}列表") @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") - #if ($sceneEnum.scene == 1) - @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") - #end +#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end + public CommonResult> get${simpleClassName}List(@RequestParam("ids") Collection<${primaryColumn.javaType}> ids) { List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(ids); return success(${table.className}Convert.INSTANCE.convertList(list)); @@ -94,9 +88,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { @GetMapping("/page") @Operation(summary = "获得${table.classComment}分页") - #if ($sceneEnum.scene == 1) - @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") - #end +#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end + public CommonResult> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageVO) { PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO); return success(${table.className}Convert.INSTANCE.convertPage(pageResult)); @@ -104,16 +97,15 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { @GetMapping("/export-excel") @Operation(summary = "导出${table.classComment} Excel") - #if ($sceneEnum.scene == 1) - @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')") - #end +#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")#end + @OperateLog(type = EXPORT) public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO, HttpServletResponse response) throws IOException { List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(exportReqVO); // 导出 Excel List<${sceneEnum.prefixClass}${table.className}ExcelVO> datas = ${table.className}Convert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "${table.classComment}.xls","数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas); + ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas); } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm index a2b4b6db9..89a8e348f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm @@ -1,6 +1,5 @@ -## @formatter:off ## 提供给 baseVO、createVO、updateVO 生成字段 - @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) + @Schema(description = "${column.columnComment}"#if (!${column.nullable}), required = true#end#if ("$!column.example" != ""), example = "${column.example}"#end) #if (!${column.nullable})## 判断 @NotEmpty 和 @NotNull 注解 #if (${field.fieldType} == 'String') @NotEmpty(message = "${column.columnComment}不能为空") @@ -11,4 +10,4 @@ #if (${column.javaType} == "LocalDateTime")## 时间类型 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) #end - private ${column.javaType} ${column.javaField}; \ No newline at end of file + private ${column.javaType} ${column.javaField}; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/baseVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/baseVO.vm index 9419c4c7b..e2c1f0b39 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/baseVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/baseVO.vm @@ -1,6 +1,6 @@ -## @formatter:off package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import java.util.*; #foreach ($column in $columns) @@ -11,11 +11,11 @@ import java.math.BigDecimal; import java.time.LocalDateTime; #end #end -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.*; +import javax.validation.constraints.*; ## 处理 Date 字段的引入 #foreach ($column in $columns) -#if (${column.createOperation} && ${column.updateOperation} && ${column.listOperationResult} && ${column.javaType} == "LocalDateTime")## 时间类型 +#if (${column.createOperation} && ${column.updateOperation} && ${column.listOperationResult} + && ${column.javaType} == "LocalDateTime")## 时间类型 import org.springframework.format.annotation.DateTimeFormat; import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm index ecef348f5..d4f6f8ea9 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm @@ -1,13 +1,13 @@ -## @formatter:off package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; import lombok.*; import java.util.*; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.*; +import javax.validation.constraints.*; ## 处理 Date 字段的引入 #foreach ($column in $columns) -#if (${column.createOperation} && (!${column.updateOperation} || !${column.listOperationResult}) && ${column.javaType} == "LocalDateTime")## 时间类型 +#if (${column.createOperation} && (!${column.updateOperation} || !${column.listOperationResult}) + && ${column.javaType} == "LocalDateTime")## 时间类型 import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -15,7 +15,7 @@ import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; #end #end -@Schema(name = "${sceneEnum.name} - ${table.classComment}创建 Request VO") +@Schema(description = "${sceneEnum.name} - ${table.classComment}创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm index 86ec3e612..15c6660c8 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm @@ -1,6 +1,6 @@ -## @formatter:off package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import java.util.*; #foreach ($column in $columns) @@ -11,6 +11,7 @@ import java.math.BigDecimal; import java.time.LocalDateTime; #end #end + import com.alibaba.excel.annotation.ExcelProperty; #foreach ($column in $columns) #if ("$!column.dictType" != "")## 有设置数据字典 @@ -22,10 +23,10 @@ import ${DictConvertClassName}; #end /** -* ${table.classComment} Excel VO -* -* @author ${table.author} -*/ + * ${table.classComment} Excel VO + * + * @author ${table.author} + */ @Data public class ${sceneEnum.prefixClass}${table.className}ExcelVO { diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm index 303232b95..d3ef4aacd 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm @@ -1,4 +1,3 @@ -## @formatter:off package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; import lombok.*; @@ -21,7 +20,7 @@ import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; private ${column.javaType}#if ("$!prefix" != "") ${prefix}${JavaField}#else ${column.javaField}#end; #end -@Schema(name = "${sceneEnum.name} - ${table.classComment} Excel 导出 Request VO", description = "参数和 ${table.className}PageReqVO 是一致的") +@Schema(description = "${sceneEnum.name} - ${table.classComment} Excel 导出 Request VO,参数和 ${table.className}PageReqVO 是一致的") @Data public class ${sceneEnum.prefixClass}${table.className}ExportReqVO { diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm index 8a3855754..6f9868da3 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm @@ -1,4 +1,3 @@ -## @formatter:off package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; import lombok.*; @@ -21,7 +20,7 @@ import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; private ${column.javaType}#if ("$!prefix" != "") ${prefix}${JavaField}#else ${column.javaField}#end; #end -@Schema(name = "${sceneEnum.name} - ${table.classComment}分页 Request VO") +@Schema(description = "${sceneEnum.name} - ${table.classComment}分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm index 7261ec3ce..2288ceee8 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm @@ -1,8 +1,7 @@ -## @formatter:off package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; -import lombok.*; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; #foreach ($column in $columns) #if (${column.javaType} == "LocalDateTime") import java.time.LocalDateTime; @@ -10,7 +9,7 @@ import java.time.LocalDateTime; #end #end -@Schema(name = "${sceneEnum.name} - ${table.classComment} Response VO") +@Schema(description = "${sceneEnum.name} - ${table.classComment} Response VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @@ -18,7 +17,7 @@ public class ${sceneEnum.prefixClass}${table.className}RespVO extends ${sceneEnu #foreach ($column in $columns) #if (${column.listOperationResult} && (!${column.createOperation} || !${column.updateOperation}))##不是通用字段 - @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) + @Schema(description = "${column.columnComment}"#if (!${column.nullable}), required = true#end#if ("$!column.example" != ""), example = "${column.example}"#end) private ${column.javaType} ${column.javaField}; #end diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm index 823f3f8f4..48d74321d 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm @@ -1,13 +1,13 @@ -## @formatter:off package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.*; +import javax.validation.constraints.*; ## 处理 Date 字段的引入 #foreach ($column in $columns) -#if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult}) && ${column.javaType} == "LocalDateTime")## 时间类型 +#if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult}) + && ${column.javaType} == "LocalDateTime")## 时间类型 import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -15,7 +15,7 @@ import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; #end #end -@Schema(name = "${sceneEnum.name} - ${table.classComment}更新 Request VO") +@Schema(description = "${sceneEnum.name} - ${table.classComment}更新 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm index 0edbdc1ee..902ca7414 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm @@ -1,11 +1,11 @@ -- 菜单 SQL INSERT INTO system_menu( name, permission, type, sort, parent_id, - path, icon, component, status + path, icon, component, status, component_name ) VALUES ( '${table.classComment}管理', '', 2, 0, ${table.parentMenuId}, - '${simpleClassName_strikeCase}', '', '${table.moduleName}/${classNameVar}/index', 0 + '${simpleClassName_strikeCase}', '', '${table.moduleName}/${classNameVar}/index', 0, '${table.className}' ); -- 按钮父菜单ID diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm index df49a002b..eaab40703 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm @@ -14,61 +14,32 @@ export interface ${simpleClassName}VO { #end } -export interface ${simpleClassName}PageReqVO extends PageParam { -#foreach ($column in $columns) -#if (${column.listOperation})##查询操作 -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") - ${column.javaField}?: number -#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") - ${column.javaField}?: Date[] -#else - ${column.javaField}?: ${column.javaType.toLowerCase()} -#end -#end -#end -} - -export interface ${simpleClassName}ExcelReqVO { -#foreach ($column in $columns) -#if (${column.listOperation})##查询操作 -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") - ${column.javaField}?: number -#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") - ${column.javaField}?: Date[] -#else - ${column.javaField}?: ${column.javaType.toLowerCase()} -#end -#end -#end -} -#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") - // 查询${table.classComment}列表 -export const get${simpleClassName}PageApi = async (params: ${simpleClassName}PageReqVO) => { +export const get${simpleClassName}Page = async (params: ${simpleClassName}PageReqVO) => { return await request.get({ url: '${baseURL}/page', params }) } // 查询${table.classComment}详情 -export const get${simpleClassName}Api = async (id: number) => { +export const get${simpleClassName} = async (id: number) => { return await request.get({ url: '${baseURL}/get?id=' + id }) } // 新增${table.classComment} -export const create${simpleClassName}Api = async (data: ${simpleClassName}VO) => { +export const create${simpleClassName} = async (data: ${simpleClassName}VO) => { return await request.post({ url: '${baseURL}/create', data }) } // 修改${table.classComment} -export const update${simpleClassName}Api = async (data: ${simpleClassName}VO) => { +export const update${simpleClassName} = async (data: ${simpleClassName}VO) => { return await request.put({ url: '${baseURL}/update', data }) } // 删除${table.classComment} -export const delete${simpleClassName}Api = async (id: number) => { +export const delete${simpleClassName} = async (id: number) => { return await request.delete({ url: '${baseURL}/delete?id=' + id }) } // 导出${table.classComment} Excel -export const export${simpleClassName}Api = async (params: ${simpleClassName}ExcelReqVO) => { +export const export${simpleClassName}Api = async (params) => { return await request.download({ url: '${baseURL}/export-excel', params }) } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/types.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/types.ts.vm deleted file mode 100644 index 54ab47e02..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/types.ts.vm +++ /dev/null @@ -1,41 +0,0 @@ -export type ${simpleClassName}VO = { -#foreach ($column in $columns) -#if ($column.createOperation || $column.updateOperation) -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") - ${column.javaField}: number -#elseif(${column.javaType.toLowerCase()} == "date") - ${column.javaField}: string -#else - ${column.javaField}: ${column.javaType.toLowerCase()} -#end -#end -#end -} - -export type ${simpleClassName}PageReqVO = { -#foreach ($column in $columns) -#if (${column.listOperation})##查询操作 -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") - ${column.javaField}: number -#elseif(${column.javaType.toLowerCase()} == "date") - ${column.javaField}: string -#else - ${column.javaField}: ${column.javaType.toLowerCase()} -#end -#end -#end -} - -export type ${simpleClassName}ExcelReqVO = { -#foreach ($column in $columns) -#if (${column.listOperation})##查询操作 -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") - ${column.javaField}: number -#elseif(${column.javaType.toLowerCase()} == "date") - ${column.javaField}: string -#else - ${column.javaField}: ${column.javaType.toLowerCase()} -#end -#end -#end -} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm deleted file mode 100644 index 33e204a46..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm +++ /dev/null @@ -1,110 +0,0 @@ -import { reactive } from 'vue' -import { useI18n } from '@/hooks/web/useI18n' -import { DICT_TYPE } from '@/utils/dict' -import { required } from '@/utils/formRules' -import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas' -const { t } = useI18n() // 国际化 -// 表单校验 -export const rules = reactive({ -#foreach ($column in $columns) -#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 -#set($comment=$column.columnComment) - $column.javaField: [required], -#end -#end -}) -// CrudSchema -const crudSchemas = reactive({ - primaryKey: 'id', // 默认的主键ID - primaryTitle: t('common.index'), // 默认显示的值 - primaryType: 'seq', // 默认为seq,序号模式 - action: true, - actionWidth: '200', // 3个按钮默认200,如有删减对应增减即可 - columns: [ - #foreach($column in $columns) - #if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation) - #set ($dictType = $column.dictType) - #if(!$column.primaryKey) - { - title: '${column.columnComment}', - field: '${column.javaField}', - #if (!$column.listOperationResult) - isTable: false, - #end - #if ("" != $dictType)## 有数据字典 - dictType: DICT_TYPE.$dictType.toUpperCase(), - #if (${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") - dictClass: 'number', - #else - dictClass: 'string', - #end - #end - #if (!$column.createOperation && !$column.updateOperation) - isForm: false, - #elseif(!("" != $column.dictType)) - #if (${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") - form: { - component: 'DatePicker', - componentProps: { - type: 'datetime', - valueFormat: 'x' - } - }, - #elseif($column.htmlType == "editor")## 文本编辑器 - form: { - component: 'Editor', - colProps: { - span: 24 - }, - componentProps: { - valueHtml: '' - } - }, - #elseif($column.htmlType == "textarea")## 文本框 - form: { - component: 'Input', - componentProps: { - type: 'textarea', - rows: 4 - }, - colProps: { - span: 24 - } - }, - #elseif(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer")## 数字类型 - form: { - component: 'InputNumber', - value: 0 - }, - #elseif($column.htmlType == "imageUpload")## 图片上传 - form: { - component: 'UploadImg' // 单图上传,多图为UploadImgs - }, - #elseif($column.htmlType == "fileUpload")## 图片上传 - form: { - component: 'UploadFile' - }, - #end - #end - #if ($column.listOperation) - #if($column.htmlType == "input") - isSearch: true, - #elseif("" != $dictType) - isSearch: true, - #elseif($column.htmlType == "datetime") - formatter: 'formatDate', - search: { - show: true, - itemRender: { - name: 'XDataTimePicker' - } - }, - #end - #end - }, - #end - #end - #end - ] -}) -export const { allSchemas } = useVxeCrudSchemas(crudSchemas) \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm new file mode 100644 index 000000000..99cce39f2 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm @@ -0,0 +1,234 @@ + + diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm index 06fe3002a..f396dde32 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm @@ -1,177 +1,285 @@ - diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/api/api.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/api/api.ts.vm new file mode 100644 index 000000000..f488c6fe4 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/api/api.ts.vm @@ -0,0 +1,45 @@ +import request from '@/config/axios' + +export interface ${simpleClassName}VO { + #foreach ($column in $columns) + #if ($column.createOperation || $column.updateOperation) + #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") + ${column.javaField}: number + #elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") + ${column.javaField}: Date + #else + ${column.javaField}: ${column.javaType.toLowerCase()} + #end + #end + #end +} + +// 查询${table.classComment}列表 +export const get${simpleClassName}Page = async (params: ${simpleClassName}PageReqVO) => { + return await request.get({ url: '${baseURL}/page', params }) +} + +// 查询${table.classComment}详情 +export const get${simpleClassName} = async (id: number) => { + return await request.get({ url: '${baseURL}/get?id=' + id }) +} + +// 新增${table.classComment} +export const create${simpleClassName} = async (data: ${simpleClassName}VO) => { + return await request.post({ url: '${baseURL}/create', data }) +} + +// 修改${table.classComment} +export const update${simpleClassName} = async (data: ${simpleClassName}VO) => { + return await request.put({ url: '${baseURL}/update', data }) +} + +// 删除${table.classComment} +export const delete${simpleClassName} = async (id: number) => { + return await request.delete({ url: '${baseURL}/delete?id=' + id }) +} + +// 导出${table.classComment} Excel +export const export${simpleClassName}Api = async (params) => { + return await request.download({ url: '${baseURL}/export-excel', params }) +} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/data.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/data.ts.vm new file mode 100644 index 000000000..cbc6a17ba --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/data.ts.vm @@ -0,0 +1,129 @@ +import type { CrudSchema } from '@/hooks/web/useCrudSchemas' +#foreach ($column in $columns) + #if ($column.listOperationResult && $column.htmlType == "datetime") +import { dateFormatter } from '@/utils/formatTime' + #break + #end +#end + +// 表单校验 +export const rules = reactive({ +#foreach ($column in $columns) +#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 +#set($comment=$column.columnComment) + $column.javaField: [required], +#end +#end +}) + +// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/ +const crudSchemas = reactive([ +#foreach($column in $columns) +#if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation) +#set ($dictType = $column.dictType) +#set ($javaField = $column.javaField) +#set ($javaType = $column.javaType) + { + label: '${column.columnComment}', + field: '${column.javaField}', +## ========= 字典部分 ========= + #if ("" != $dictType)## 有数据字典 + dictType: DICT_TYPE.$dictType.toUpperCase(), + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") + dictClass: 'number', + #elseif ($javaType == "String") + dictClass: 'string', + #elseif ($javaType == "Boolean") + dictClass: 'boolean', + #end + #end +## ========= Table 表格部分 ========= + #if (!$column.listOperationResult) + isTable: false, + #else + #if ($column.htmlType == "datetime") + formatter: dateFormatter, + #end + #end +## ========= Search 表格部分 ========= + #if ($column.listOperation) + isSearch: true, + #if ($column.htmlType == "datetime") + search: { + component: 'DatePicker', + componentProps: { + valueFormat: 'YYYY-MM-DD HH:mm:ss', + type: 'daterange', + defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')] + } + }, + #end + #end +## ========= Form 表单部分 ========= + #if ((!$column.createOperation && !$column.updateOperation) || $column.primaryKey) + isForm: false, + #else + #if($column.htmlType == "imageUpload")## 图片上传 + form: { + component: 'UploadImg' + }, + #elseif($column.htmlType == "fileUpload")## 文件上传 + form: { + component: 'UploadFile' + }, + #elseif($column.htmlType == "editor")## 文本编辑器 + form: { + component: 'Editor', + componentProps: { + valueHtml: '', + height: 200 + } + }, + #elseif($column.htmlType == "select")## 下拉框 + form: { + component: 'SelectV2' + }, + #elseif($column.htmlType == "checkbox")## 多选框 + form: { + component: 'Checkbox' + }, + #elseif($column.htmlType == "radio")## 单选框 + form: { + component: 'Radio' + }, + #elseif($column.htmlType == "datetime")## 时间框 + form: { + component: 'DatePicker', + componentProps: { + type: 'datetime', + valueFormat: 'x' + } + }, + #elseif($column.htmlType == "textarea")## 文本框 + form: { + component: 'Input', + componentProps: { + type: 'textarea', + rows: 4 + }, + colProps: { + span: 24 + } + }, + #elseif(${javaType.toLowerCase()} == "long" || ${javaType.toLowerCase()} == "integer")## 文本框 + form: { + component: 'InputNumber', + value: 0 + }, + #end + #end + }, +#end +#end + { + label: '操作', + field: 'action', + isForm: false + } +]) +export const { allSchemas } = useCrudSchemas(crudSchemas) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/form.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/form.vue.vm new file mode 100644 index 000000000..45b8aa260 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/form.vue.vm @@ -0,0 +1,65 @@ + + diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/index.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/index.vue.vm new file mode 100644 index 000000000..c2cbeff06 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/index.vue.vm @@ -0,0 +1,85 @@ + +