From a33302315ce217d70f752f43965e585728ba232c Mon Sep 17 00:00:00 2001 From: wizzercn Date: Sat, 8 Dec 2018 23:49:55 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=E5=A2=9E=E5=8A=A0vue=E7=89=88=E6=9C=AC=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wk-app/wk-model/pom.xml | 2 +- wk-code/wk-code-generator-nb/pom.xml | 2 +- .../app/code/commons/builder/Generator.java | 40 +- .../main/resources/templet/controller_vue.vm | 114 +++++ .../main/resources/templet/vue/index.html.vm | 344 +++++++++++++ .../templet/vue_notlocale/index.html.vm | 340 +++++++++++++ wk-code/wk-code-ideaplugin-nb/.idea/misc.xml | 2 +- .../wk-code-ideaplugin-nb/.idea/workspace.xml | 470 ++++++++++++------ .../resources/META-INF/plugin.xml | 6 +- .../code/commons/plugin/GeneratorAction.java | 1 + .../code/commons/plugin/ui/ConfigDialog.java | 18 +- .../commons/plugin/utils/GenerateConfig.java | 9 + .../wk-code-ideaplugin-nb.jar | Bin 12415 -> 13470 bytes 13 files changed, 1195 insertions(+), 153 deletions(-) create mode 100644 wk-code/wk-code-generator-nb/src/main/resources/templet/controller_vue.vm create mode 100644 wk-code/wk-code-generator-nb/src/main/resources/templet/vue/index.html.vm create mode 100644 wk-code/wk-code-generator-nb/src/main/resources/templet/vue_notlocale/index.html.vm diff --git a/wk-app/wk-model/pom.xml b/wk-app/wk-model/pom.xml index 975214fca..acd9bd93c 100644 --- a/wk-app/wk-model/pom.xml +++ b/wk-app/wk-model/pom.xml @@ -19,7 +19,7 @@ cn.wizzer.app wk-code-generator-nb - 5.0.7 + 5.1.1 org.slf4j diff --git a/wk-code/wk-code-generator-nb/pom.xml b/wk-code/wk-code-generator-nb/pom.xml index de70f6f45..21ecaee41 100644 --- a/wk-code/wk-code-generator-nb/pom.xml +++ b/wk-code/wk-code-generator-nb/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> cn.wizzer.app wk-code-generator-nb - 5.0.7 + 5.1.1 4.0.0 jar wk-code-generator-nb diff --git a/wk-code/wk-code-generator-nb/src/main/java/cn/wizzer/app/code/commons/builder/Generator.java b/wk-code/wk-code-generator-nb/src/main/java/cn/wizzer/app/code/commons/builder/Generator.java index 191de6f2b..04073b542 100644 --- a/wk-code/wk-code-generator-nb/src/main/java/cn/wizzer/app/code/commons/builder/Generator.java +++ b/wk-code/wk-code-generator-nb/src/main/java/cn/wizzer/app/code/commons/builder/Generator.java @@ -74,6 +74,7 @@ public static void main(String[] args) throws Exception { Method add = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class}); add.setAccessible(true); add.invoke(classLoader, programRootDir.toURI().toURL()); + boolean vue = false; String basePath = ""; String baseNbPath = ""; String baseComPath = ""; @@ -94,7 +95,7 @@ public static void main(String[] args) throws Exception { String types[] = {"all"}; String pages[] = {"index", "add", "edit", "detail"}; Options options = new Options(); - options.addOption("c", "config", true, "spring datasource config file(classpath)"); + options.addOption("c", "config", true, "datasource config file(classpath)"); options.addOption("i", "include", true, "include table pattern"); options.addOption("x", "exclude", true, "exclude table pattern"); options.addOption("p", "package", true, "base package name,default:cn.wizzer.app"); @@ -114,6 +115,10 @@ public static void main(String[] args) throws Exception { "views", true, "for generator pages,default:all pages,eg: -v index_detail will generate index.html and detail.html"); + options.addOption("vue", + "vue", + true, + "for generator vue"); options.addOption("j", "project-path", true, "project directory, default is empty"); options.addOption("b", "base-path", true, "base directory, default is empty"); options.addOption("y", "common-path", true, "base common directory, default is empty"); @@ -126,6 +131,12 @@ public static void main(String[] args) throws Exception { CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, args); + if (commandLine.hasOption("vue")) { + String _vue = commandLine.getOptionValue("vue", "false"); + if ("true".equals(_vue)) { + vue = true; + } + } if (commandLine.hasOption("c")) { configPath = commandLine.getOptionValue("c"); } @@ -228,7 +239,14 @@ public static void main(String[] args) throws Exception { if (!hasLocale(types)) { viewpath = "view_notlocale"; } - generateViews(projectPath + "/" + outputDir + "/src/main", force, viewpath, table, generator, pages); + if (vue) { + viewpath = "vue"; + if (!hasLocale(types)) { + viewpath = "vue_notlocale"; + } + generateViewsVue(projectPath + "/" + outputDir + "/src/main", force, viewpath, table, generator, pages); + } else + generateViews(projectPath + "/" + outputDir + "/src/main", force, viewpath, table, generator, pages); } else if (type.equals("locale")) { generateLocales(projectPath + "/" + outputDir + "/src/main", force, table, generator); } else { @@ -246,6 +264,9 @@ public static void main(String[] args) throws Exception { } String templatePath = "templet/" + type.toLowerCase() + ".vm"; + if ("controller".equals(type) && vue) { + templatePath = "templet/controller_vue.vm"; + } String packagePath = packageName.replace('.', '/'); String className = table.getEntityClassName(); @@ -320,6 +341,21 @@ private static void generateViews(String outputDir, boolean force, String viewpa } } + private static void generateViewsVue(String outputDir, boolean force, String viewpath, + TableDescriptor table, + Generator generator, + String[] pages) + throws IOException { + + String templatePath = "templet/" + viewpath + "/index.html.vm"; + File file = new File(outputDir + "/resources/views/" + + table.getViewBasePath() + + "/index.html"); + log.debug("generate html:" + file.getName()); + generator.generate(null, templatePath, file, force); + + } + private static void usage(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Main [options] [all|entity|service|controller|view]", options); diff --git a/wk-code/wk-code-generator-nb/src/main/resources/templet/controller_vue.vm b/wk-code/wk-code-generator-nb/src/main/resources/templet/controller_vue.vm new file mode 100644 index 000000000..78554eb4e --- /dev/null +++ b/wk-code/wk-code-generator-nb/src/main/resources/templet/controller_vue.vm @@ -0,0 +1,114 @@ +package ${packageName}; + +import cn.wizzer.app.web.commons.slog.annotation.SLog; +import cn.wizzer.app.web.commons.utils.PageUtil; +import cn.wizzer.app.web.commons.utils.StringUtil; +import ${table.EntityFullClassName}; +import ${table.ServiceFullClassName}; +import cn.wizzer.framework.base.Result; +import com.alibaba.dubbo.config.annotation.Reference; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.nutz.dao.Cnd; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.Strings; +import org.nutz.lang.Times; +import org.nutz.log.Log; +import org.nutz.log.Logs; +import org.nutz.mvc.annotation.At; +import org.nutz.mvc.annotation.Ok; +import org.nutz.mvc.annotation.Param; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +#set($parameterId = '${args[0].id}') +#set($parameterId2 = "${req.getAttribute('id')}") +@IocBean +@At("${table.UriPrefix}") +public class ${table.ControllerClassName}{ + private static final Log log = Logs.get(); + @Inject + @Reference + private ${table.ServiceClassName} ${table.ServiceInstanceName}; + + @At("") + @Ok("beetl:/${table.ViewBasePath}/index.html") + @RequiresPermissions("${table.Permissions}") + public void index() { + } + + @At("/data") + @Ok("json:full") + @RequiresPermissions("${table.Permissions}") + public Object data(@Param("searchName") String searchName, @Param("searchKeyword") String searchKeyword, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) { + Cnd cnd = Cnd.NEW(); + if (!Strings.isBlank(searchName) && !Strings.isBlank(searchKeyword)) { + cnd.and(searchName, "like", "%" + searchKeyword + "%"); + } + if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) { + cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy)); + } + return Result.success().addData(${table.ServiceInstanceName}.listPage(pageNumber, pageSize, cnd)); + } + + + @At("/addDo") + @Ok("json") + @RequiresPermissions("${table.Permissions}.add") + @SLog(tag = "${table.Label}", msg = "$parameterId") + public Object addDo(@Param("..")${table.EntityClassName} ${table.EntityInstanceName}, HttpServletRequest req) { + try { + ${table.EntityInstanceName}.setOpBy(StringUtil.getPlatformUid()); + ${table.ServiceInstanceName}.insert(${table.EntityInstanceName}); + return Result.success(); + } catch (Exception e) { + return Result.error(); + } + } + + @At("/edit/?") + @Ok("json") + @RequiresPermissions("${table.Permissions}") + public Object edit(${table.pkType} id,HttpServletRequest req) { + try { + return Result.success().addData(${table.ServiceInstanceName}.fetch(id)); + } catch (Exception e) { + return Result.error(); + } + } + + @At("/editDo") + @Ok("json") + @RequiresPermissions("${table.Permissions}.edit") + @SLog(tag = "${table.Label}", msg = "$parameterId") + public Object editDo(@Param("..")${table.EntityClassName} ${table.EntityInstanceName}, HttpServletRequest req) { + try { + ${table.EntityInstanceName}.setOpBy(StringUtil.getPlatformUid()); + ${table.EntityInstanceName}.setOpAt(Times.getTS()); + ${table.ServiceInstanceName}.updateIgnoreNull(${table.EntityInstanceName}); + return Result.success(); + } catch (Exception e) { + return Result.error(); + } + } + + @At({"/delete/?", "/delete"}) + @Ok("json") + @RequiresPermissions("${table.Permissions}.delete") + @SLog(tag = "${table.Label}", msg = "$parameterId2") + public Object delete(${table.pkType} id, @Param("ids") ${table.pkType}[] ids, HttpServletRequest req) { + try { + if(ids!=null&&ids.length>0){ + ${table.ServiceInstanceName}.delete(ids); + req.setAttribute("id", org.apache.shiro.util.StringUtils.toString(ids)); + }else{ + ${table.ServiceInstanceName}.delete(id); + req.setAttribute("id", id); + } + return Result.success(); + } catch (Exception e) { + return Result.error(); + } + } +} diff --git a/wk-code/wk-code-generator-nb/src/main/resources/templet/vue/index.html.vm b/wk-code/wk-code-generator-nb/src/main/resources/templet/vue/index.html.vm new file mode 100644 index 000000000..80d182383 --- /dev/null +++ b/wk-code/wk-code-generator-nb/src/main/resources/templet/vue/index.html.vm @@ -0,0 +1,344 @@ + +#set($ttt="$") + +
+ +
+ + + ${msg['globals.button.add']} + +
+
+ + + #foreach ($column in $table.LabeledColumns) + + #end + + + +
+
+ + + ${msg['globals.button.delete.more']} + +
+
+ + + + + #foreach ($column in $table.LabeledColumns) + #set($temp = '${msg['''+${table.LocalePath}+'.column.'+${column.fieldName}+''']}') + + + #end + + + + + + + + + + + + + + #set ($columSize=0) + #foreach ($column in $table.LabeledColumns) + #set($columSize=$columSize+1) + #set($temp = '${msg['''+${table.LocalePath}+'.column.'+${column.fieldName}+''']}') + + + + #end + + + ${msg['globals.button.cancel']} + ${msg['globals.button.submit']} + + + + + + #set ($columSize=0) + #foreach ($column in $table.LabeledColumns) + #set($columSize=$columSize+1) + #set($temp = '${msg['''+${table.LocalePath}+'.column.'+${column.fieldName}+''']}') + + + + #end + + + ${msg['globals.button.cancel']} + ${msg['globals.button.submit']} + + +
+ + \ No newline at end of file diff --git a/wk-code/wk-code-generator-nb/src/main/resources/templet/vue_notlocale/index.html.vm b/wk-code/wk-code-generator-nb/src/main/resources/templet/vue_notlocale/index.html.vm new file mode 100644 index 000000000..eb3d97212 --- /dev/null +++ b/wk-code/wk-code-generator-nb/src/main/resources/templet/vue_notlocale/index.html.vm @@ -0,0 +1,340 @@ + +#set($ttt="$") + +
+ +
+ + + 新建 + +
+
+ + + #foreach ($column in $table.LabeledColumns) + + #end + + + +
+
+ + + 删除 + +
+
+ + + + + #foreach ($column in $table.LabeledColumns) + + + #end + + + + + + + + + + + + + + #set ($columSize=0) + #foreach ($column in $table.LabeledColumns) + #set($columSize=$columSize+1) + + + + #end + + + 取 消 + 确 定 + + + + + + #set ($columSize=0) + #foreach ($column in $table.LabeledColumns) + #set($columSize=$columSize+1) + + + + #end + + + 取 消 + 确 定 + + +
+ + \ No newline at end of file diff --git a/wk-code/wk-code-ideaplugin-nb/.idea/misc.xml b/wk-code/wk-code-ideaplugin-nb/.idea/misc.xml index 999b8a4d1..34b521fbe 100644 --- a/wk-code/wk-code-ideaplugin-nb/.idea/misc.xml +++ b/wk-code/wk-code-ideaplugin-nb/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/wk-code/wk-code-ideaplugin-nb/.idea/workspace.xml b/wk-code/wk-code-ideaplugin-nb/.idea/workspace.xml index 02199cd87..a98f66e7d 100644 --- a/wk-code/wk-code-ideaplugin-nb/.idea/workspace.xml +++ b/wk-code/wk-code-ideaplugin-nb/.idea/workspace.xml @@ -2,12 +2,23 @@ + + + + + + + + + + - - - + + + - - + + - - - - - - - - - - - + - - - - - - - - - - - + + - + @@ -90,6 +82,11 @@ + + + viewCheckBox + + @@ -98,10 +95,10 @@ @@ -118,11 +115,14 @@