Commit 54767591 authored by yyh's avatar yyh

loading

parent eeefc23f
......@@ -75,6 +75,7 @@ const errorHandle = (status: number, other: any) => {
const instance = axios.create({ timeout: 1000 * 12});
// 设置post请求头
instance.defaults.headers.post['Content-Type'] = 'application/json';
/**
* 请求拦截器
* 每次请求前,如果存在token则在请求头中携带token
......@@ -86,7 +87,14 @@ instance.interceptors.request.use(
// 后台根据携带的token判断用户的登录情况,并返回给我们对应的状态码
// 而后我们可以在响应拦截器中,根据状态码进行一些统一的操作。
// token && (config.headers.Authorization = token);
const url = config.url as string;
if (url.indexOf('list') < 0 ) {
const toast = Toast({
type: 'loading',
duration: 0,
forbidClick: true,
});
}
config.cancelToken = new CancelToken((c) => {
removePendingAjax(config, c);
});
......@@ -102,6 +110,9 @@ instance.interceptors.response.use(
// 请求成功
(res: any) => {
removePendingAjax(res.config);
setTimeout(() => {
Toast.clear();
}, 200);
if ( res.status === 200) {
if (res.data.code === 200) {
return Promise.resolve(res.data.data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment