From 2a839a56f0cc8185d43dad79b193150b54182cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Thu, 30 Jan 2020 12:39:17 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E6=94=AF=E6=8C=81=20elemen?= =?UTF-8?q?t=20=E5=8E=9F=E7=94=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/constant/enums/StyleTypeEnum.java | 33 +++++ .../pigx/codegen/entity/GenConfig.java | 7 + .../service/impl/GenFormConfServiceImpl.java | 2 +- .../pig4cloud/pigx/codegen/util/GenUtils.java | 44 ++++-- .../resources/template/{ => avue}/api.js.vm | 0 .../resources/template/{ => avue}/crud.js.vm | 0 .../template/{ => avue}/index.vue.vm | 0 .../template/element/add-or-update.vue.vm | 86 ++++++++++++ .../resources/template/element/index.vue.vm | 126 ++++++++++++++++++ 9 files changed, 285 insertions(+), 13 deletions(-) create mode 100644 pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/StyleTypeEnum.java rename pigx-visual/pigx-codegen/src/main/resources/template/{ => avue}/api.js.vm (100%) rename pigx-visual/pigx-codegen/src/main/resources/template/{ => avue}/crud.js.vm (100%) rename pigx-visual/pigx-codegen/src/main/resources/template/{ => avue}/index.vue.vm (100%) create mode 100644 pigx-visual/pigx-codegen/src/main/resources/template/element/add-or-update.vue.vm create mode 100644 pigx-visual/pigx-codegen/src/main/resources/template/element/index.vue.vm diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/StyleTypeEnum.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/StyleTypeEnum.java new file mode 100644 index 000000000..0e776f828 --- /dev/null +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/StyleTypeEnum.java @@ -0,0 +1,33 @@ +package com.pig4cloud.pigx.common.core.constant.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author lengleng + * @date 2020-01-19 + *

+ * 前端类型类型 + */ +@Getter +@AllArgsConstructor +public enum StyleTypeEnum { + /** + * 前端类型-avue 风格 + */ + AVUE("0", "avue 风格"), + + /** + * 前端类型-element 风格 + */ + ELEMENT("1", "element 风格"); + + /** + * 类型 + */ + private String style; + /** + * 描述 + */ + private String description; +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenConfig.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenConfig.java index cb270c897..579c45730 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenConfig.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenConfig.java @@ -56,4 +56,11 @@ public class GenConfig { * 表备注 */ private String comments; + + /** + * 代码风格 + * 0 - avue + * 1 - element + */ + private String style; } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java index 690c4c465..ef7df6c9a 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenFormConfServiceImpl.java @@ -78,7 +78,7 @@ public class GenFormConfServiceImpl extends ServiceImpl columnList = new ArrayList<>(); diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java index 26a55a4bf..73e03c9ac 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java @@ -26,6 +26,7 @@ import com.pig4cloud.pigx.codegen.entity.GenConfig; import com.pig4cloud.pigx.codegen.entity.GenFormConf; import com.pig4cloud.pigx.codegen.entity.TableEntity; import com.pig4cloud.pigx.common.core.constant.CommonConstants; +import com.pig4cloud.pigx.common.core.constant.enums.StyleTypeEnum; import com.pig4cloud.pigx.common.core.exception.CheckedException; import lombok.SneakyThrows; import lombok.experimental.UtilityClass; @@ -63,11 +64,19 @@ public class GenUtils { private final String CONTROLLER_JAVA_VM = "Controller.java.vm"; private final String MAPPER_XML_VM = "Mapper.xml.vm"; private final String MENU_SQL_VM = "menu.sql.vm"; - private final String INDEX_VUE_VM = "index.vue.vm"; - private final String API_JS_VM = "api.js.vm"; - private final String CRUD_JS_VM = "crud.js.vm"; + private final String AVUE_INDEX_VUE_VM = "avue/index.vue.vm"; + private final String ELE_INDEX_VUE_VM = "element/index.vue.vm"; + private final String ELE_ADD_UPDATE_VUE_VM = "element/add-or-update.vue.vm"; + private final String AVUE_API_JS_VM = "avue/api.js.vm"; + private final String AVUE_CRUD_JS_VM = "avue/crud.js.vm"; - private List getTemplates() { + /** + * 配置 + * + * @param config + * @return + */ + private List getTemplates(GenConfig config) { List templates = new ArrayList<>(); templates.add("template/Entity.java.vm"); templates.add("template/Mapper.java.vm"); @@ -76,10 +85,16 @@ public class GenUtils { templates.add("template/ServiceImpl.java.vm"); templates.add("template/Controller.java.vm"); templates.add("template/menu.sql.vm"); + templates.add("template/avue/api.js.vm"); + + if (StyleTypeEnum.ELEMENT.getStyle().equals(config.getStyle())) { + templates.add("template/element/index.vue.vm"); + templates.add("template/element/add-or-update.vue.vm"); + } else { + templates.add("template/avue/index.vue.vm"); + templates.add("template/avue/crud.js.vm"); + } - templates.add("template/index.vue.vm"); - templates.add("template/api.js.vm"); - templates.add("template/crud.js.vm"); return templates; } @@ -199,10 +214,10 @@ public class GenUtils { VelocityContext context = new VelocityContext(map); //获取模板列表 - List templates = getTemplates(); + List templates = getTemplates(genConfig); for (String template : templates) { // 如果是crud - if (template.contains(CRUD_JS_VM) && formConf != null) { + if (template.contains(AVUE_CRUD_JS_VM) && formConf != null) { zip.putNextEntry(new ZipEntry(Objects .requireNonNull(getFileName(template, tableEntity.getCaseClassName() , map.get("package").toString(), map.get("moduleName").toString())))); @@ -293,20 +308,25 @@ public class GenUtils { return className.toLowerCase() + "_menu.sql"; } - if (template.contains(INDEX_VUE_VM)) { + if (template.contains(AVUE_INDEX_VUE_VM) || template.contains(ELE_INDEX_VUE_VM)) { return CommonConstants.FRONT_END_PROJECT + File.separator + "src" + File.separator + "views" + File.separator + moduleName + File.separator + className.toLowerCase() + File.separator + "index.vue"; } - if (template.contains(API_JS_VM)) { + if (template.contains(AVUE_API_JS_VM)) { return CommonConstants.FRONT_END_PROJECT + File.separator + "src" + File.separator + "api" + File.separator + className.toLowerCase() + ".js"; } - if (template.contains(CRUD_JS_VM)) { + if (template.contains(AVUE_CRUD_JS_VM)) { return CommonConstants.FRONT_END_PROJECT + File.separator + "src" + File.separator + "const" + File.separator + "crud" + File.separator + className.toLowerCase() + ".js"; } + if (template.contains(ELE_ADD_UPDATE_VUE_VM)) { + return CommonConstants.FRONT_END_PROJECT + File.separator + "src" + File.separator + "views" + + File.separator + moduleName + File.separator + className.toLowerCase() + File.separator + moduleName + "-add-or-update.vue"; + } + return null; } } diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/api.js.vm b/pigx-visual/pigx-codegen/src/main/resources/template/avue/api.js.vm similarity index 100% rename from pigx-visual/pigx-codegen/src/main/resources/template/api.js.vm rename to pigx-visual/pigx-codegen/src/main/resources/template/avue/api.js.vm diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm b/pigx-visual/pigx-codegen/src/main/resources/template/avue/crud.js.vm similarity index 100% rename from pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm rename to pigx-visual/pigx-codegen/src/main/resources/template/avue/crud.js.vm diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm b/pigx-visual/pigx-codegen/src/main/resources/template/avue/index.vue.vm similarity index 100% rename from pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm rename to pigx-visual/pigx-codegen/src/main/resources/template/avue/index.vue.vm diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/element/add-or-update.vue.vm b/pigx-visual/pigx-codegen/src/main/resources/template/element/add-or-update.vue.vm new file mode 100644 index 000000000..bef510cdb --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/element/add-or-update.vue.vm @@ -0,0 +1,86 @@ + + + diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/element/index.vue.vm b/pigx-visual/pigx-codegen/src/main/resources/template/element/index.vue.vm new file mode 100644 index 000000000..ed318be3a --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/resources/template/element/index.vue.vm @@ -0,0 +1,126 @@ + + +