From 9a14a75b42a64f3f5e45a1c6365f9885e4a4e165 Mon Sep 17 00:00:00 2001 From: karlcarlo Date: Thu, 25 Jun 2026 19:24:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20move=20debug=20overlay=20to=20MobileLay?= =?UTF-8?q?out=20(=E5=85=A8=E5=B1=80=E6=8C=81=E4=B9=85=E6=98=BE=E7=A4=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/serv.sh | 0 frontend/src/app/components/MobileLayout.tsx | 19 ++++++++++++++++--- frontend/src/app/context/UserContext.tsx | 13 ++++++++++++- frontend/src/app/pages/LoginPage.tsx | 19 +------------------ 4 files changed, 29 insertions(+), 22 deletions(-) mode change 100755 => 100644 backend/serv.sh diff --git a/backend/serv.sh b/backend/serv.sh old mode 100755 new mode 100644 diff --git a/frontend/src/app/components/MobileLayout.tsx b/frontend/src/app/components/MobileLayout.tsx index 3e36298..1e0cb10 100644 --- a/frontend/src/app/components/MobileLayout.tsx +++ b/frontend/src/app/components/MobileLayout.tsx @@ -1,14 +1,27 @@ import { Outlet } from "react-router"; +import { useUser } from "../context/UserContext"; /** * H5 移动端全局布局容器 - * - max-w-md (448px) 限制最大宽度,大屏居中显示 - * - min-h-dvh 使用动态视口高度,解决 Safari 地址栏问题 - * - safe-area padding 适配刘海屏/底部手势条 */ export function MobileLayout() { + const { debugInfo, clearDebug } = useUser(); + return (
+ {/* 全局调试浮层:所有页面下可见 */} + {debugInfo.length > 0 && ( +
clearDebug()} + > +
H5应用调试
+ {debugInfo.map((msg, i) => ( +
{msg}
+ ))} +
+ )}
); diff --git a/frontend/src/app/context/UserContext.tsx b/frontend/src/app/context/UserContext.tsx index b46f5ab..b94fd9c 100644 --- a/frontend/src/app/context/UserContext.tsx +++ b/frontend/src/app/context/UserContext.tsx @@ -187,6 +187,9 @@ interface UserContextValue { setToken: (token: string) => void; setTokenAndUser: (token: string, info: BasicUserInfo) => void; fetchProfile: () => Promise; + debugInfo: string[]; + addDebug: (msg: string) => void; + clearDebug: () => void; logout: () => void; } @@ -195,6 +198,14 @@ const UserContext = createContext(null); export function UserProvider({ children }: { children: ReactNode }) { const [user, setUser] = useState(loadProfile); const [token, setTokenState] = useState(getToken); + const [debugInfo, setDebugInfo] = useState([]); + const addDebug = useCallback((msg: string) => { + console.log(msg); + setDebugInfo(prev => [...prev.slice(-20), msg]); + }, []); + const clearDebug = useCallback(() => { + setDebugInfo([]); + }, []); const setToken = useCallback((newToken: string) => { // 清理前一个用户的本地数据,防止用户间数据残留 @@ -280,7 +291,7 @@ export function UserProvider({ children }: { children: ReactNode }) { }, []); // eslint-disable-line react-hooks/exhaustive-deps return ( - + {children} ); diff --git a/frontend/src/app/pages/LoginPage.tsx b/frontend/src/app/pages/LoginPage.tsx index 9f24e67..445c499 100644 --- a/frontend/src/app/pages/LoginPage.tsx +++ b/frontend/src/app/pages/LoginPage.tsx @@ -10,11 +10,7 @@ export function LoginPage() { const navigate = useNavigate(); const { setTokenAndUser, fetchProfile } = useUser(); const [error, setError] = useState(""); - const [debugInfo, setDebugInfo] = useState([]); - const addDebug = (msg: string) => { - console.log(msg); - setDebugInfo(prev => [...prev.slice(-20), msg]); - }; + const { addDebug, debugInfo } = useUser(); useEffect(() => { clearDebugLogs(); @@ -98,19 +94,6 @@ export function LoginPage() { return (
- {/* 调试浮层:点击可关闭 */} - {debugInfo.length > 0 && ( -
setDebugInfo([])} - > -
H5应用调试
- {debugInfo.map((msg, i) => ( -
{msg}
- ))} -
- )}