From 37c50ed517d6aea831236ac5191875e739f500c0 Mon Sep 17 00:00:00 2001 From: qing <1776177662@qq.com> Date: Mon, 3 Aug 2026 23:11:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(static):=20=E8=8E=B7=E5=8F=96=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E9=AA=8C=E8=AF=81=E7=A0=81=E5=90=8E=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E5=B7=B2=E8=BE=93=E5=85=A5=E7=9A=84=E5=9B=BE=E5=BD=A2=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refreshCaptcha 增加 preserveInput 参数,获取验证码后的自动刷新不再清空图形验证码输入框,避免误清空用户输入 --- static/public/forgot.html | 9 +++++---- static/public/js/register.js | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/static/public/forgot.html b/static/public/forgot.html index 8d19c9d..c87f688 100644 --- a/static/public/forgot.html +++ b/static/public/forgot.html @@ -63,11 +63,11 @@ let cooldownTimer = null; // 重发倒计时(与服务端 smtp 同邮箱 60s let captchaToken = ''; let captchaLoading = false; // 防重复点击:加载中忽略再次触发 -async function refreshCaptcha() { +async function refreshCaptcha(preserveInput) { if (captchaLoading) return; captchaLoading = true; captchaToken = ''; - captchaInput.value = ''; // 开始刷新时清空输入,避免用户误用旧验证码 + if (!preserveInput) captchaInput.value = ''; // 默认清空输入;preserveInput=true 时保留(获取验证码后) captchaImg.style.opacity = '0.5'; // 视觉提示:正在刷新 try { const res = await fetch('/captcha/image', { cache: 'no-store' }); @@ -267,8 +267,9 @@ getCodeButton.addEventListener('click', async function () { codeTip.classList.add('tip-red'); if (httpStatus === 429) startResendCooldown(60); // 命中冷却/限流,倒计时对齐 } finally { - // CAPTCHA Token 一次性消费,无论成败都刷新 - refreshCaptcha(); + // CAPTCHA Token 一次性消费,无论成败都刷新图形验证码; + // 刷新时保留已输入的图形验证码答案,避免误清空用户输入 + refreshCaptcha(true); if (!cooldownTimer) getCodeButton.disabled = false; } }); diff --git a/static/public/js/register.js b/static/public/js/register.js index 45898ee..e44dccb 100644 --- a/static/public/js/register.js +++ b/static/public/js/register.js @@ -19,11 +19,11 @@ let cooldownTimer = null; // 重发倒计时(与服务端同邮箱 60s 发送 let captchaToken = ''; let captchaLoading = false; // 防重复点击:加载中忽略再次触发 -async function refreshCaptcha() { +async function refreshCaptcha(preserveInput) { if (captchaLoading) return; captchaLoading = true; captchaToken = ''; - captchaInput.value = ''; // 开始刷新时清空输入,避免用户误用旧验证码 + if (!preserveInput) captchaInput.value = ''; // 默认清空输入;preserveInput=true 时保留(获取验证码后) captchaImg.style.opacity = '0.5'; // 视觉提示:正在刷新 try { const res = await fetch('/captcha/image', { cache: 'no-store' }); @@ -222,8 +222,9 @@ getCodeButton.addEventListener('click', async function () { codeTip.classList.add('tip-red'); if (httpStatus === 429) startResendCooldown(60); // 命中冷却/限流,倒计时对齐 } finally { - // CAPTCHA Token 一次性消费,无论成败都刷新 - refreshCaptcha(); + // CAPTCHA Token 一次性消费,无论成败都刷新图形验证码; + // 刷新时保留已输入的图形验证码答案,避免误清空用户输入 + refreshCaptcha(true); if (!cooldownTimer) getCodeButton.disabled = false; } });