Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(http.ts): 优化401状态退出不用等满3秒显得很卡 #514

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
)
}
}
zds-s marked this conversation as resolved.
Show resolved Hide resolved
// 检查token是否需要刷新
if (userStore.isLogin && !isRefreshToken.value) {
isRefreshToken.value = true
Expand Down
Loading