From 4ac6c4892e6e69bdfb3e1eb8cdec5a0570927754 Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Thu, 16 Oct 2025 15:23:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E9=99=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Auth/AuthFormContent.js | 1 + src/components/Auth/WechatRegister.js | 41 +++++++++++++++++++ .../SignIn/SignInIllustration.js | 1 + 3 files changed, 43 insertions(+) diff --git a/src/components/Auth/AuthFormContent.js b/src/components/Auth/AuthFormContent.js index d8536c9f..370415d5 100644 --- a/src/components/Auth/AuthFormContent.js +++ b/src/components/Auth/AuthFormContent.js @@ -159,6 +159,7 @@ export default function AuthFormContent() { headers: { 'Content-Type': 'application/json', }, + credentials: 'include', body: JSON.stringify({ credential, type: 'phone', diff --git a/src/components/Auth/WechatRegister.js b/src/components/Auth/WechatRegister.js index ea697bdb..f467de41 100644 --- a/src/components/Auth/WechatRegister.js +++ b/src/components/Auth/WechatRegister.js @@ -14,6 +14,7 @@ import { authService, WECHAT_STATUS, STATUS_MESSAGES } from "../../services/auth // 配置常量 const POLL_INTERVAL = 2000; // 轮询间隔:2秒 +const BACKUP_POLL_INTERVAL = 3000; // 备用轮询间隔:3秒 const QR_CODE_TIMEOUT = 300000; // 二维码超时:5分钟 export default function WechatRegister() { @@ -26,6 +27,7 @@ export default function WechatRegister() { // 使用 useRef 管理定时器,避免闭包问题和内存泄漏 const pollIntervalRef = useRef(null); + const backupPollIntervalRef = useRef(null); // 备用轮询定时器 const timeoutRef = useRef(null); const isMountedRef = useRef(true); // 追踪组件挂载状态 const containerRef = useRef(null); // 容器DOM引用 @@ -67,6 +69,10 @@ export default function WechatRegister() { clearInterval(pollIntervalRef.current); pollIntervalRef.current = null; } + if (backupPollIntervalRef.current) { + clearInterval(backupPollIntervalRef.current); + backupPollIntervalRef.current = null; + } if (timeoutRef.current) { clearTimeout(timeoutRef.current); timeoutRef.current = null; @@ -239,6 +245,40 @@ export default function WechatRegister() { }; }, [clearTimers]); + /** + * 备用轮询机制 - 防止丢失状态 + * 每3秒检查一次,仅在获取到二维码URL且状态为waiting时执行 + */ + useEffect(() => { + // 只在有auth_url、session_id且状态为waiting时启动备用轮询 + if (wechatAuthUrl && wechatSessionId && wechatStatus === WECHAT_STATUS.WAITING) { + console.log('备用轮询:启动备用轮询机制'); + + backupPollIntervalRef.current = setInterval(() => { + try { + if (wechatStatus === WECHAT_STATUS.WAITING && isMountedRef.current) { + console.log('备用轮询:检查微信状态'); + // 添加 .catch() 静默处理异步错误,防止被 ErrorBoundary 捕获 + checkWechatStatus().catch(error => { + console.warn('备用轮询检查失败(静默处理):', error); + }); + } + } catch (error) { + // 捕获所有同步错误,防止被 ErrorBoundary 捕获 + console.warn('备用轮询执行出错(静默处理):', error); + } + }, BACKUP_POLL_INTERVAL); + } + + // 清理备用轮询 + return () => { + if (backupPollIntervalRef.current) { + clearInterval(backupPollIntervalRef.current); + backupPollIntervalRef.current = null; + } + }; + }, [wechatAuthUrl, wechatSessionId, wechatStatus, checkWechatStatus]); + /** * 测量容器尺寸并计算缩放比例 */ @@ -314,6 +354,7 @@ export default function WechatRegister() { >