Skip to content

Commit

Permalink
chore(http.ts): 优化401状态退出不用等满3秒显得很卡 (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljk123 authored Jan 8, 2025
1 parent dfa5c65 commit e3981ef
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions web/src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ http.interceptors.request.use(
},
)

let isLogout = false

http.interceptors.response.use(
async (response: AxiosResponse): Promise<any> => {
isLoading.value = false
Expand All @@ -72,14 +74,14 @@ http.interceptors.response.use(
else {
switch (response?.data?.code) {
case ResultCode.UNAUTHORIZED: {
const logout = useDebounceFn(
async () => {
const logout = async () => {
if (isLogout === false) {
isLogout = true
setTimeout(() => isLogout = false, 5000)
Message.error('登录状态已过期,需要重新登录', { zIndex: 9999 })
await useUserStore().logout()
},
3000,
{ maxWait: 5000 },
)
}
}
// 检查token是否需要刷新
if (userStore.isLogin && !isRefreshToken.value) {
isRefreshToken.value = true
Expand Down

0 comments on commit e3981ef

Please sign in to comment.