From 27bdea1e2631f7add19fd89b3db060b3689a8f99 Mon Sep 17 00:00:00 2001 From: wangbing Date: Sun, 12 May 2019 00:11:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbtool/javafx/ctrl/MainController.java | 5 + .../javafx/ctrl/VueOptionController.java | 60 + .../dbtool/javafx/manger/ProjectManager.java | 31 +- .../manger/callable/AndroidCallable.java | 1 - .../javafx/manger/callable/VueCallable.java | 77 + .../wbsite/dbtool/javafx/po/VueOption.java | 7 + .../xyz/wbsite/dbtool/javafx/tool/Dialog.java | 84 +- src/main/resources/fxml/main.fxml | 3 +- src/main/resources/fxml/vueOption.fxml | 54 + src/main/resources/modules/Android/.gitignore | 29 - src/main/resources/modules/Vue/README.md | 29 + .../resources/modules/Vue/babel.config.js | 5 + .../resources/modules/Vue/package-lock.json | 11578 ++++++++++++++++ src/main/resources/modules/Vue/package.json | 49 + .../resources/modules/Vue/public/favicon.ico | Bin 0 -> 4286 bytes .../resources/modules/Vue/public/index.html | 17 + src/main/resources/modules/Vue/src/App.vue | 33 + .../resources/modules/Vue/src/assets/logo.png | Bin 0 -> 6849 bytes .../modules/Vue/src/components/HelloWorld.vue | 66 + src/main/resources/modules/Vue/src/main.js | 11 + .../modules/Vue/src/plugins/element.js | 5 + src/main/resources/modules/Vue/src/router.js | 15 + 22 files changed, 12109 insertions(+), 50 deletions(-) create mode 100644 src/main/java/xyz/wbsite/dbtool/javafx/ctrl/VueOptionController.java create mode 100644 src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/VueCallable.java create mode 100644 src/main/java/xyz/wbsite/dbtool/javafx/po/VueOption.java create mode 100644 src/main/resources/fxml/vueOption.fxml delete mode 100644 src/main/resources/modules/Android/.gitignore create mode 100644 src/main/resources/modules/Vue/README.md create mode 100644 src/main/resources/modules/Vue/babel.config.js create mode 100644 src/main/resources/modules/Vue/package-lock.json create mode 100644 src/main/resources/modules/Vue/package.json create mode 100644 src/main/resources/modules/Vue/public/favicon.ico create mode 100644 src/main/resources/modules/Vue/public/index.html create mode 100644 src/main/resources/modules/Vue/src/App.vue create mode 100644 src/main/resources/modules/Vue/src/assets/logo.png create mode 100644 src/main/resources/modules/Vue/src/components/HelloWorld.vue create mode 100644 src/main/resources/modules/Vue/src/main.js create mode 100644 src/main/resources/modules/Vue/src/plugins/element.js create mode 100644 src/main/resources/modules/Vue/src/router.js diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java index a86034af..221fa8ed 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java @@ -195,6 +195,11 @@ public class MainController { } } + @FXML + public void generateVue(ActionEvent actionEvent) { + Dialog.showVue(); + } + @FXML public void generateApi(ActionEvent actionEvent) { Dialog.showApi(); diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/VueOptionController.java b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/VueOptionController.java new file mode 100644 index 00000000..9ae9cff4 --- /dev/null +++ b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/VueOptionController.java @@ -0,0 +1,60 @@ +package xyz.wbsite.dbtool.javafx.ctrl; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; +import javafx.scene.control.TextField; + +public class VueOptionController { + + @FXML + private TextField name; + @FXML + private CheckBox elementUI; + @FXML + private CheckBox iView; + @FXML + private Button ok; + @FXML + private Button cancel; + + public Button getOk() { + return ok; + } + + public void setOk(Button ok) { + this.ok = ok; + } + + public Button getCancel() { + return cancel; + } + + public void setCancel(Button cancel) { + this.cancel = cancel; + } + + public TextField getName() { + return name; + } + + public void setName(TextField name) { + this.name = name; + } + + public CheckBox getElementUI() { + return elementUI; + } + + public void setElementUI(CheckBox elementUI) { + this.elementUI = elementUI; + } + + public CheckBox getiView() { + return iView; + } + + public void setiView(CheckBox iView) { + this.iView = iView; + } +} diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java index c7e12f95..4e8835ee 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java @@ -3,10 +3,7 @@ package xyz.wbsite.dbtool.javafx.manger; import org.springframework.boot.system.ApplicationHome; import xyz.wbsite.dbtool.javafx.enumeration.DataBase; import xyz.wbsite.dbtool.javafx.enumeration.FieldType; -import xyz.wbsite.dbtool.javafx.manger.callable.AndroidCallable; -import xyz.wbsite.dbtool.javafx.manger.callable.SDKCallable; -import xyz.wbsite.dbtool.javafx.manger.callable.SpringBootCallable; -import xyz.wbsite.dbtool.javafx.manger.callable.SpringMVCMybatisCallable; +import xyz.wbsite.dbtool.javafx.manger.callable.*; import xyz.wbsite.dbtool.javafx.po.*; import xyz.wbsite.dbtool.javafx.tool.Dialog; @@ -317,7 +314,7 @@ public class ProjectManager { } } - public void generateAndroid(final String path, AndroidOption option) { + public void generate(final String path, AndroidOption option) { Dialog.showProgress("生成中..."); new Thread() { @Override @@ -341,6 +338,30 @@ public class ProjectManager { }.start(); } + public void generate(final String path, VueOption option) { + Dialog.showProgress("生成中..."); + new Thread() { + @Override + public void run() { + VueCallable vueCallable = new VueCallable(path, option); + Future submit = service.submit(vueCallable); + try { + Boolean b = (Boolean) submit.get(); + if (!b) { + Dialog.showError("请确认目录结构是否存在或正确!"); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + + Dialog.stopPopup(); + Dialog.showSuccess("Vue生成完成."); + } + }.start(); + } + public void invalidate() { project = xmlService.inflate(path); } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/AndroidCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/AndroidCallable.java index b0c53708..7436f9a0 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/AndroidCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/AndroidCallable.java @@ -82,7 +82,6 @@ public class AndroidCallable implements Callable { values.mkdirs(); { - Tool.outputResource("Android/.gitignore", new File(project, ".gitignore")); Tool.outputResource("Android/build.gradles", new File(project, "build.gradle")); Tool.outputResource("Android/settings.gradles", new File(project, "settings.gradle")); } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/VueCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/VueCallable.java new file mode 100644 index 00000000..be767722 --- /dev/null +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/VueCallable.java @@ -0,0 +1,77 @@ +package xyz.wbsite.dbtool.javafx.manger.callable; + +import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager; +import xyz.wbsite.dbtool.javafx.manger.ManagerFactory; +import xyz.wbsite.dbtool.javafx.manger.ProjectManager; +import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper; +import xyz.wbsite.dbtool.javafx.po.AndroidOption; +import xyz.wbsite.dbtool.javafx.po.VueOption; +import xyz.wbsite.dbtool.javafx.tool.Tool; + +import javax.validation.constraints.NotNull; +import java.io.File; +import java.util.HashMap; +import java.util.concurrent.Callable; +import java.util.regex.Matcher; + +import static xyz.wbsite.dbtool.javafx.tool.Tool.clear; + +public class VueCallable implements Callable { + + private String path; + private VueOption option; + + private FreeMarkerManager freeMarkerManager; + + public VueCallable(@NotNull String path, VueOption option) { + this.path = path; + this.option = option; + this.freeMarkerManager = ManagerFactory.getFreeMarkerManager(); + } + + private AbstractDBmapper dBmapper; + + public Boolean call() throws Exception { + File app = new File(path, option.projectName); + if (!app.exists()) { + app.mkdirs(); + } else { + clear(app); + } + + // 目录生成 + File src = new File(app, "src"); + src.mkdirs(); + File assets = new File(src, "assets"); + assets.mkdirs(); + File components = new File(src, "components"); + components.mkdirs(); + File plugins = new File(src, "plugins"); + plugins.mkdirs(); + File publics = new File(app, "public"); + publics.mkdirs(); + + { + HashMap ctx = new HashMap(); + ctx.put("appName", option.projectName); + freeMarkerManager.outputTemp(new File(app, "package.json"), "Vue/package.json", ctx); + freeMarkerManager.outputTemp(new File(app, "package-lock.json"), "Vue/package-lock.json", ctx); + freeMarkerManager.outputTemp(new File(app, "README.md"), "Vue/README.md", ctx); + Tool.outputResource("Vue/babel.config.js", new File(app, "babel.config.js")); + + //public + Tool.outputResource("Vue/public/favicon.ico", new File(publics, "favicon.ico")); + Tool.outputResource("Vue/public/index.html", new File(publics, "index.html")); + + //src + freeMarkerManager.outputTemp(new File(src, "App.vue"), "Vue/src/App.vue", ctx); + Tool.outputResource("Vue/src/main.js", new File(src, "main.js")); + Tool.outputResource("Vue/src/router.js", new File(src, "router.js")); + Tool.outputResource("Vue/src/assets/logo.png", new File(assets, "logo.png")); + Tool.outputResource("Vue/src/components/HelloWorld.vue", new File(components, "HelloWorld.vue")); + Tool.outputResource("Vue/src/plugins/element.js", new File(plugins, "element.js")); + } + + return true; + } +} diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/po/VueOption.java b/src/main/java/xyz/wbsite/dbtool/javafx/po/VueOption.java new file mode 100644 index 00000000..5a6d96e9 --- /dev/null +++ b/src/main/java/xyz/wbsite/dbtool/javafx/po/VueOption.java @@ -0,0 +1,7 @@ +package xyz.wbsite.dbtool.javafx.po; + +public class VueOption { + public String projectName; + public boolean elementui; + public boolean iView; +} diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java index 1d6918e0..830e7ee6 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java @@ -1,17 +1,5 @@ package xyz.wbsite.dbtool.javafx.tool; -import xyz.wbsite.dbtool.Application; -import xyz.wbsite.dbtool.javafx.ctrl.AndroidOptionController; -import xyz.wbsite.dbtool.javafx.ctrl.ConnectInfoController; -import xyz.wbsite.dbtool.javafx.ctrl.GenerateOptionController; -import xyz.wbsite.dbtool.javafx.ctrl.SdkInfoController; -import xyz.wbsite.dbtool.javafx.enumeration.DataBase; -import xyz.wbsite.dbtool.javafx.listener.GenerateOptionListener; -import xyz.wbsite.dbtool.javafx.manger.ProjectManager; -import xyz.wbsite.dbtool.javafx.manger.ManagerFactory; -import xyz.wbsite.dbtool.javafx.po.AndroidOption; -import xyz.wbsite.dbtool.javafx.po.Api; -import xyz.wbsite.dbtool.javafx.po.Module; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; @@ -30,6 +18,16 @@ import javafx.stage.DirectoryChooser; import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.WindowEvent; +import xyz.wbsite.dbtool.Application; +import xyz.wbsite.dbtool.javafx.ctrl.*; +import xyz.wbsite.dbtool.javafx.enumeration.DataBase; +import xyz.wbsite.dbtool.javafx.listener.GenerateOptionListener; +import xyz.wbsite.dbtool.javafx.manger.ManagerFactory; +import xyz.wbsite.dbtool.javafx.manger.ProjectManager; +import xyz.wbsite.dbtool.javafx.po.AndroidOption; +import xyz.wbsite.dbtool.javafx.po.Api; +import xyz.wbsite.dbtool.javafx.po.Module; +import xyz.wbsite.dbtool.javafx.po.VueOption; import java.io.File; import java.io.IOException; @@ -580,7 +578,7 @@ public class Dialog { directoryChooser.setInitialDirectory(new File(dBmanger.getPath())); Stage stage = new Stage(); File file = directoryChooser.showDialog(stage); - if (file!=null){ + if (file != null) { System.out.println("生成目录:" + file.getAbsolutePath()); AndroidOption androidOption = new AndroidOption(); androidOption.projectName = controller.getName().getText(); @@ -590,7 +588,65 @@ public class Dialog { androidOption.qrcode = controller.getQrcode().isSelected(); androidOption.fileselect = controller.getFileselect().isSelected(); - dBmanger.generateAndroid(file.getAbsolutePath(), androidOption); + dBmanger.generate(file.getAbsolutePath(), androidOption); + Platform.runLater(new Runnable() { + @Override + public void run() { + stage.close(); + } + }); + } + } + }); + + popup = new Stage(); + popup.initModality(Modality.APPLICATION_MODAL); + + Scene scene = new Scene(root); + + popup.setOnCloseRequest(new EventHandler() { + @Override + public void handle(WindowEvent event) { + stopPopup(); + } + }); + popup.setScene(scene); + popup.setTitle("配置"); + popup.show(); + } + + public static void showVue() { + FXMLLoader dbdetailloader = new FXMLLoader(Application.class.getResource("../../../fxml/vueOption.fxml")); + try { + dbdetailloader.load(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + Parent root = dbdetailloader.getRoot(); + VueOptionController controller = dbdetailloader.getController(); + controller.getCancel().setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + stopPopup(); + } + }); + controller.getOk().setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + ProjectManager dBmanger = ManagerFactory.getdBManager(); + DirectoryChooser directoryChooser = new DirectoryChooser(); + directoryChooser.setInitialDirectory(new File(dBmanger.getPath())); + Stage stage = new Stage(); + File file = directoryChooser.showDialog(stage); + if (file != null) { + System.out.println("生成目录:" + file.getAbsolutePath()); + VueOption vueOption = new VueOption(); + vueOption.projectName = controller.getName().getText(); + vueOption.elementui = controller.getElementUI().isSelected(); + vueOption.iView = controller.getiView().isSelected(); + + dBmanger.generate(file.getAbsolutePath(), vueOption); Platform.runLater(new Runnable() { @Override public void run() { diff --git a/src/main/resources/fxml/main.fxml b/src/main/resources/fxml/main.fxml index b586caca..95f7c159 100644 --- a/src/main/resources/fxml/main.fxml +++ b/src/main/resources/fxml/main.fxml @@ -16,7 +16,8 @@ - + + diff --git a/src/main/resources/fxml/vueOption.fxml b/src/main/resources/fxml/vueOption.fxml new file mode 100644 index 00000000..488f5e36 --- /dev/null +++ b/src/main/resources/fxml/vueOption.fxml @@ -0,0 +1,54 @@ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +