修复登录报错

This commit is contained in:
2026-07-27 16:30:34 +08:00
parent abfa8e0cae
commit 278532cdad
3 changed files with 21 additions and 8 deletions

View File

@@ -12,11 +12,12 @@ export function index() {
})
}
export function login(method: 'get' | 'post', params: object = {}) {
export function login(method: 'get' | 'post', params: object = {}, axiosConfig: Record<string, unknown> = {}) {
return createAxios({
url: url + 'login',
data: params,
method: method,
...axiosConfig,
})
}

View File

@@ -288,11 +288,7 @@ function redirectToLoginIfNeedLoginFromHttp303(error: any): boolean {
const adminInfo = useAdminInfo()
const userInfo = useUserInfo()
if (router.currentRoute.value.name === loginRouteName) {
if (isAdminAppFlag) {
adminInfo.removeToken()
} else {
userInfo.removeToken()
}
// 已在登录页:仅吞掉 303勿清 token避免 login GET 与 login POST 并发时清掉刚登录成功的 token
return true
}
window.authRedirecting = true

View File

@@ -174,6 +174,14 @@ import { fullUrl } from '/@/utils/common'
import { adminBaseRoutePath } from '/@/router/static/adminBase'
import type { FormItemRule } from 'element-plus'
let timer: number
let loginPrefetchController: AbortController | null = null
const abortLoginPrefetch = () => {
if (loginPrefetchController) {
loginPrefetchController.abort()
loginPrefetchController = null
}
}
const config = useConfig()
const adminInfo = useAdminInfo()
@@ -253,9 +261,10 @@ const navigateAfterLogin = (userInfo: anyObj) => {
if (!userInfo?.token) {
return
}
abortLoginPrefetch()
adminInfo.dataFill(userInfo, false)
nextTick(() => {
router.push({ path: adminBaseRoutePath })
router.replace({ path: adminBaseRoutePath })
})
}
@@ -264,17 +273,23 @@ onMounted(() => {
pageBubble.init()
}, 1000)
login('get')
abortLoginPrefetch()
loginPrefetchController = new AbortController()
login('get', {}, { signal: loginPrefetchController.signal })
.then((res) => {
state.showCaptcha = res.data.captcha
nextTick(() => focusInput())
})
.catch((err) => {
if (err?.code === 'ERR_CANCELED' || err?.message === 'canceled') {
return
}
console.log(err)
})
})
onBeforeUnmount(() => {
abortLoginPrefetch()
clearTimeout(timer)
pageBubble.removeListeners()
})
@@ -292,6 +307,7 @@ const onSubmitPre = () => {
}
const onSubmit = (captchaInfo = '') => {
abortLoginPrefetch()
state.submitLoading = true
form.captchaInfo = captchaInfo
login('post', form)