vue2-client 1.2.113 → 1.2.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Change Log
2
2
  > 所有关于本项目的变化都在该文档里。
3
3
 
4
- **1.2.113 -2022-09-02 @江超**
4
+ **1.2.113 - 1.2.114 -2022-09-02 @江超**
5
5
  - 功能修改:
6
6
  - 修改请求后只有当返回的token有值时才设置store
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2-client",
3
- "version": "1.2.113",
3
+ "version": "1.2.114",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -207,14 +207,8 @@ export default {
207
207
  setAuthorization({ token: data, expireAt: dateAfter })
208
208
  },
209
209
  setV4AccessToken (data) {
210
- if (data.token && data.expire) {
211
- localStorage.setItem('ACCESS_TOKEN', data.token)
212
- localStorage.setItem('ACCESS_TOKEN_EXPIRES', data.expire)
213
- setAuthorization({ token: data.token, expire: data.expire })
214
- } else {
215
- localStorage.removeItem('ACCESS_TOKEN')
216
- localStorage.removeItem('ACCESS_TOKEN_EXPIRES')
217
- }
210
+ localStorage.setItem(ACCESS_TOKEN, data.token)
211
+ setAuthorization({ token: data.token, expire: data.expire })
218
212
  }
219
213
  }
220
214
  }
@@ -1 +1,2 @@
1
- export const ACCESS_TOKEN = 'Access-Token'
1
+ export const ACCESS_TOKEN = 'Access-Token'
2
+ export const V4_ACCESS_TOKEN = 'Authorization'
@@ -1,16 +1,13 @@
1
1
  import axios from 'axios'
2
2
  import Cookie from 'js-cookie'
3
3
  import Vue from 'vue'
4
- import { ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
4
+ import {ACCESS_TOKEN, V4_ACCESS_TOKEN} from '@vue2-client/store/mutation-types'
5
5
  import notification from 'ant-design-vue/es/notification'
6
6
 
7
7
  let compatible
8
8
 
9
9
  // 跨域认证信息 header 名
10
10
  const xsrfHeaderName = 'Authorization'
11
- // V4系统请求头名
12
- const ACCESS_TOKEN_KEY = 'ACCESS_TOKEN'
13
- const ACCESS_TOKEN_EXPIRES_KEY = 'ACCESS_TOKEN_EXPIRES'
14
11
 
15
12
  axios.defaults.timeout = 5000
16
13
  axios.defaults.withCredentials = true
@@ -50,45 +47,6 @@ async function request (url, method, params, config) {
50
47
  }
51
48
  }
52
49
 
53
- /**
54
- * 设置V4认证信息
55
- * @param auth {Object}
56
- * @param authType {AUTH_TYPE} 认证类型,默认:{AUTH_TYPE.BEARER}
57
- */
58
- function setAuthorizationV4 (auth, authType = AUTH_TYPE.BEARER) {
59
- switch (authType) {
60
- case AUTH_TYPE.BEARER:
61
- if (auth.token) {
62
- Cookie.set(ACCESS_TOKEN_KEY, 'Bearer ' + auth.token)
63
- Cookie.set(ACCESS_TOKEN_EXPIRES_KEY, 'Bearer ' + auth.expire)
64
- }
65
- break
66
- case AUTH_TYPE.BASIC:
67
- case AUTH_TYPE.AUTH1:
68
- case AUTH_TYPE.AUTH2:
69
- default:
70
- break
71
- }
72
- }
73
-
74
- /**
75
- * 移出V4认证信息
76
- * @param authType {AUTH_TYPE} 认证类型
77
- */
78
- function removeAuthorizationV4 (authType = AUTH_TYPE.BEARER) {
79
- switch (authType) {
80
- case AUTH_TYPE.BEARER:
81
- Cookie.remove(ACCESS_TOKEN_KEY)
82
- Cookie.remove(ACCESS_TOKEN_EXPIRES_KEY)
83
- break
84
- case AUTH_TYPE.BASIC:
85
- case AUTH_TYPE.AUTH1:
86
- case AUTH_TYPE.AUTH2:
87
- default:
88
- break
89
- }
90
- }
91
-
92
50
  /**
93
51
  * 设置认证信息
94
52
  * @param auth {Object}
@@ -155,7 +113,7 @@ function checkAuthorization (authType = AUTH_TYPE.BEARER) {
155
113
  function loadInterceptors () {
156
114
  // 加载请求拦截器
157
115
  axios.interceptors.request.use(config => {
158
- const token = localStorage.getItem(ACCESS_TOKEN_KEY)
116
+ const token = localStorage.getItem(ACCESS_TOKEN)
159
117
  // 如果 token 存在
160
118
  // 让每个请求携带自定义 token 请根据实际情况自行修改
161
119
  if (token) {
@@ -166,10 +124,9 @@ function loadInterceptors () {
166
124
  // 判断是否为V4环境
167
125
  if (compatible === 'V4') {
168
126
  // V4 环境则添加 V4请求头
169
- config.headers[ACCESS_TOKEN_KEY] = localStorage.getItem(ACCESS_TOKEN_KEY)
170
- config.headers[ACCESS_TOKEN_EXPIRES_KEY] = localStorage.getItem(ACCESS_TOKEN_EXPIRES_KEY)
127
+ config.headers[V4_ACCESS_TOKEN] = token
171
128
  } else {
172
- config.headers['Access-Token'] = token
129
+ config.headers[ACCESS_TOKEN] = token
173
130
  }
174
131
  }
175
132
  if (!config.headers['Content-Type']) {