登录修改
This commit is contained in:
parent
4137bc10d7
commit
c55f128c22
@ -440,9 +440,12 @@ const handleLogin = async () => {
|
|||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
// 网络访问测试(最多重试3次,短退避:200/400/800ms,总上限约 1.4s)
|
// 网络访问测试(打包后端启动较慢时,做短暂重试等待)
|
||||||
|
const MAX_HEALTH_ATTEMPTS = 6
|
||||||
|
const HEALTH_BASE_DELAY_MS = 200
|
||||||
|
const HEALTH_MAX_DELAY_MS = 1500
|
||||||
let healthOk = false
|
let healthOk = false
|
||||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
for (let attempt = 1; attempt <= MAX_HEALTH_ATTEMPTS; attempt++) {
|
||||||
try {
|
try {
|
||||||
const result = await systemAPI.health()
|
const result = await systemAPI.health()
|
||||||
if (result && result.status === 'healthy') {
|
if (result && result.status === 'healthy') {
|
||||||
@ -450,22 +453,22 @@ const handleLogin = async () => {
|
|||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
// 后台返回非 healthy 状态
|
// 后台返回非 healthy 状态
|
||||||
if (attempt === 3) {
|
if (attempt === MAX_HEALTH_ATTEMPTS) {
|
||||||
showError('后台服务异常,请稍后重试!')
|
showError('后台服务异常,请稍后重试!')
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const delay = 200 * Math.pow(2, attempt - 1)
|
const delay = Math.min(HEALTH_MAX_DELAY_MS, HEALTH_BASE_DELAY_MS * Math.pow(2, attempt - 1))
|
||||||
await new Promise(resolve => setTimeout(resolve, delay))
|
await new Promise(resolve => setTimeout(resolve, delay))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 捕获异常,等待后重试
|
// 捕获异常,等待后重试
|
||||||
if (attempt === 3) {
|
if (attempt === MAX_HEALTH_ATTEMPTS) {
|
||||||
showError('网络访问失败,请检查连接后重试!')
|
showError('网络访问失败,请检查连接后重试!')
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const delay = 200 * Math.pow(2, attempt - 1)
|
const delay = Math.min(HEALTH_MAX_DELAY_MS, HEALTH_BASE_DELAY_MS * Math.pow(2, attempt - 1))
|
||||||
await new Promise(resolve => setTimeout(resolve, delay))
|
await new Promise(resolve => setTimeout(resolve, delay))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user