|
@@ -2,7 +2,7 @@
|
|
/* eslint-disable */
|
|
/* eslint-disable */
|
|
import axios from "axios"
|
|
import axios from "axios"
|
|
// import router from '../router/index'
|
|
// import router from '../router/index'
|
|
-import { browser } from '@/common/common'
|
|
|
|
|
|
+import { browser } from '@/common/common'
|
|
|
|
|
|
// Full config: https://github.com/axios/axios#request-config
|
|
// Full config: https://github.com/axios/axios#request-config
|
|
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
@@ -10,43 +10,43 @@ import { browser } from '@/common/common'
|
|
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
|
|
|
let config = {
|
|
let config = {
|
|
- // baseURL: process.env.baseURL || process.env.apiUrl || ""
|
|
|
|
- // timeout: 60 * 1000, // Timeout
|
|
|
|
- // withCredentials: true, // Check cross-site Access-Control
|
|
|
|
- // transformRequest: [function(data) {
|
|
|
|
- // console.log(data)
|
|
|
|
- // if(!data.qStringify) {
|
|
|
|
- // data = qs.stringify({
|
|
|
|
- // ...data
|
|
|
|
- // })
|
|
|
|
- // }
|
|
|
|
- // return data
|
|
|
|
- // }]
|
|
|
|
|
|
+ // baseURL: process.env.baseURL || process.env.apiUrl || ""
|
|
|
|
+ // timeout: 60 * 1000, // Timeout
|
|
|
|
+ // withCredentials: true, // Check cross-site Access-Control
|
|
|
|
+ // transformRequest: [function(data) {
|
|
|
|
+ // console.log(data)
|
|
|
|
+ // if(!data.qStringify) {
|
|
|
|
+ // data = qs.stringify({
|
|
|
|
+ // ...data
|
|
|
|
+ // })
|
|
|
|
+ // }
|
|
|
|
+ // return data
|
|
|
|
+ // }]
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
const _axios = axios.create(config);
|
|
const _axios = axios.create(config);
|
|
|
|
|
|
_axios.interceptors.request.use(
|
|
_axios.interceptors.request.use(
|
|
- function(config) {
|
|
|
|
|
|
+ function (config) {
|
|
// Do something before request is sent
|
|
// Do something before request is sent
|
|
// 判断用户是否登录
|
|
// 判断用户是否登录
|
|
- if(browser().android || browser().iPhone) { // app里面
|
|
|
|
|
|
+ if (browser().android || browser().iPhone) { // app里面
|
|
let userInfo = decodeURI(localStorage.getItem('Authorization'))
|
|
let userInfo = decodeURI(localStorage.getItem('Authorization'))
|
|
-
|
|
|
|
- if(userInfo) {
|
|
|
|
|
|
+
|
|
|
|
+ if (userInfo) {
|
|
config.headers['Authorization'] = userInfo
|
|
config.headers['Authorization'] = userInfo
|
|
}
|
|
}
|
|
} else { // 网页里面
|
|
} else { // 网页里面
|
|
let auth = decodeURI(localStorage.getItem('userInfo'))
|
|
let auth = decodeURI(localStorage.getItem('userInfo'))
|
|
- if(auth) {
|
|
|
|
|
|
+ if (auth) {
|
|
config.headers['Authorization'] = auth
|
|
config.headers['Authorization'] = auth
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // config.headers['Authorization'] ='bearer a8ecd31d-ed2d-4caa-9038-e85b8135af53'
|
|
|
|
|
|
+ config.headers['Authorization'] = 'bearer 5848d682-f5a3-4ce1-b86d-5b5f466ae665'
|
|
return config;
|
|
return config;
|
|
},
|
|
},
|
|
- function(error) {
|
|
|
|
|
|
+ function (error) {
|
|
// Do something with request error
|
|
// Do something with request error
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
}
|
|
}
|
|
@@ -54,21 +54,21 @@ _axios.interceptors.request.use(
|
|
|
|
|
|
// Add a response interceptor
|
|
// Add a response interceptor
|
|
_axios.interceptors.response.use(
|
|
_axios.interceptors.response.use(
|
|
- function(response) {
|
|
|
|
|
|
+ function (response) {
|
|
// Do something with response data
|
|
// Do something with response data
|
|
- if(response.data.code == 403) {
|
|
|
|
|
|
+ if (response.data.code == 403) {
|
|
window.localStorage.removeItem('userInfo') // 删除用户信息
|
|
window.localStorage.removeItem('userInfo') // 删除用户信息
|
|
window.localStorage.removeItem('Authorization') // 删除用户信息
|
|
window.localStorage.removeItem('Authorization') // 删除用户信息
|
|
// android ios 注册方法
|
|
// android ios 注册方法
|
|
- if(browser().android) {
|
|
|
|
- DAYA.postMessage(JSON.stringify({api: 'login'}))
|
|
|
|
- } else if(browser().iPhone) {
|
|
|
|
- window.webkit.messageHandlers.DAYA.postMessage(JSON.stringify({api: 'login'}))
|
|
|
|
- }
|
|
|
|
|
|
+ if (browser().android) {
|
|
|
|
+ DAYA.postMessage(JSON.stringify({ api: 'login' }))
|
|
|
|
+ } else if (browser().iPhone) {
|
|
|
|
+ window.webkit.messageHandlers.DAYA.postMessage(JSON.stringify({ api: 'login' }))
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return response;
|
|
return response;
|
|
},
|
|
},
|
|
- function(error) {
|
|
|
|
|
|
+ function (error) {
|
|
// Do something with response error
|
|
// Do something with response error
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
}
|
|
}
|