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}
- ))} -
- )}