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 @@