:sparkles:新增自动续期token

This commit is contained in:
不做码农
2023-08-29 17:00:22 +08:00
parent 460594f116
commit 05715b40c4
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -139,6 +139,10 @@ const useUserStore = defineStore('user', {
setClientId(clientId) { setClientId(clientId) {
this.clientId = clientId this.clientId = clientId
cache.local.set('clientId', clientId) cache.local.set('clientId', clientId)
},
refreshToken(token) {
setToken(token)
this.token = token
} }
} }
}) })
+4
View File
@@ -55,6 +55,10 @@ service.interceptors.response.use(
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') { if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
return res return res
} }
var token = res.headers['x-refresh-token']
if (token) {
useUserStore().refreshToken(token)
}
if (code == 401) { if (code == 401) {
ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', { ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
confirmButtonText: '重新登陆', confirmButtonText: '重新登陆',