Skip to content

Commit e3981ef

Browse files
authored
chore(http.ts): 优化401状态退出不用等满3秒显得很卡 (#514)
1 parent dfa5c65 commit e3981ef

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

web/src/utils/http.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ http.interceptors.request.use(
5252
},
5353
)
5454

55+
let isLogout = false
56+
5557
http.interceptors.response.use(
5658
async (response: AxiosResponse): Promise<any> => {
5759
isLoading.value = false
@@ -72,14 +74,14 @@ http.interceptors.response.use(
7274
else {
7375
switch (response?.data?.code) {
7476
case ResultCode.UNAUTHORIZED: {
75-
const logout = useDebounceFn(
76-
async () => {
77+
const logout = async () => {
78+
if (isLogout === false) {
79+
isLogout = true
80+
setTimeout(() => isLogout = false, 5000)
7781
Message.error('登录状态已过期,需要重新登录', { zIndex: 9999 })
7882
await useUserStore().logout()
79-
},
80-
3000,
81-
{ maxWait: 5000 },
82-
)
83+
}
84+
}
8385
// 检查token是否需要刷新
8486
if (userStore.isLogin && !isRefreshToken.value) {
8587
isRefreshToken.value = true

0 commit comments

Comments
 (0)