From 9caf8b9786c5f748a2773409082883d97d199d25 Mon Sep 17 00:00:00 2001 From: jianghao <332515344@qq.com> Date: Thu, 26 Feb 2026 11:28:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=94=A8=E6=88=B7):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=AB=AF=E6=A3=80=E6=B5=8B=E5=B9=B6=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E7=99=BB=E5=BD=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在注册页面添加移动端检测钩子 登录成功后保存用户信息到localStorage并更新全局状态 --- src/pages/user/login/index.tsx | 7 ++++++- src/pages/user/register/index.tsx | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/user/login/index.tsx b/src/pages/user/login/index.tsx index b6f4f83..e5093af 100644 --- a/src/pages/user/login/index.tsx +++ b/src/pages/user/login/index.tsx @@ -125,8 +125,13 @@ const Login: React.FC = () => { defaultMessage: '登录成功!', }); message.success(defaultLoginSuccessMessage); - // await fetchUserInfo(); + // 保存用户信息到 localStorage localStorage.setItem('timeline_user', JSON.stringify(response.data)); + // 更新全局 initialState,确保跳转后权限检查通过 + await setInitialState((s: any) => ({ + ...s, + currentUser: response.data, + })); const urlParams = new URL(window.location.href).searchParams; // 修复:直接使用 redirect 参数,如果不存在则跳转到首页 const redirect = urlParams.get('redirect'); diff --git a/src/pages/user/register/index.tsx b/src/pages/user/register/index.tsx index 6235700..7afa924 100644 --- a/src/pages/user/register/index.tsx +++ b/src/pages/user/register/index.tsx @@ -6,6 +6,7 @@ import type { Store } from 'antd/es/form/interface'; import type { FC } from 'react'; import { useEffect, useState } from 'react'; import useStyles from './style.style'; +import { useIsMobile } from '@/hooks/useIsMobile'; const FormItem = Form.Item; const { Option } = Select;