You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.8 KiB
101 lines
2.8 KiB
import http from "./http";
|
|
import { baseUrl } from "../config/env";
|
|
// import qs from "qs";
|
|
// import {cache} from '@/store/store';
|
|
// 通用公用方法
|
|
const _get = (url, params, success, error) => {
|
|
return request("GET", url, params, success, error);
|
|
};
|
|
const _post = (url, params, success, error) => {
|
|
return request("POST", url, params, success, error);
|
|
};
|
|
const _post_paging = (url, params, success, error) => {
|
|
return request(
|
|
"POST",
|
|
url + "?pageNum=" + params.pageNum + "&pageSize=" + params.pageSize,
|
|
params,
|
|
success,
|
|
error
|
|
);
|
|
};
|
|
const _put = (url, params, success, error) => {
|
|
return request("PUT", url, params, success, error);
|
|
};
|
|
const _delete = (url, params, success, error) => {
|
|
return request("DELETE", url, params, success, error);
|
|
};
|
|
|
|
const _form = (url, params, success, error) => {
|
|
return request("FORM", url, params, success, error);
|
|
};
|
|
|
|
function request(type, url, params, success, error) {
|
|
let config = {
|
|
method: type,
|
|
url: baseUrl + url,
|
|
data: params
|
|
};
|
|
if (type == "GET") {
|
|
config.params = params;
|
|
} else {
|
|
config.data = params;
|
|
}
|
|
if (type == "FORM") {
|
|
config.method = "POST";
|
|
config.headers = { "Content-Type": "application/x-www-form-urlencoded" };
|
|
// config.data = qs.stringify(params);
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
http
|
|
.request(config)
|
|
.then(res => {
|
|
resolve(res.data);
|
|
if (res && res.data && res.data.code === 500) {
|
|
error && error(res.data);
|
|
return;
|
|
}
|
|
if (res.data) {
|
|
success && success(res.data);
|
|
return;
|
|
}
|
|
if (res.response.status == 403) {
|
|
error && error(res.data);
|
|
return;
|
|
}
|
|
if (res.response.data && res.response.data.message) {
|
|
error && error(res.data);
|
|
return Message.error({
|
|
type: "error",
|
|
message: res.response.data.message,
|
|
duration: 1500
|
|
});
|
|
}
|
|
if (res.response.status != 403) {
|
|
// let show = cache.getMemoryCache("isShow");
|
|
// if(!show){
|
|
// // Message.error({
|
|
// // type: "error",
|
|
// // message: "系统异常,程序员正在紧急修复",
|
|
// // duration: 1500
|
|
// // });
|
|
// }
|
|
error && error(res.data);
|
|
}
|
|
})
|
|
.catch(err => {
|
|
console.log(err);
|
|
reject(err.data);
|
|
// let show = cache.getMemoryCache("isShow");
|
|
// if(!show){
|
|
// // Message.error({
|
|
// // type: "error",
|
|
// // message: "系统异常,程序员正在紧急修复",
|
|
// // duration: 1500
|
|
// // });
|
|
// }
|
|
error && error(err.data);
|
|
});
|
|
});
|
|
}
|
|
|
|
export { _get, _post, _put, _delete, _form, _post_paging };
|
|
|