From 8ef911603e4c257316e7b018e330388cefe0e3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8?= Date: Fri, 22 May 2026 14:29:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=80=92=E8=AE=A1=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/sendCaptcha/index.ts | 18 +++++++++++++----- src/views/capital/fundFlow/index.vue | 2 +- src/views/capital/rechangeCheck/index.vue | 1 + src/views/capital/transfer/index.vue | 6 +++--- src/views/profile/personalCenter/index.vue | 10 +++++----- src/views/user/ChangePassword.vue | 6 +++--- src/views/user/ForgotPassword.vue | 6 +++--- src/views/user/Register.vue | 6 +++--- src/views/user/bindEmail.vue | 4 ++-- src/views/user/bindPhone.vue | 4 ++-- 10 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/utils/sendCaptcha/index.ts b/src/utils/sendCaptcha/index.ts index 9b62bdc..ca60c1a 100644 --- a/src/utils/sendCaptcha/index.ts +++ b/src/utils/sendCaptcha/index.ts @@ -23,18 +23,26 @@ export interface CaptchaCountdownState { * 初始化验证码倒计时状态(支持刷新恢复) * @param key 唯一标识(必填,如:register_phone/register_email/forgotPassword_phone) * @param totalSeconds 总倒计时时长(默认60秒) + * @param pagePrefix 页面级唯一前缀(可选,用于隔离不同页面的倒计时状态) * @returns 倒计时状态对象 */ -export const initCaptchaState = (key: string, totalSeconds: number = 60): CaptchaCountdownState => { +export const initCaptchaState = ( + key: string, + totalSeconds: number = 60, + pagePrefix?: string +): CaptchaCountdownState => { + // 生成完整的 key,包含页面级前缀以避免跨页面状态污染 + const fullKey = pagePrefix ? `${pagePrefix}_${key}` : key; + const state: CaptchaCountdownState = { countdown: ref(0), isCounting: ref(false), timer: null, - key + key: fullKey }; // 页面刷新后,从sessionStorage恢复状态 - const stored = getStorage(`captcha_${key}`, 'session'); + const stored = getStorage(`captcha_${fullKey}`, 'session'); if (stored) { try { const now = Date.now(); @@ -58,11 +66,11 @@ export const initCaptchaState = (key: string, totalSeconds: number = 60): Captch }, 1000); } else { // 剩余时间<=0,清空本地存储 - removeStorage(`captcha_${key}`, 'session'); + removeStorage(`captcha_${fullKey}`, 'session'); } } catch (e) { console.error('恢复验证码倒计时状态失败:', e); - removeStorage(`captcha_${key}`, 'session'); + removeStorage(`captcha_${fullKey}`, 'session'); } } diff --git a/src/views/capital/fundFlow/index.vue b/src/views/capital/fundFlow/index.vue index bba9063..bc2a88f 100644 --- a/src/views/capital/fundFlow/index.vue +++ b/src/views/capital/fundFlow/index.vue @@ -1,7 +1,7 @@