|
@@ -19,6 +19,7 @@ import qs from 'qs'
|
|
import store from '@/store'
|
|
import store from '@/store'
|
|
import {getStore, setStore} from "@/util/store.js";
|
|
import {getStore, setStore} from "@/util/store.js";
|
|
import website from "@/const/website.js";
|
|
import website from "@/const/website.js";
|
|
|
|
+import {validatenull} from "@/util/validate";
|
|
|
|
|
|
const scope = 'server'
|
|
const scope = 'server'
|
|
|
|
|
|
@@ -128,10 +129,10 @@ export const logout = () => {
|
|
* 校验令牌,若有效期小于半小时自动续期
|
|
* 校验令牌,若有效期小于半小时自动续期
|
|
* @param refreshLock
|
|
* @param refreshLock
|
|
*/
|
|
*/
|
|
-export const checkToken = (refreshLock, $store) => {
|
|
|
|
|
|
+export const checkToken = (refreshTime, refreshLock, $store) => {
|
|
const token = store.getters.access_token
|
|
const token = store.getters.access_token
|
|
// 获取当前选中的 basic 认证信息
|
|
// 获取当前选中的 basic 认证信息
|
|
- let basicAuth = getStore({name: 'basicAuth'})
|
|
|
|
|
|
+ const basicAuth = getStore({ name: 'basicAuth' })
|
|
|
|
|
|
request({
|
|
request({
|
|
url: '/admin/token/check_token',
|
|
url: '/admin/token/check_token',
|
|
@@ -140,28 +141,35 @@ export const checkToken = (refreshLock, $store) => {
|
|
Authorization: basicAuth
|
|
Authorization: basicAuth
|
|
},
|
|
},
|
|
method: 'get',
|
|
method: 'get',
|
|
- params: {token}
|
|
|
|
- }).then(response => {
|
|
|
|
- const expire = response && response.data && response.data.exp
|
|
|
|
- if (expire) {
|
|
|
|
- const expiredPeriod = expire * 1000 - new Date().getTime()
|
|
|
|
- //小于半小时自动续约
|
|
|
|
- if (expiredPeriod <= 30 * 60 * 1000) {
|
|
|
|
- if (!refreshLock) {
|
|
|
|
- refreshLock = true
|
|
|
|
- $store.dispatch('RefreshToken')
|
|
|
|
- .catch(() => {
|
|
|
|
- clearInterval(this.refreshTime)
|
|
|
|
- })
|
|
|
|
- refreshLock = false
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }).catch(error => {
|
|
|
|
- console.error(error)
|
|
|
|
|
|
+ params: { token }
|
|
})
|
|
})
|
|
|
|
+ .then((response) => {
|
|
|
|
+ if (validatenull(response)) {
|
|
|
|
+ clearInterval(refreshTime)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const expire = response && response.data && response.data.exp
|
|
|
|
+ if (expire) {
|
|
|
|
+ const expiredPeriod = expire * 1000 - new Date().getTime()
|
|
|
|
+ //小于半小时自动续约
|
|
|
|
+ if (expiredPeriod <= 10 * 60 * 1000) {
|
|
|
|
+ if (!refreshLock) {
|
|
|
|
+ refreshLock = true
|
|
|
|
+ $store.dispatch('RefreshToken').catch(() => {
|
|
|
|
+ clearInterval(refreshTime)
|
|
|
|
+ })
|
|
|
|
+ refreshLock = false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ console.error(error)
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 注册用户
|
|
* 注册用户
|
|
*/
|
|
*/
|