fix: 连接失败后可以重试并重新获取验证码

This commit is contained in:
2026-10-25 07:37:09 +08:00
parent d129c30bde
commit 79e2c48e02
2 changed files with 27 additions and 2 deletions
+20 -2
View File
@@ -10,6 +10,8 @@ defineProps<{ notice?: string }>();
const emit = defineEmits<{ success: [user: UserInfo] }>();
const ready = ref(false);
const connecting = ref(false);
const connectFailed = ref(false);
const offline = ref("");
const sessionId = ref("");
const captchaUrl = ref("");
@@ -47,6 +49,8 @@ async function refreshSaved() {
}
async function connect() {
connecting.value = true;
connectFailed.value = false;
offline.value = "";
ready.value = false;
for (let attempt = 0; attempt < 40; attempt += 1) {
@@ -55,17 +59,24 @@ async function connect() {
sessionId.value = result.sessionId;
captchaUrl.value = result.captcha;
ready.value = true;
connecting.value = false;
offline.value = "";
return;
} catch (error) {
const failedLocally = !(error instanceof ApiError) || error.status === 0;
offline.value = error instanceof ApiError ? error.message : "连接失败";
if (!failedLocally) {
ready.value = true;
connecting.value = false;
return;
}
await new Promise((resolve) => window.setTimeout(resolve, 500));
}
}
connecting.value = false;
connectFailed.value = true;
ready.value = false;
offline.value = "连接失败";
}
async function reloadCaptcha(keepError = false) {
@@ -205,8 +216,14 @@ onUnmounted(stopCountdown);
</div>
<n-alert v-if="notice" type="warning" style="margin-bottom: 12px">{{ notice }}</n-alert>
<n-spin :show="!ready && !offline">
<n-alert v-if="!ready" type="warning" style="margin-bottom: 12px">连接失败,正在重试。</n-alert>
<n-spin :show="connecting && !offline">
<n-alert v-if="connecting && offline" type="warning" style="margin-bottom: 12px">连接失败,正在重试。</n-alert>
<template v-else-if="connectFailed">
<n-alert type="warning" style="margin-bottom: 12px">连接失败</n-alert>
<div class="retry-row">
<n-button type="primary" secondary @click="connect">重试</n-button>
</div>
</template>
<n-alert v-else-if="offline" type="warning" style="margin-bottom: 12px">{{ offline }}</n-alert>
<n-alert v-if="errorText && !smsRequired" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
<form @submit.prevent="submit()">
@@ -242,6 +259,7 @@ onUnmounted(stopCountdown);
<div class="captcha-line">
<n-input id="captcha" v-model:value="captcha" placeholder="验证码" />
<img v-if="captchaUrl" :src="captchaUrl" alt="验证码" title="点击刷新" @click="reloadCaptcha()" />
<n-button v-else-if="ready" @click="reloadCaptcha()">重新获取验证码</n-button>
</div>
</div>
<div class="gate-actions">
+7
View File
@@ -168,6 +168,13 @@ select {
margin-right: auto;
}
.retry-row {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-bottom: 12px;
}
.shell {
height: 100%;
display: grid;