修复登录报错
This commit is contained in:
@@ -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({
|
return createAxios({
|
||||||
url: url + 'login',
|
url: url + 'login',
|
||||||
data: params,
|
data: params,
|
||||||
method: method,
|
method: method,
|
||||||
|
...axiosConfig,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -288,11 +288,7 @@ function redirectToLoginIfNeedLoginFromHttp303(error: any): boolean {
|
|||||||
const adminInfo = useAdminInfo()
|
const adminInfo = useAdminInfo()
|
||||||
const userInfo = useUserInfo()
|
const userInfo = useUserInfo()
|
||||||
if (router.currentRoute.value.name === loginRouteName) {
|
if (router.currentRoute.value.name === loginRouteName) {
|
||||||
if (isAdminAppFlag) {
|
// 已在登录页:仅吞掉 303,勿清 token(避免 login GET 与 login POST 并发时清掉刚登录成功的 token)
|
||||||
adminInfo.removeToken()
|
|
||||||
} else {
|
|
||||||
userInfo.removeToken()
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
window.authRedirecting = true
|
window.authRedirecting = true
|
||||||
|
|||||||
@@ -174,6 +174,14 @@ import { fullUrl } from '/@/utils/common'
|
|||||||
import { adminBaseRoutePath } from '/@/router/static/adminBase'
|
import { adminBaseRoutePath } from '/@/router/static/adminBase'
|
||||||
import type { FormItemRule } from 'element-plus'
|
import type { FormItemRule } from 'element-plus'
|
||||||
let timer: number
|
let timer: number
|
||||||
|
let loginPrefetchController: AbortController | null = null
|
||||||
|
|
||||||
|
const abortLoginPrefetch = () => {
|
||||||
|
if (loginPrefetchController) {
|
||||||
|
loginPrefetchController.abort()
|
||||||
|
loginPrefetchController = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const config = useConfig()
|
const config = useConfig()
|
||||||
const adminInfo = useAdminInfo()
|
const adminInfo = useAdminInfo()
|
||||||
@@ -253,9 +261,10 @@ const navigateAfterLogin = (userInfo: anyObj) => {
|
|||||||
if (!userInfo?.token) {
|
if (!userInfo?.token) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
abortLoginPrefetch()
|
||||||
adminInfo.dataFill(userInfo, false)
|
adminInfo.dataFill(userInfo, false)
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
router.push({ path: adminBaseRoutePath })
|
router.replace({ path: adminBaseRoutePath })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,17 +273,23 @@ onMounted(() => {
|
|||||||
pageBubble.init()
|
pageBubble.init()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
login('get')
|
abortLoginPrefetch()
|
||||||
|
loginPrefetchController = new AbortController()
|
||||||
|
login('get', {}, { signal: loginPrefetchController.signal })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
state.showCaptcha = res.data.captcha
|
state.showCaptcha = res.data.captcha
|
||||||
nextTick(() => focusInput())
|
nextTick(() => focusInput())
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
if (err?.code === 'ERR_CANCELED' || err?.message === 'canceled') {
|
||||||
|
return
|
||||||
|
}
|
||||||
console.log(err)
|
console.log(err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
abortLoginPrefetch()
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
pageBubble.removeListeners()
|
pageBubble.removeListeners()
|
||||||
})
|
})
|
||||||
@@ -292,6 +307,7 @@ const onSubmitPre = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onSubmit = (captchaInfo = '') => {
|
const onSubmit = (captchaInfo = '') => {
|
||||||
|
abortLoginPrefetch()
|
||||||
state.submitLoading = true
|
state.submitLoading = true
|
||||||
form.captchaInfo = captchaInfo
|
form.captchaInfo = captchaInfo
|
||||||
login('post', form)
|
login('post', form)
|
||||||
|
|||||||
Reference in New Issue
Block a user