|
@@ -3,7 +3,17 @@ import qs from 'qs'
|
3
|
3
|
import toolClass from './util'
|
4
|
4
|
import router from '../pages/user/router'
|
5
|
5
|
import { Toast } from '../../node_modules/vant';
|
6
|
|
-var JWT = localStorage.getItem('JWT')
|
|
6
|
+
|
|
7
|
+const token = function (headers) {
|
|
8
|
+ let JWT
|
|
9
|
+ if (headers){
|
|
10
|
+ localStorage.setItem('JWT', headers.authorization)
|
|
11
|
+ JWT = headers.authorization
|
|
12
|
+ }
|
|
13
|
+ console.log(JWT)
|
|
14
|
+ return JWT ? JWT : localStorage.getItem('JWT')
|
|
15
|
+}
|
|
16
|
+
|
7
|
17
|
const Axios = axios.create({
|
8
|
18
|
timeout: 60000,
|
9
|
19
|
responseType: 'json',
|
|
@@ -12,11 +22,12 @@ const Axios = axios.create({
|
12
|
22
|
urlData: {},
|
13
|
23
|
headers: {
|
14
|
24
|
'Content-Type': 'multipart/form-data',
|
15
|
|
- 'authorization': JWT
|
|
25
|
+ 'authorization': token()
|
16
|
26
|
}
|
17
|
27
|
})
|
18
|
28
|
|
19
|
29
|
Axios.interceptors.request.use((config) => {
|
|
30
|
+ config.headers.authorization = token()
|
20
|
31
|
// 处理请求data,若为get请求,拼到url后面,若为post请求,直接添加到body中
|
21
|
32
|
config.urlData = { ...config.urlData, org: 'MQ' }
|
22
|
33
|
let urlData = qs.stringify(config.urlData)
|
|
@@ -51,8 +62,7 @@ const ajax = (...args) => {
|
51
|
62
|
return new Promise((resolve, reject) => {
|
52
|
63
|
Axios(...args).then(({ data, headers }) => {
|
53
|
64
|
if (headers.authorization) {
|
54
|
|
- localStorage.setItem('JWT', headers.authorization)
|
55
|
|
- JWT = headers.authorization
|
|
65
|
+ token(headers)
|
56
|
66
|
}
|
57
|
67
|
const { code, message, result } = data
|
58
|
68
|
if (code === 200) {
|