parent
5a11f27a45
commit
d5c0d98dab
@ -0,0 +1,10 @@
|
|||||||
|
package ${basePackage}.frame.excel.exception;
|
||||||
|
|
||||||
|
public class ReadErrorException extends Exception {
|
||||||
|
public ReadErrorException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadErrorException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package ${basePackage}.frame.excel.exception;
|
||||||
|
|
||||||
|
public class TemplateNotMatchException extends Exception {
|
||||||
|
public TemplateNotMatchException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public TemplateNotMatchException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
@ -1,302 +0,0 @@
|
|||||||
jsonService = axios.create({
|
|
||||||
method: 'post',
|
|
||||||
timeout: 30000,
|
|
||||||
baseURL: '/ajax',
|
|
||||||
headers: {'Content-Type': 'application/json;charset=UTF-8'},
|
|
||||||
});
|
|
||||||
downloadService = axios.create({
|
|
||||||
method: 'post',
|
|
||||||
timeout: 30000,
|
|
||||||
baseURL: '/ajax',
|
|
||||||
responseType: 'blob',
|
|
||||||
headers: {'Content-Type': 'application/json;charset=UTF-8'},
|
|
||||||
});
|
|
||||||
uploadService = axios.create({
|
|
||||||
method: 'post',
|
|
||||||
timeout: 30000,
|
|
||||||
baseURL: '/ajax',
|
|
||||||
headers: {'Content-Type': 'multipart/form-data'},
|
|
||||||
onUploadProgress: function (progressEvent) {
|
|
||||||
var complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%'
|
|
||||||
nav.tip.show("上传中(" + complete + ")")
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// 添加JSON请求拦截器
|
|
||||||
jsonService.interceptors.request.use(function (config) {
|
|
||||||
// 在发送请求之前做些什么
|
|
||||||
nav.bar.show();
|
|
||||||
nav.tip.show();
|
|
||||||
return config;
|
|
||||||
}, function (error) {
|
|
||||||
return Promise.reject(error);
|
|
||||||
});
|
|
||||||
uploadService.interceptors.request.use(function (config) {
|
|
||||||
// 在发送请求之前做些什么
|
|
||||||
nav.bar.show();
|
|
||||||
nav.tip.show("上传中 ...");
|
|
||||||
return config;
|
|
||||||
}, function (error) {
|
|
||||||
return Promise.reject(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 添加JSON响应拦截器
|
|
||||||
jsonService.interceptors.response.use(function (response) {
|
|
||||||
// 对响应数据做点什么
|
|
||||||
nav.tip.close();
|
|
||||||
try {//确保服务器正确返回Json
|
|
||||||
if(response.data.errors.length > 0){
|
|
||||||
console.error(response.data.errors)
|
|
||||||
}
|
|
||||||
nav.bar.finish();
|
|
||||||
}catch (e){
|
|
||||||
nav.bar.error();
|
|
||||||
response.data = {errors: [{message: '服务器响应错误'}]};
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}, function (error) {
|
|
||||||
// 对响应错误做点什么,并返回错误结果
|
|
||||||
nav.tip.close();
|
|
||||||
nav.bar.error();
|
|
||||||
const rsp = {errors: []};
|
|
||||||
if (!error.response) {
|
|
||||||
rsp.errors.push({message: error.message});
|
|
||||||
} else {
|
|
||||||
rsp.errors.push(handleError(error.response.status));
|
|
||||||
}
|
|
||||||
return Promise.reject(rsp);
|
|
||||||
});
|
|
||||||
// 添加Upload响应拦截器
|
|
||||||
uploadService.interceptors.response.use(function (response) {
|
|
||||||
// 对响应数据做点什么
|
|
||||||
nav.tip.close();
|
|
||||||
try {//确保服务器正确返回Json
|
|
||||||
if(response.data.errors.length > 0){
|
|
||||||
console.error(response.data.errors)
|
|
||||||
}
|
|
||||||
nav.bar.finish();
|
|
||||||
}catch (e){
|
|
||||||
nav.bar.error();
|
|
||||||
response.data = {errors: [{message: '服务器响应错误'}]};
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
}, function (error) {
|
|
||||||
// 对响应错误做点什么,并返回错误结果
|
|
||||||
nav.tip.close();
|
|
||||||
nav.bar.error();
|
|
||||||
const rsp = {errors: []};
|
|
||||||
if (!error.response) {
|
|
||||||
rsp.errors.push({message: error.message});
|
|
||||||
} else {
|
|
||||||
rsp.errors.push(handleError(error.response.status));
|
|
||||||
}
|
|
||||||
return Promise.reject(rsp);
|
|
||||||
});
|
|
||||||
function handerResponse(){
|
|
||||||
|
|
||||||
}
|
|
||||||
function handleError(status){
|
|
||||||
switch (status) {
|
|
||||||
case 401:
|
|
||||||
return {message: "未授权,请登录(401)"};
|
|
||||||
case 403:
|
|
||||||
return {message: "拒绝访问(403)"};
|
|
||||||
case 404:
|
|
||||||
return {message: "请求地址错误(404)"};
|
|
||||||
case 408:
|
|
||||||
return {message: "请求超时(408)"};
|
|
||||||
case 500:
|
|
||||||
return {message: "服务器内部错误(500)"};
|
|
||||||
case 501:
|
|
||||||
return {message: "服务未实现(501)"};
|
|
||||||
default:
|
|
||||||
return {message: "请求错误(" + error.response.status + ")"};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsonRequest = function (data) {
|
|
||||||
return jsonService.request(data)
|
|
||||||
.then(function (response) {
|
|
||||||
return Promise.resolve(response.data);
|
|
||||||
}, function (response) {
|
|
||||||
return Promise.resolve(response);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
upRequest = function (data) {
|
|
||||||
data.url='/upload';
|
|
||||||
return uploadService.request(data)
|
|
||||||
.then(function (response) {
|
|
||||||
return Promise.resolve(response.data);
|
|
||||||
}, function (response) {
|
|
||||||
return Promise.resolve(response);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
downRequest = function (data) {
|
|
||||||
return downloadService.request(data)
|
|
||||||
.then(function (response) {
|
|
||||||
if (!response.data) {
|
|
||||||
return Promise.resolve({errors: [{message: '下载错误'}]});
|
|
||||||
}
|
|
||||||
// 获取响应header中文件信息
|
|
||||||
var dis = response.headers['content-disposition'];
|
|
||||||
// 正则匹配文件名
|
|
||||||
var fileName = dis.match(/filename="(.*\..*)"/)[1];
|
|
||||||
// 模拟下载
|
|
||||||
var url = window.URL.createObjectURL(new Blob([response.data]));
|
|
||||||
var link = document.createElement('a')
|
|
||||||
link.style.display = 'none';
|
|
||||||
link.href = url;
|
|
||||||
link.setAttribute('download', fileName)
|
|
||||||
document.body.appendChild(link)
|
|
||||||
link.click();
|
|
||||||
return Promise.resolve({errors: []});
|
|
||||||
}, function (response) {
|
|
||||||
return Promise.resolve(response);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
window.ajax = {
|
|
||||||
authLogin: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/Auth/login",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
fileUpload: function (file) {
|
|
||||||
var fd = new FormData();
|
|
||||||
fd.append("file", file);
|
|
||||||
return upRequest({
|
|
||||||
data: fd
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictCreate: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/Dict/create",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictUpdate: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/Dict/update",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictDelete: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/Dict/delete",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictFind: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/Dict/find",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictGet: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/Dict/get",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictLoad: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/Dict/load",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictTemplate: function (data) {
|
|
||||||
return downRequest({
|
|
||||||
url: "/system/Dict/template",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictItemCreate: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/DictItem/create",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictItemUpdate: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/DictItem/update",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictItemDelete: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/DictItem/delete",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictItemFind: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/DictItem/find",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
dictItemGet: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/system/DictItem/get",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
<#list modules as db>
|
|
||||||
<#list db.tables as table>
|
|
||||||
<#if table.getCreate()>
|
|
||||||
${table.getFName()}Create: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/${db.moduleName}/${table.getCName()}/create",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getDelete()>
|
|
||||||
${table.getFName()}Delete: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/${db.moduleName}/${table.getCName()}/delete",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getUpdate()>
|
|
||||||
${table.getFName()}Update: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/${db.moduleName}/${table.getCName()}/update",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getFind()>
|
|
||||||
${table.getFName()}Find: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/${db.moduleName}/${table.getCName()}/find",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getGet()>
|
|
||||||
${table.getFName()}Get: function(data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/${db.moduleName}/${table.getCName()}/get",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getSearch()>
|
|
||||||
${table.getFName()}Search: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/${db.moduleName}/${table.getCName()}/search",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getGetAll()>
|
|
||||||
${table.getFName()}GetAll: function (data) {
|
|
||||||
return jsonRequest({
|
|
||||||
url: "/${db.moduleName}/${table.getCName()}/getAll",
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
</#list>
|
|
||||||
</#list>
|
|
||||||
}
|
|
@ -1,165 +0,0 @@
|
|||||||
import axios from 'axios'
|
|
||||||
// 创建axios实例
|
|
||||||
const service = axios.create({
|
|
||||||
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
|
|
||||||
withCredentials: true, // send cookies when cross-domain requests
|
|
||||||
method: 'post', // request method
|
|
||||||
timeout: 5000 // request timeout
|
|
||||||
})
|
|
||||||
|
|
||||||
// 添加请求拦截器
|
|
||||||
service.interceptors.request.use(config => {
|
|
||||||
// 在发送请求之前做些什么
|
|
||||||
if (config.url === '/upload') {
|
|
||||||
console.log()
|
|
||||||
} else {
|
|
||||||
console.log()
|
|
||||||
}
|
|
||||||
return config
|
|
||||||
}, error => {
|
|
||||||
// 对请求错误做些什么
|
|
||||||
return Promise.reject(error)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 添加响应拦截器
|
|
||||||
service.interceptors.response.use(response => {
|
|
||||||
// 对响应数据做点什么
|
|
||||||
return response
|
|
||||||
}, 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)
|
|
||||||
})
|
|
||||||
export function jsonRequest(config) {
|
|
||||||
return service.request({
|
|
||||||
params: {
|
|
||||||
method: config.method
|
|
||||||
},
|
|
||||||
url: '/ajax',
|
|
||||||
headers: { 'Content-Type': 'text/plain' },
|
|
||||||
data: config.data
|
|
||||||
}).then(response => {
|
|
||||||
return Promise.resolve(response.data)
|
|
||||||
}, response => {
|
|
||||||
return Promise.resolve(response)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
export function fileRequest(config) {
|
|
||||||
return service.request({
|
|
||||||
url: '/upload',
|
|
||||||
data: config.data,
|
|
||||||
headers: { 'Content-Type': 'multipart/form-data' },
|
|
||||||
onUploadProgress: progressEvent => {
|
|
||||||
console.log((progressEvent.loaded / progressEvent.total * 100 | 0) + '%')
|
|
||||||
}
|
|
||||||
}).then(response => {
|
|
||||||
return Promise.resolve(response.data)
|
|
||||||
}, response => {
|
|
||||||
return Promise.resolve(response)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const ajax = {
|
|
||||||
example: data => {
|
|
||||||
return jsonRequest({
|
|
||||||
method: 'ajax.example.example',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
},
|
|
||||||
fileUpload: file => {
|
|
||||||
const 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: data => {
|
|
||||||
return jsonRequest({
|
|
||||||
method:'ajax.${db.moduleName}.${table.getLName()}.create',
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getDelete()>
|
|
||||||
${table.getFName()}Delete: data => {
|
|
||||||
return jsonRequest({
|
|
||||||
method:'ajax.${db.moduleName}.${table.getLName()}.delete',
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getUpdate()>
|
|
||||||
${table.getFName()}Update: data => {
|
|
||||||
return jsonRequest({
|
|
||||||
method:'ajax.${db.moduleName}.${table.getLName()}.update',
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getFind()>
|
|
||||||
${table.getFName()}Find: data => {
|
|
||||||
return jsonRequest({
|
|
||||||
method:'ajax.${db.moduleName}.${table.getLName()}.find',
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getGet()>
|
|
||||||
${table.getFName()}Get: data => {
|
|
||||||
return jsonRequest({
|
|
||||||
method:'ajax.${db.moduleName}.${table.getLName()}.get',
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getSearch()>
|
|
||||||
${table.getFName()}Search: data => {
|
|
||||||
return jsonRequest({
|
|
||||||
method:'ajax.${db.moduleName}.${table.getLName()}.search',
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
<#if table.getGetAll()>
|
|
||||||
${table.getFName()}GetAll: data => {
|
|
||||||
return jsonRequest({
|
|
||||||
method:'ajax.${db.moduleName}.${table.getLName()}.get.all',
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
</#if>
|
|
||||||
</#list>
|
|
||||||
</#list>
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ajax
|
|
Loading…
Reference in new issue