master
wangbing 6 years ago
parent 911bf348b8
commit 219cbb7fa5

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

@ -13,8 +13,6 @@ 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 AndroidCallable implements Callable {
private Tool tool = new Tool();
@ -36,7 +34,7 @@ public class AndroidCallable implements Callable {
if (!project.exists()) {
project.mkdirs();
} else {
clear(project);
Tool.clear(project);
}
dBmapper = ProjectManager.dBmapper;

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

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

@ -16,8 +16,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.Callable;
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
public class SpringMVCCallable implements Callable {
private String root;
@ -44,7 +42,7 @@ public class SpringMVCCallable implements Callable {
if (!projectFile.exists()) {
projectFile.mkdir();
} else {
clear(projectFile);
Tool.clear(projectFile);
}
dBmapper = ProjectManager.dBmapper;
@ -181,7 +179,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
for (Table table : project.getTables()) {
@ -212,7 +210,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
try {
@ -241,7 +239,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
try {
@ -268,7 +266,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -297,7 +295,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
try {
HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -330,7 +328,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
try {
@ -368,7 +366,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
try {
@ -404,7 +402,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
try {
HashMap<String, Object> ctx = new HashMap<String, Object>();
@ -471,7 +469,7 @@ public class SpringMVCCallable implements Callable {
if (!root.exists()) {
root.mkdirs();
} else {
clear(root);
Tool.clear(root);
}
try {
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.ManagerFactory;
import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
import xyz.wbsite.dbtool.javafx.po.VueOption;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.javafx.tool.ZipUtil;
@ -10,9 +9,6 @@ import xyz.wbsite.dbtool.javafx.tool.ZipUtil;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.util.concurrent.Callable;
import java.util.zip.ZipFile;
import static xyz.wbsite.dbtool.javafx.tool.Tool.clear;
public class VueCallable implements Callable {
@ -27,28 +23,21 @@ public class VueCallable implements Callable {
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);
}
switch (option.type) {
case "vue":
Tool.outputResource("Vue/vue-simple.zip", new File(path, "vue-simple.zip"));
new ZipUtil().unZip(new File(path, "vue-simple.zip"),app);
break;
case "vue-element-admin":
Tool.outputResource("Vue/vue-element-admin.zip", new File(path, "vue-element-admin.zip"));
break;
case "vue-admin-template":
Tool.outputResource("Vue/vue-admin-template.zip", new File(path, "vue-admin-template.zip"));
break;
}
// 文件输出文件
File zipFile = new File(path, option.type + ".zip");
// 文件输出目录
File dir = new File(path, option.type);
// 清空输出目录
Tool.clear(dir);
System.out.println("清空文件" + dir.getAbsolutePath());
// 输出文件
Tool.outputResource("Vue/" + option.type + ".zip", zipFile);
// 解压文件
new ZipUtil().unZip(zipFile, new File(path));
// 删除文件
zipFile.delete();
System.out.println("删除文件" + zipFile.getAbsolutePath());
return true;
}
}

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

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

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

@ -9,53 +9,31 @@
<center>
<VBox prefHeight="200" prefWidth="300">
<children>
<GridPane prefHeight="40.0" prefWidth="300.0" BorderPane.alignment="CENTER">
<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>
<Label text="选择生成的Vue模板" prefHeight="50.0" prefWidth="300.0"/>
<VBox prefHeight="100.0" prefWidth="300.0">
<children>
<RadioButton mnemonicParsing="false" text="vue" id="1" selected="true">
<toggleGroup>
<ToggleGroup fx:id="type"/>
</toggleGroup>
<padding>
<Insets bottom="5.0"/>
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" text="vue-element-admin" id="2" toggleGroup="$type">
<padding>
<Insets bottom="5.0"/>
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" text="vue-admin-template" toggleGroup="$type">
<padding>
<Insets bottom="5.0"/>
</padding>
</RadioButton>
</children>
<RadioButton mnemonicParsing="false" text="vue-simple" id="1" selected="true">
<toggleGroup>
<ToggleGroup fx:id="type"/>
</toggleGroup>
<padding>
<Insets bottom="3.0" left="30.0" right="10.0" top="10.0"/>
<Insets bottom="5.0"/>
</padding>
</VBox>
</RadioButton>
<RadioButton mnemonicParsing="false" text="vue-element-admin" id="2" toggleGroup="$type">
<padding>
<Insets bottom="5.0"/>
</padding>
</RadioButton>
<RadioButton mnemonicParsing="false" text="vue-admin-template" toggleGroup="$type">
<padding>
<Insets bottom="5.0"/>
</padding>
</RadioButton>
</children>
<padding>
<Insets bottom="3.0" left="30.0" right="10.0" top="10.0"/>
</padding>
</VBox>
</center>
<bottom>

@ -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.