diff --git a/app.py b/app.py index 667c82c7..796d7fbf 100755 --- a/app.py +++ b/app.py @@ -4180,7 +4180,9 @@ def wechat_callback(): 'debug_user_id': user.id, 'debug_nickname': user_info.get('nickname', '')[:10], }) - return redirect(f"{frontend_redirect}?{debug_params}") + # ⚡ 修复:正确处理已有查询参数的 URL + separator = '&' if '?' in frontend_redirect else '?' + return redirect(f"{frontend_redirect}{separator}{debug_params}") # PC 扫码模式:更新状态供前端轮询 if not mode: diff --git a/src/components/Auth/AuthFormContent.js b/src/components/Auth/AuthFormContent.js index 1dad5095..25b5f6b9 100644 --- a/src/components/Auth/AuthFormContent.js +++ b/src/components/Auth/AuthFormContent.js @@ -407,8 +407,10 @@ export default function AuthFormContent() { authEvents.trackWechatLoginInitiated('icon_button'); try { - // 1. 构建回调URL - const redirectUrl = `${window.location.origin}/home/wechat-callback`; + // 1. 构建回调URL,携带当前页面路径以便登录后返回 + const currentPath = window.location.pathname + window.location.search; + const returnUrl = encodeURIComponent(currentPath); + const redirectUrl = `${window.location.origin}/home/wechat-callback?returnUrl=${returnUrl}`; // 2. 显示提示 toast({ diff --git a/src/views/Pages/WechatCallback.js b/src/views/Pages/WechatCallback.js index b0395f90..7878f7aa 100644 --- a/src/views/Pages/WechatCallback.js +++ b/src/views/Pages/WechatCallback.js @@ -38,11 +38,21 @@ export default function WechatCallback() { const code = searchParams.get("code"); const state = searchParams.get("state"); const wechatLogin = searchParams.get("wechat_login"); + // ⚡ 获取登录前的页面路径(用于登录后跳转回原页面) + const returnUrl = searchParams.get("returnUrl"); + const targetUrl = returnUrl ? decodeURIComponent(returnUrl) : "/home"; + + logger.info('WechatCallback', '解析回调参数', { + wechatLogin, + returnUrl, + targetUrl, + state + }); // 2. 检查是否是 H5 模式登录成功回调 // 后端已经完成登录,只需要刷新前端 session 状态 if (wechatLogin === "success") { - logger.info('WechatCallback', 'H5 模式登录成功', { state }); + logger.info('WechatCallback', 'H5 模式登录成功', { state, targetUrl }); // 刷新 session 状态 await checkSession(); @@ -51,9 +61,9 @@ export default function WechatCallback() { setStatus("success"); setMessage("登录成功!正在跳转..."); - // 延迟跳转到首页 + // ⚡ 延迟跳转到原页面(而不是固定 /home) setTimeout(() => { - navigate("/home", { replace: true }); + navigate(targetUrl, { replace: true }); }, 1000); return; } @@ -85,15 +95,16 @@ export default function WechatCallback() { setStatus("success"); setMessage("登录成功!正在跳转..."); - // 8. 延迟跳转到首页 + // 8. ⚡ 延迟跳转到原页面(而不是固定 /home) setTimeout(() => { - navigate("/home", { replace: true }); + navigate(targetUrl, { replace: true }); }, 1500); } catch (error) { logger.error('WechatCallback', 'handleCallback', error, { code: searchParams.get("code"), state: searchParams.get("state"), wechat_login: searchParams.get("wechat_login"), + returnUrl: searchParams.get("returnUrl"), errorMessage: error.message }); setStatus("error");