yuantianjiao 6 anos atrás
pai
commit
ca1657d223
3 arquivos alterados com 16 adições e 6 exclusões
  1. 2
    2
      config/index.js
  2. 1
    0
      package.json
  3. 13
    4
      src/util/ajax.js

+ 2
- 2
config/index.js Ver arquivo

@@ -13,8 +13,8 @@ module.exports = {
13 13
       '/api': {
14 14
         // target: 'https://dp.huiju360.com.cn/hj_operations',
15 15
         // target: 'http://192.168.0.62:8080', //wf
16
-        target: 'http://localhost:8080', 
17
-        // target: 'http://192.168.0.11', //ys
16
+        // target: 'http://localhost:8080', 
17
+        target: 'http://192.168.0.11', //ys
18 18
         // target: 'http://dev.ycjcjy.com/', //frp
19 19
         changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
20 20
         // pathRewrite: {

+ 1
- 0
package.json Ver arquivo

@@ -48,6 +48,7 @@
48 48
     "babel-register": "^6.22.0",
49 49
     "chalk": "^2.0.1",
50 50
     "chromedriver": "^2.27.2",
51
+    "clipboard": "^2.0.1",
51 52
     "copy-webpack-plugin": "^4.0.1",
52 53
     "cross-env": "^5.2.0",
53 54
     "cross-spawn": "^5.0.1",

+ 13
- 4
src/util/ajax.js Ver arquivo

@@ -3,7 +3,16 @@ import qs from 'qs'
3 3
 import router from '../router'
4 4
 import { Message } from 'element-ui'
5 5
 
6
-var JWT = localStorage.getItem('JWT')
6
+const token = function (headers) {
7
+  let JWT
8
+  if (headers){
9
+    localStorage.setItem('JWT', headers.authorization)
10
+    JWT = headers.authorization
11
+  }
12
+  console.log(JWT)
13
+  return JWT ? JWT : localStorage.getItem('JWT')
14
+}
15
+
7 16
 const Axios = axios.create({
8 17
   timeout: 60000,
9 18
   responseType: 'json',
@@ -12,11 +21,12 @@ const Axios = axios.create({
12 21
   urlData: {},
13 22
   headers: {
14 23
     'Content-Type': 'multipart/form-data',
15
-    'authorization': JWT
24
+    'authorization': token()
16 25
   }
17 26
 })
18 27
 
19 28
 Axios.interceptors.request.use((config) => {
29
+  config.headers.authorization = token()
20 30
   config.urlData = {...config.urlData, org: 'MQ'}
21 31
   // 处理请求data,若为get请求,拼到url后面,若为post请求,直接添加到body中
22 32
   let urlData = qs.stringify(config.urlData)
@@ -72,8 +82,7 @@ const ajax = (...args) => {
72 82
   return new Promise((resolve, reject) => {
73 83
     Axios(...args).then(({ data, headers }) => {
74 84
       if (headers.authorization) {
75
-        localStorage.setItem('JWT', headers.authorization)
76
-        JWT = headers.authorization
85
+        token(headers)
77 86
       }
78 87
       const { code, message, result } = data
79 88
       if (code === 200) {