|
@@ -2,8 +2,12 @@
|
|
|
/* eslint-disable */
|
|
|
import axios from "axios"
|
|
|
// import router from '../router/index'
|
|
|
-import { browser } from '@/utils/common'
|
|
|
-import { Toast } from 'vant'
|
|
|
+import {
|
|
|
+ browser
|
|
|
+} from '@/utils/common'
|
|
|
+import {
|
|
|
+ Toast
|
|
|
+} from 'vant'
|
|
|
|
|
|
// Full config: https://github.com/axios/axios#request-config
|
|
|
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
@@ -11,42 +15,35 @@ import { Toast } from 'vant'
|
|
|
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
|
|
|
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);
|
|
|
|
|
|
_axios.interceptors.request.use(
|
|
|
- function(config) {
|
|
|
+ function (config) {
|
|
|
// Do something before request is sent
|
|
|
// 判断用户是否登录
|
|
|
- if(browser().android || browser().iPhone) { // app里面
|
|
|
- let userInfo = localStorage.getItem('Authorization')
|
|
|
- if(userInfo) {
|
|
|
- config.headers['Authorization'] = userInfo
|
|
|
- }
|
|
|
- } else { // 网页里面
|
|
|
- let auth = localStorage.getItem('userInfo')
|
|
|
- if(auth) {
|
|
|
- config.headers['Authorization'] = auth
|
|
|
- }
|
|
|
+ let userInfo = localStorage.getItem('Authorization')
|
|
|
+ if (userInfo) {
|
|
|
+ config.headers['Authorization'] = userInfo
|
|
|
}
|
|
|
// config.headers['Authorization'] ='bearer 8ffb419c-0d24-46b8-8faf-135ff24fa1d9'
|
|
|
return config;
|
|
|
},
|
|
|
- function(error) {
|
|
|
+ function (error) {
|
|
|
Toast.clear()
|
|
|
Toast('网络错误')
|
|
|
// Do something with request error
|
|
@@ -56,22 +53,26 @@ _axios.interceptors.request.use(
|
|
|
|
|
|
// Add a response interceptor
|
|
|
_axios.interceptors.response.use(
|
|
|
- function(response) {
|
|
|
+ function (response) {
|
|
|
// Do something with response data
|
|
|
- if(response.data.code == 403 || response.data.code == 403) {
|
|
|
+ if (response.data.code == 403 || response.data.code == 403) {
|
|
|
window.localStorage.removeItem('userInfo') // 删除用户信息
|
|
|
window.localStorage.removeItem('Authorization') // 删除用户信息
|
|
|
- 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'
|
|
|
+ }))
|
|
|
} else {
|
|
|
// router.push('/login')
|
|
|
}
|
|
|
}
|
|
|
return response;
|
|
|
},
|
|
|
- function(error) {
|
|
|
+ function (error) {
|
|
|
Toast.clear()
|
|
|
Toast('网络错误')
|
|
|
// Do something with response error
|
|
@@ -97,4 +98,4 @@ _axios.interceptors.response.use(
|
|
|
// };
|
|
|
|
|
|
// Vue.use(Plugin)
|
|
|
-export default _axios
|
|
|
+export default _axios
|