fix: 平台登录提示8秒后消失,失败后固定显示
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<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 { useRoute, useRouter } from "vue-router";
|
||||||
import { NButton, NInput, NModal, NSpin } from "naive-ui";
|
import { NButton, NInput, NModal, NSpin } from "naive-ui";
|
||||||
import { api, saveSession } from "../../shared/http";
|
import { api, saveSession } from "../../shared/http";
|
||||||
@@ -32,7 +32,47 @@ const smsRequired = ref(false);
|
|||||||
const smsSending = ref(false);
|
const smsSending = ref(false);
|
||||||
const countdown = ref(0);
|
const countdown = ref(0);
|
||||||
const busy = ref(false);
|
const busy = ref(false);
|
||||||
|
const noticeVisible = ref(false);
|
||||||
|
const noticePinned = ref(false);
|
||||||
let countdownTimer = 0;
|
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 () => {
|
onMounted(async () => {
|
||||||
if (props.purpose !== "pool" && route.query.notice === "already") {
|
if (props.purpose !== "pool" && route.query.notice === "already") {
|
||||||
@@ -40,15 +80,24 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
if (props.purpose === "pool") {
|
if (props.purpose === "pool") {
|
||||||
mode.value = "nqi";
|
mode.value = "nqi";
|
||||||
|
showNotice();
|
||||||
await startNqi();
|
await startNqi();
|
||||||
|
beginNoticeCountdown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = await api<{ mode: string }>("/api/auth/mode");
|
const result = await api<{ mode: string }>("/api/auth/mode");
|
||||||
mode.value = result.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() {
|
function submitLogin() {
|
||||||
if (busy.value) return;
|
if (busy.value) return;
|
||||||
@@ -85,6 +134,7 @@ async function beginLogin() {
|
|||||||
captchaUrl.value = result.captcha || "";
|
captchaUrl.value = result.captcha || "";
|
||||||
captchaBroken.value = !captchaUrl.value;
|
captchaBroken.value = !captchaUrl.value;
|
||||||
toast.error(result.message || "请重新输入验证码");
|
toast.error(result.message || "请重新输入验证码");
|
||||||
|
pinNotice();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result.status === "sms_required") {
|
if (result.status === "sms_required") {
|
||||||
@@ -98,6 +148,7 @@ async function beginLogin() {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fail(error);
|
fail(error);
|
||||||
|
pinNotice();
|
||||||
} finally {
|
} finally {
|
||||||
busy.value = false;
|
busy.value = false;
|
||||||
}
|
}
|
||||||
@@ -191,6 +242,7 @@ async function sendSms() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
stopCountdown();
|
stopCountdown();
|
||||||
fail(error);
|
fail(error);
|
||||||
|
pinNotice();
|
||||||
} finally {
|
} finally {
|
||||||
smsSending.value = false;
|
smsSending.value = false;
|
||||||
}
|
}
|
||||||
@@ -217,6 +269,7 @@ async function finishNqi() {
|
|||||||
captchaUrl.value = result.captcha || "";
|
captchaUrl.value = result.captcha || "";
|
||||||
captchaBroken.value = !captchaUrl.value;
|
captchaBroken.value = !captchaUrl.value;
|
||||||
toast.error(result.message || "请重新输入验证码");
|
toast.error(result.message || "请重新输入验证码");
|
||||||
|
pinNotice();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result.status === "sms_required") {
|
if (result.status === "sms_required") {
|
||||||
@@ -234,6 +287,7 @@ async function finishNqi() {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fail(error);
|
fail(error);
|
||||||
|
pinNotice();
|
||||||
} finally {
|
} finally {
|
||||||
busy.value = false;
|
busy.value = false;
|
||||||
}
|
}
|
||||||
@@ -245,7 +299,7 @@ async function finishNqi() {
|
|||||||
<ThemeButton v-if="purpose !== 'pool'" />
|
<ThemeButton v-if="purpose !== 'pool'" />
|
||||||
<section :class="purpose === 'pool' ? 'lv-embed' : 'lv-side'">
|
<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>
|
<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">
|
<form class="lv-fields" @submit.prevent="submitLogin">
|
||||||
<label for="login-account">账号</label>
|
<label for="login-account">账号</label>
|
||||||
<n-input :input-props="{ id: 'login-account', autocomplete: 'username' }" v-model:value="username" @keyup.enter="submitLogin" />
|
<n-input :input-props="{ id: 'login-account', autocomplete: 'username' }" v-model:value="username" @keyup.enter="submitLogin" />
|
||||||
|
|||||||
Reference in New Issue
Block a user