Commit 7fc08338 authored by 左玲玲's avatar 左玲玲 :grimacing:

1654

parent 394bf9ae
......@@ -6,7 +6,7 @@ import { extend } from 'umi-request';
import { message, notification, Modal } from 'antd';
import { history } from '@umijs/max';
import qs from 'query-string';
const { NODE_ENV } = process.env; //development production
const codeMessage = {
200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。',
......@@ -55,23 +55,25 @@ const request = extend({
// request拦截器, 改变url 或 options.
request.interceptors.request.use(async (url, options) => {
let token = localStorage.getItem('TOKENES');
if (token) {
const headers =
options.type == 'form'
? {
Authorization: 'Bearer ' + token,
}
: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: 'Bearer ' + token,
};
return {
url: url,
options: { ...options, headers: headers, useCache: true, ttl: 2000 },
};
let token = localStorage.getItem('TOKENES') ?? "", headers = {};
if (NODE_ENV == "development" && url.indexOf("token") == -1 && token) {
headers = options.type == 'form' ? {
Authorization: "Bearer " + token
} : {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: "Bearer " + token
}
} else {
headers = options.type == 'form' ? {} : {
'Content-Type': 'application/json',
Accept: 'application/json'
}
}
return {
url: url,
options: { ...options, headers: headers, useCache: true, ttl: 2000 },
};
});
// response拦截器, 处理response
......
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