feat: 请求时刷新session age

This commit is contained in:
ibuler
2020-09-08 20:11:59 +08:00
committed by Orange
parent 214bb28c4c
commit 4385d84f01
2 changed files with 19 additions and 0 deletions

View File

@@ -65,3 +65,7 @@ export function logout() {
method: 'post'
})
}
export function refreshSessionIdAge() {
return getProfile()
}

View File

@@ -1,6 +1,7 @@
import axios from 'axios'
import i18n from '@/i18n/i18n'
import { getTokenFromCookie } from '@/utils/auth'
import { refreshSessionIdAge } from '@/api/users'
import { Message, MessageBox } from 'element-ui'
import store from '@/store'
@@ -88,6 +89,19 @@ export function flashErrorMsg({ response, error }) {
}
}
let timer = null
function refreshSessionAgeDelay(response) {
if (response.request.responseURL.indexOf('/users/profile/') !== -1) {
return
}
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(function() {
refreshSessionIdAge()
}, 60 * 10)
}
// response interceptor
service.interceptors.response.use(
/**
@@ -102,6 +116,7 @@ service.interceptors.response.use(
*/
response => {
// NProgress.done()
refreshSessionAgeDelay(response)
const res = response.data
if (response.config.raw === 1) {