|
@@ -4,6 +4,8 @@ import store from '@/store'
|
|
|
import { getToken } from '@/utils/auth'
|
|
import { getToken } from '@/utils/auth'
|
|
|
import errorCode from '@/utils/errorCode'
|
|
import errorCode from '@/utils/errorCode'
|
|
|
import { tansParams } from "@/utils/huyi";
|
|
import { tansParams } from "@/utils/huyi";
|
|
|
|
|
+import { getRepeatToken } from "@/utils/common";
|
|
|
|
|
+
|
|
|
|
|
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
// 创建axios实例
|
|
// 创建axios实例
|
|
@@ -14,6 +16,7 @@ const service = axios.create({
|
|
|
timeout: 10000
|
|
timeout: 10000
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+const repeatToken = getRepeatToken();
|
|
|
// request拦截器
|
|
// request拦截器
|
|
|
service.interceptors.request.use(config => {
|
|
service.interceptors.request.use(config => {
|
|
|
// 是否需要设置 token
|
|
// 是否需要设置 token
|
|
@@ -21,6 +24,10 @@ service.interceptors.request.use(config => {
|
|
|
if (getToken() && !isToken) {
|
|
if (getToken() && !isToken) {
|
|
|
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
}
|
|
}
|
|
|
|
|
+ const repeat = config.repeat;
|
|
|
|
|
+ if (repeat) {
|
|
|
|
|
+ config.headers['repeatToken'] = repeatToken + ":" + config.url;
|
|
|
|
|
+ }
|
|
|
// get请求映射params参数
|
|
// get请求映射params参数
|
|
|
if (config.method === 'get' && config.params) {
|
|
if (config.method === 'get' && config.params) {
|
|
|
let url = config.url + '?';
|
|
let url = config.url + '?';
|
|
@@ -52,7 +59,7 @@ service.interceptors.request.use(config => {
|
|
|
// console.log(typeof(config.data));
|
|
// console.log(typeof(config.data));
|
|
|
if(typeof(config.data)=== 'object'){
|
|
if(typeof(config.data)=== 'object'){
|
|
|
for (const propName of Object.keys(config.data)) {
|
|
for (const propName of Object.keys(config.data)) {
|
|
|
- if(config.data[propName]){
|
|
|
|
|
|
|
+ if(config.data[propName]){
|
|
|
if(typeof(config.data[propName])=="string"){
|
|
if(typeof(config.data[propName])=="string"){
|
|
|
config.data[propName] = config.data[propName].trim();
|
|
config.data[propName] = config.data[propName].trim();
|
|
|
}
|
|
}
|