fix: 平台登录提示8秒后消失,失败后固定显示

This commit is contained in:
2026-11-02 11:41:21 +08:00
parent ba0727d94e
commit 116348045c
+58 -4
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from "vue";
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { NButton, NInput, NModal, NSpin } from "naive-ui";
import { api, saveSession } from "../../shared/http";
@@ -32,7 +32,47 @@ const smsRequired = ref(false);
const smsSending = ref(false);
const countdown = ref(0);
const busy = ref(false);
const noticeVisible = ref(false);
const noticePinned = ref(false);
let countdownTimer = 0;
let noticeTimer = 0;
function clearNoticeTimer() {
window.clearTimeout(noticeTimer);
noticeTimer = 0;
}
function showNotice() {
if (mode.value !== "nqi") return;
noticePinned.value = false;
noticeVisible.value = true;
clearNoticeTimer();
}
function beginNoticeCountdown() {
if (mode.value !== "nqi" || noticePinned.value) return;
clearNoticeTimer();
noticeTimer = window.setTimeout(() => {
noticeTimer = 0;
if (!noticePinned.value) noticeVisible.value = false;
}, 8000);
}
function pinNotice() {
if (mode.value !== "nqi") return;
clearNoticeTimer();
noticePinned.value = true;
noticeVisible.value = true;
}
watch(mode, (value) => {
if (value === "nqi") showNotice();
else {
noticePinned.value = false;
noticeVisible.value = false;
clearNoticeTimer();
}
});
onMounted(async () => {
if (props.purpose !== "pool" && route.query.notice === "already") {
@@ -40,15 +80,24 @@ onMounted(async () => {
}
if (props.purpose === "pool") {
mode.value = "nqi";
showNotice();
await startNqi();
beginNoticeCountdown();
return;
}
const result = await api<{ mode: string }>("/api/auth/mode");
mode.value = result.mode;
if (mode.value === "nqi") await startNqi();
if (mode.value === "nqi") {
showNotice();
await startNqi();
beginNoticeCountdown();
}
});
onUnmounted(() => window.clearInterval(countdownTimer));
onUnmounted(() => {
window.clearInterval(countdownTimer);
clearNoticeTimer();
});
function submitLogin() {
if (busy.value) return;
@@ -85,6 +134,7 @@ async function beginLogin() {
captchaUrl.value = result.captcha || "";
captchaBroken.value = !captchaUrl.value;
toast.error(result.message || "请重新输入验证码");
pinNotice();
return;
}
if (result.status === "sms_required") {
@@ -98,6 +148,7 @@ async function beginLogin() {
}
} catch (error) {
fail(error);
pinNotice();
} finally {
busy.value = false;
}
@@ -191,6 +242,7 @@ async function sendSms() {
} catch (error) {
stopCountdown();
fail(error);
pinNotice();
} finally {
smsSending.value = false;
}
@@ -217,6 +269,7 @@ async function finishNqi() {
captchaUrl.value = result.captcha || "";
captchaBroken.value = !captchaUrl.value;
toast.error(result.message || "请重新输入验证码");
pinNotice();
return;
}
if (result.status === "sms_required") {
@@ -234,6 +287,7 @@ async function finishNqi() {
}
} catch (error) {
fail(error);
pinNotice();
} finally {
busy.value = false;
}
@@ -245,7 +299,7 @@ async function finishNqi() {
<ThemeButton v-if="purpose !== 'pool'" />
<section :class="purpose === 'pool' ? 'lv-embed' : 'lv-side'">
<div v-if="purpose !== 'pool'" class="lv-brand"><div class="lv-mark" aria-hidden="true">D</div><h1>DecomEval</h1></div>
<p v-if="mode === 'nqi'" class="lv-notice">请使用大数据平台账号登录</p>
<p v-if="noticeVisible" class="lv-notice">请使用大数据平台账号登录</p>
<form class="lv-fields" @submit.prevent="submitLogin">
<label for="login-account">账号</label>
<n-input :input-props="{ id: 'login-account', autocomplete: 'username' }" v-model:value="username" @keyup.enter="submitLogin" />