master
wangbing 6 years ago
parent 911bf348b8
commit 219cbb7fa5

@ -8,8 +8,6 @@ import javafx.scene.control.ToggleGroup;
public class OptionVueController { public class OptionVueController {
@FXML
private TextField name;
@FXML @FXML
private Button ok; private Button ok;
@FXML @FXML
@ -33,14 +31,6 @@ public class OptionVueController {
this.cancel = cancel; this.cancel = cancel;
} }
public TextField getName() {
return name;
}
public void setName(TextField name) {
this.name = name;
}
public ToggleGroup getType() { public ToggleGroup getType() {
return type; return type;
} }

@ -13,8 +13,6 @@ import java.util.HashMap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
public class AndroidCallable implements Callable { public class AndroidCallable implements Callable {
private Tool tool = new Tool(); private Tool tool = new Tool();
@ -36,7 +34,7 @@ public class AndroidCallable implements Callable {
if (!project.exists()) { if (!project.exists()) {
project.mkdirs(); project.mkdirs();
} else { } else {
clear(project); Tool.clear(project);
} }
dBmapper = ProjectManager.dBmapper; dBmapper = ProjectManager.dBmapper;

@ -14,8 +14,6 @@ import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
public class SDKCallable implements Callable { public class SDKCallable implements Callable {
private File sdk; private File sdk;
@ -44,7 +42,7 @@ public class SDKCallable implements Callable {
if (!sdk.exists()) { if (!sdk.exists()) {
sdk.mkdir(); sdk.mkdir();
} else { } else {
clear(sdk); Tool.clear(sdk);
} }
dBmapper = ProjectManager.dBmapper; dBmapper = ProjectManager.dBmapper;

@ -13,8 +13,6 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
public class SpringBootCallable implements Callable { public class SpringBootCallable implements Callable {
private String root; private String root;
@ -44,7 +42,7 @@ public class SpringBootCallable implements Callable {
if (!projectDir.exists()) { if (!projectDir.exists()) {
projectDir.mkdir(); projectDir.mkdir();
} else { } else {
clear(projectDir); Tool.clear(projectDir);
} }
// 生成POM // 生成POM
@ -204,7 +202,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("basePackage", project.getProjectBasePackage()); ctx.put("basePackage", project.getProjectBasePackage());
@ -230,7 +228,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("basePackage", project.getProjectBasePackage()); ctx.put("basePackage", project.getProjectBasePackage());
@ -255,7 +253,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
for (Table table : md.getTables()) { for (Table table : md.getTables()) {
@ -283,7 +281,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -319,7 +317,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -342,7 +340,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -375,7 +373,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -431,7 +429,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -487,7 +485,7 @@ public class SpringBootCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("basePackage", project.getProjectBasePackage()); ctx.put("basePackage", project.getProjectBasePackage());

@ -16,8 +16,6 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
public class SpringMVCCallable implements Callable { public class SpringMVCCallable implements Callable {
private String root; private String root;
@ -44,7 +42,7 @@ public class SpringMVCCallable implements Callable {
if (!projectFile.exists()) { if (!projectFile.exists()) {
projectFile.mkdir(); projectFile.mkdir();
} else { } else {
clear(projectFile); Tool.clear(projectFile);
} }
dBmapper = ProjectManager.dBmapper; dBmapper = ProjectManager.dBmapper;
@ -181,7 +179,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
for (Table table : project.getTables()) { for (Table table : project.getTables()) {
@ -212,7 +210,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
try { try {
@ -241,7 +239,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
try { try {
@ -268,7 +266,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -297,7 +295,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
try { try {
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -330,7 +328,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
try { try {
@ -368,7 +366,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
try { try {
@ -404,7 +402,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
try { try {
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -471,7 +469,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
} else { } else {
clear(root); Tool.clear(root);
} }
try { try {
HashMap<String, Object> ctx = new HashMap<String, Object>(); HashMap<String, Object> ctx = new HashMap<String, Object>();

@ -2,7 +2,6 @@ package xyz.wbsite.dbtool.javafx.manger.callable;
import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager; import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory; import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
import xyz.wbsite.dbtool.javafx.po.VueOption; import xyz.wbsite.dbtool.javafx.po.VueOption;
import xyz.wbsite.dbtool.javafx.tool.Tool; import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.javafx.tool.ZipUtil; import xyz.wbsite.dbtool.javafx.tool.ZipUtil;
@ -10,9 +9,6 @@ import xyz.wbsite.dbtool.javafx.tool.ZipUtil;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.File; import java.io.File;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.zip.ZipFile;
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
public class VueCallable implements Callable { public class VueCallable implements Callable {
@ -27,28 +23,21 @@ public class VueCallable implements Callable {
this.freeMarkerManager = ManagerFactory.getFreeMarkerManager(); this.freeMarkerManager = ManagerFactory.getFreeMarkerManager();
} }
private AbstractDBmapper dBmapper;
public Boolean call() throws Exception { public Boolean call() throws Exception {
File app = new File(path, option.projectName); // 文件输出文件
if (!app.exists()) { File zipFile = new File(path, option.type + ".zip");
app.mkdirs(); // 文件输出目录
} else { File dir = new File(path, option.type);
clear(app); // 清空输出目录
} Tool.clear(dir);
System.out.println("清空文件" + dir.getAbsolutePath());
switch (option.type) { // 输出文件
case "vue": Tool.outputResource("Vue/" + option.type + ".zip", zipFile);
Tool.outputResource("Vue/vue-simple.zip", new File(path, "vue-simple.zip")); // 解压文件
new ZipUtil().unZip(new File(path, "vue-simple.zip"),app); new ZipUtil().unZip(zipFile, new File(path));
break; // 删除文件
case "vue-element-admin": zipFile.delete();
Tool.outputResource("Vue/vue-element-admin.zip", new File(path, "vue-element-admin.zip")); System.out.println("删除文件" + zipFile.getAbsolutePath());
break;
case "vue-admin-template":
Tool.outputResource("Vue/vue-admin-template.zip", new File(path, "vue-admin-template.zip"));
break;
}
return true; return true;
} }
} }

@ -1,6 +1,5 @@
package xyz.wbsite.dbtool.javafx.po; package xyz.wbsite.dbtool.javafx.po;
public class VueOption { public class VueOption {
public String projectName;
public String type; public String type;
} }

@ -639,7 +639,6 @@ public class Dialog {
if (file != null) { if (file != null) {
System.out.println("生成目录:" + file.getAbsolutePath()); System.out.println("生成目录:" + file.getAbsolutePath());
VueOption vueOption = new VueOption(); VueOption vueOption = new VueOption();
vueOption.projectName = controller.getName().getText();
ToggleGroup type = controller.getType(); ToggleGroup type = controller.getType();
RadioButton value = (RadioButton) type.selectedToggleProperty().getValue(); RadioButton value = (RadioButton) type.selectedToggleProperty().getValue();
vueOption.type = value.textProperty().getValue(); vueOption.type = value.textProperty().getValue();

@ -2,7 +2,6 @@ package xyz.wbsite.dbtool.javafx.tool;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -336,9 +335,9 @@ public class Tool {
for (File file : files) { for (File file : files) {
if (file.isDirectory()) { if (file.isDirectory()) {
clear(file, exclude); clear(file, exclude);
System.out.println("删除文件夹" + file.getName() + (file.delete() ? "成功" : "失败")); // System.out.println("删除文件夹" + file.getName() + (file.delete() ? "成功" : "失败"));
} else { } else {
System.out.println("删除" + file.getName() + (file.delete() ? "成功" : "失败")); // System.out.println("删除" + file.getName() + (file.delete() ? "成功" : "失败"));
} }
} }
} }

@ -1,67 +1,69 @@
package xyz.wbsite.dbtool.javafx.tool; package xyz.wbsite.dbtool.javafx.tool;
import java.io.*; import java.io.File;
import java.nio.charset.Charset; import java.io.FileOutputStream;
import java.util.ArrayList; import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
public class ZipUtil { public class ZipUtil {
public boolean unZip(File zipFile, File descDir) {
return unZip(zipFile, descDir, new ArrayList<>());
}
/** /**
* *
* *
* @param zipFile * @param zipFile
* @param descDir * @param descDir
* @param urlList
* @return * @return
*/ */
public boolean unZip(File zipFile, File descDir, List<String> urlList) { public void unZip(File zipFile, File descDir) {
boolean flag = false;
if (!descDir.exists()) { if (!descDir.exists()) {
descDir.mkdirs(); descDir.mkdirs();
} }
ZipFile zip = null; ZipFile zip = null;
System.out.println("解压文件" + zipFile.getAbsolutePath());
try { try {
//指定编码,否则压缩包里面不能有中文目录 zip = new ZipFile(zipFile);
zip = new ZipFile(zipFile, Charset.forName("gbk")); Enumeration<?> entries = zip.entries();
for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) { while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement(); ZipEntry entry = (ZipEntry) entries.nextElement();
String zipEntryName = entry.getName(); // 如果是文件夹,就创建个文件夹
InputStream in = zip.getInputStream(entry); if (entry.isDirectory()) {
File outPath = new File(descDir, zipEntryName); String dirPath = descDir + "/" + entry.getName();
//判断路径是否存在,不存在则创建文件路径 File dir = new File(dirPath);
if (!outPath.getParentFile().exists()) { dir.mkdirs();
outPath.getParentFile().mkdirs(); } else {
// 如果是文件就先创建一个文件然后用io流把内容copy过去
File targetFile = new File(descDir + "/" + entry.getName());
// 保证这个文件的父文件夹必须要存在
if (!targetFile.getParentFile().exists()) {
targetFile.getParentFile().mkdirs();
} }
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压 targetFile.createNewFile();
if (outPath.isDirectory()) { // 将压缩文件内容写入到这个文件中
continue; InputStream is = zip.getInputStream(entry);
} FileOutputStream fos = new FileOutputStream(targetFile);
//保存文件路径信息
urlList.add(outPath.getAbsolutePath());
OutputStream out = new FileOutputStream(outPath);
byte[] buf1 = new byte[2048];
int len; int len;
while ((len = in.read(buf1)) > 0) { byte[] buf = new byte[1024];
out.write(buf1, 0, len); while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
} }
in.close(); // 关流顺序,先打开的后关闭
out.close(); fos.close();
is.close();
} }
flag = true; }
//必须关闭否则无法删除该zip文件 } catch (Exception e) {
throw new RuntimeException("unzip error from ZipUtils", e);
} finally {
if (zip != null) {
try {
zip.close(); zip.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return flag; }
}
} }
} }

@ -9,30 +9,9 @@
<center> <center>
<VBox prefHeight="200" prefWidth="300"> <VBox prefHeight="200" prefWidth="300">
<children> <children>
<GridPane prefHeight="40.0" prefWidth="300.0" BorderPane.alignment="CENTER"> <Label text="选择生成的Vue模板" prefHeight="50.0" prefWidth="300.0"/>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" prefWidth="80.0"/>
<ColumnConstraints hgrow="SOMETIMES" prefWidth="200.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label text="项目名称" GridPane.halignment="CENTER" GridPane.rowIndex="0"
GridPane.valignment="CENTER"/>
<TextField fx:id="name" text="my-app" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
</children>
<opaqueInsets>
<Insets/>
</opaqueInsets>
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</GridPane>
<VBox prefHeight="100.0" prefWidth="300.0"> <RadioButton mnemonicParsing="false" text="vue-simple" id="1" selected="true">
<children>
<RadioButton mnemonicParsing="false" text="vue" id="1" selected="true">
<toggleGroup> <toggleGroup>
<ToggleGroup fx:id="type"/> <ToggleGroup fx:id="type"/>
</toggleGroup> </toggleGroup>
@ -51,12 +30,11 @@
</padding> </padding>
</RadioButton> </RadioButton>
</children> </children>
<padding> <padding>
<Insets bottom="3.0" left="30.0" right="10.0" top="10.0"/> <Insets bottom="3.0" left="30.0" right="10.0" top="10.0"/>
</padding> </padding>
</VBox> </VBox>
</children>
</VBox>
</center> </center>
<bottom> <bottom>
<Pane prefHeight="50.0" prefWidth="300.0" BorderPane.alignment="CENTER"> <Pane prefHeight="50.0" prefWidth="300.0" BorderPane.alignment="CENTER">

@ -0,0 +1,170 @@
import axios from 'axios'
//创建axios实例
const instance = axios.create({
method: 'post',
timeout: 30000,
});
// 添加请求拦截器
instance.interceptors.request.use(function (config) {
// 在发送请求之前做些什么
if (config.url == '/upload') {
} else {
}
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});
// 添加响应拦截器
instance.interceptors.response.use(function (response) {
// 对响应数据做点什么
try {//确保服务器正确返回Json
if(response.data.errors.length > 0){
console.error(response.data.errors)
}
}catch (e){
response.data = {errors: [{message: '服务器错误'}]};
}
return response;
}, function (error) {
// 对响应错误做点什么,保准化返回结果
const rsp = {errors: []};
if (!error.response) {
rsp.errors.push({message: error.message});
} else {
switch (error.response.status) {
case 401:
rsp.errors.push({message: "未授权,请登录(401)"});
break
case 403:
rsp.errors.push({message: "拒绝访问(403)"});
break
case 404:
rsp.errors.push({message: "请求地址错误(404)"});
break
case 408:
rsp.errors.push({message: "请求超时(408)"});
break
case 500:
rsp.errors.push({message: "服务器内部错误(500)"});
break
case 501:
rsp.errors.push({message: "服务未实现(501)"});
break
default:
rsp.errors.push({message: "请求错误(" + error.response.status + ")"});
break
}
}
return Promise.reject(rsp);
});
let jsonRequest = function (config) {
return instance.request({
params: {
method: config.method
},
url: '${contextPath?default("")}/ajax',
headers: {'Content-Type': 'text/plain'},
data: config.data
}).then(function (response) {
return Promise.resolve(response.data);
}, function (response) {
return Promise.resolve(response);
})
};
let fileRequest = function (config) {
return instance.request({
url: '${contextPath?default("")}/upload',
data: config.data,
headers: {'Content-Type': 'multipart/form-data'},
onUploadProgress: function (progressEvent) {
var complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%'
nav.tip.show("上传中(" + complete + ")")
}
}).then(function (response) {
return Promise.resolve(response.data);
}, function (response) {
return Promise.resolve(response);
})
};
let ajax = {
example: function (data) {
return jsonRequest({
method: "ajax.example.example",
data: data
})
},
fileUpload: function (file) {
var fd = new FormData();
fd.append("file", file);
return fileRequest({
data: fd
})
},
<#list modules as db>
<#list db.tables as table>
<#if table.getCreate()>
${table.getFName()}Create: function (data) {
return jsonRequest({
method:"ajax.${db.moduleName}.${table.getLName()}.create",
data: JSON.stringify(data),
})
},
</#if>
<#if table.getDelete()>
${table.getFName()}Delete: function (data) {
return jsonRequest({
method:"ajax.${db.moduleName}.${table.getLName()}.delete",
data: JSON.stringify(data),
})
},
</#if>
<#if table.getUpdate()>
${table.getFName()}Update: function (data) {
return jsonRequest({
method:"ajax.${db.moduleName}.${table.getLName()}.update",
data: JSON.stringify(data),
})
},
</#if>
<#if table.getFind()>
${table.getFName()}Find: function (data) {
return jsonRequest({
method:"ajax.${db.moduleName}.${table.getLName()}.find",
data: JSON.stringify(data),
})
},
</#if>
<#if table.getGet()>
${table.getFName()}Get: function(data) {
return jsonRequest({
method:"ajax.${db.moduleName}.${table.getLName()}.get",
data: JSON.stringify(data),
})
},
</#if>
<#if table.getSearch()>
${table.getFName()}Search: function (data) {
return jsonRequest({
method:"ajax.${db.moduleName}.${table.getLName()}.search",
data: JSON.stringify(data),
})
},
</#if>
<#if table.getGetAll()>
${table.getFName()}GetAll: function (data) {
return jsonRequest({
method:"ajax.${db.moduleName}.${table.getLName()}.get.all",
data: JSON.stringify(data),
})
},
</#if>
</#list>
</#list>
}
export default ajax
Loading…
Cancel
Save

Powered by TurnKey Linux.