From 563ac993480deeb93900bee600e4ba3689c2c519 Mon Sep 17 00:00:00 2001 From: pllx Date: Wed, 1 Jul 2026 11:16:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BF=98=E8=AE=B0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=A2=9E=E8=AE=BE=E5=B1=80=E9=83=A8=E7=84=A6=E7=82=B9=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E5=8F=8A=E5=8F=91=E4=BF=A1=E6=88=90=E5=8A=9F30?= =?UTF-8?q?=E7=A7=92=E9=98=B2=E5=88=B7=E7=BD=AE=E7=81=B0=E5=80=92=E8=AE=A1?= =?UTF-8?q?=E6=97=B6=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/password-forgot.js | 54 ++++++++++++++++++++--- resources/views/password-forgot.blade.php | 4 +- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/resources/js/password-forgot.js b/resources/js/password-forgot.js index 25536ba..0b46296 100644 --- a/resources/js/password-forgot.js +++ b/resources/js/password-forgot.js @@ -12,6 +12,19 @@ function getCsrfToken() { return document.querySelector('meta[name="csrf-token"]')?.getAttribute("content") ?? ""; } +/** + * 获取当前应当使用的局部消息框元素。 + * + * @returns {HTMLDivElement|null} + */ +function getActiveAlertBox() { + const stepDetect = document.getElementById("step-detect"); + if (stepDetect && stepDetect.style.display !== "none") { + return document.getElementById("alert-detect"); + } + return document.getElementById("alert-email"); +} + /** * 展示找回密码页面提示。 * @@ -20,7 +33,7 @@ function getCsrfToken() { * @returns {void} */ function showAlert(message, type) { - const alertBox = document.getElementById("alert-box"); + const alertBox = getActiveAlertBox(); if (!alertBox) { return; } @@ -28,6 +41,9 @@ function showAlert(message, type) { alertBox.textContent = message; alertBox.className = type === "success" ? "alert alert-success" : "alert alert-error"; alertBox.style.display = "block"; + + // 平滑滚动提示框到可视区域 + alertBox.scrollIntoView({ behavior: "smooth", block: "nearest" }); } /** @@ -36,9 +52,13 @@ function showAlert(message, type) { * @returns {void} */ function hideAlert() { - const alertBox = document.getElementById("alert-box"); - if (alertBox) { - alertBox.style.display = "none"; + const alertDetect = document.getElementById("alert-detect"); + const alertEmail = document.getElementById("alert-email"); + if (alertDetect) { + alertDetect.style.display = "none"; + } + if (alertEmail) { + alertEmail.style.display = "none"; } } @@ -206,6 +226,8 @@ async function submitPasswordRecovery(event) { } hideAlert(); + let isSentSuccess = false; + try { const emailInput = document.getElementById("email"); const emailVal = emailInput instanceof HTMLInputElement ? emailInput.value.trim() : ""; @@ -231,6 +253,7 @@ async function submitPasswordRecovery(event) { if (body.status === "success") { showAlert(body.message, "success"); + isSentSuccess = true; return; } @@ -240,8 +263,27 @@ async function submitPasswordRecovery(event) { showAlert("网络发送异常,请稍后再试。", "error"); } finally { if (submitButton instanceof HTMLButtonElement) { - submitButton.disabled = false; - submitButton.innerText = "发送重置邮件"; + if (isSentSuccess) { + // 成功时启动 30 秒置灰倒计时锁定 + let seconds = 30; + submitButton.disabled = true; + submitButton.innerText = `${seconds}秒内不能重复发送`; + + const timer = setInterval(() => { + seconds--; + if (seconds <= 0) { + clearInterval(timer); + submitButton.disabled = false; + submitButton.innerText = "二次验证并发送重置邮件"; + } else { + submitButton.innerText = `${seconds}秒内不能重复发送`; + } + }, 1000); + } else { + // 校验失败,立刻解除禁用供重新编辑 + submitButton.disabled = false; + submitButton.innerText = "二次验证并发送重置邮件"; + } } } } diff --git a/resources/views/password-forgot.blade.php b/resources/views/password-forgot.blade.php index 3c59224..8d26749 100644 --- a/resources/views/password-forgot.blade.php +++ b/resources/views/password-forgot.blade.php @@ -295,12 +295,11 @@
PASSWORD RECOVERY

忘记密码

-
-

请输入您的聊天室用户昵称,小助手将智能查询并为您提供最安全的重置方案。

+
+