vue2-client 1.2.113 → 1.2.116
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 +1 -1
- package/package.json +1 -1
- package/src/pages/login/Login.vue +10 -12
- package/src/store/mutation-types.js +2 -1
- package/src/utils/request.js +5 -50
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -199,21 +199,19 @@ export default {
|
|
|
199
199
|
this.$message.success(timeFix().CN + `,${result.name} 欢迎回来`, 3)
|
|
200
200
|
},
|
|
201
201
|
setAccessToken (data) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
202
|
+
if (data) {
|
|
203
|
+
localStorage.setItem(ACCESS_TOKEN, data)
|
|
204
|
+
let timestamp = new Date().getTime()// 当前的时间戳
|
|
205
|
+
timestamp = timestamp + 12 * 60 * 60 * 1000
|
|
206
|
+
// 格式化时间获取年月日, 登陆过期时间
|
|
207
|
+
const dateAfter = new Date(timestamp)
|
|
208
|
+
setAuthorization({ token: data, expireAt: dateAfter })
|
|
209
|
+
}
|
|
208
210
|
},
|
|
209
211
|
setV4AccessToken (data) {
|
|
210
|
-
if (data.token
|
|
211
|
-
localStorage.setItem(
|
|
212
|
-
localStorage.setItem('ACCESS_TOKEN_EXPIRES', data.expire)
|
|
212
|
+
if (data.token) {
|
|
213
|
+
localStorage.setItem(ACCESS_TOKEN, data.token)
|
|
213
214
|
setAuthorization({ token: data.token, expire: data.expire })
|
|
214
|
-
} else {
|
|
215
|
-
localStorage.removeItem('ACCESS_TOKEN')
|
|
216
|
-
localStorage.removeItem('ACCESS_TOKEN_EXPIRES')
|
|
217
215
|
}
|
|
218
216
|
}
|
|
219
217
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const ACCESS_TOKEN = 'Access-Token'
|
|
1
|
+
export const ACCESS_TOKEN = 'Access-Token'
|
|
2
|
+
export const V4_ACCESS_TOKEN = 'Authorization'
|
package/src/utils/request.js
CHANGED
|
@@ -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(
|
|
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[
|
|
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[
|
|
129
|
+
config.headers[ACCESS_TOKEN] = token
|
|
173
130
|
}
|
|
174
131
|
}
|
|
175
132
|
if (!config.headers['Content-Type']) {
|
|
@@ -264,7 +221,5 @@ export {
|
|
|
264
221
|
removeAuthorization,
|
|
265
222
|
checkAuthorization,
|
|
266
223
|
loadInterceptors,
|
|
267
|
-
parseUrlParams
|
|
268
|
-
setAuthorizationV4,
|
|
269
|
-
removeAuthorizationV4
|
|
224
|
+
parseUrlParams
|
|
270
225
|
}
|