Commit 7fc08338 authored by 左玲玲's avatar 左玲玲 😬

1654

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