import React, { useEffect } from 'react'; import { createRoot } from 'react-dom/client'; import { createBrowserRouter, RouterProvider, Outlet, Navigate, useLocation } from 'react-router'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { AuthProvider, ThemeProvider, useAuth } from './hooks.tsx'; import HomePage from './pages/index.tsx'; import LoginPage from './pages/login.tsx'; import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; // 设置中文语言 dayjs.locale('zh-cn'); // 创建QueryClient实例 const queryClient = new QueryClient(); // 添加全局CSS(使用TailwindCSS的类) const injectGlobalStyles = () => { const style = document.createElement('style'); style.innerHTML = ` :root { --primary-color: #3B82F6; --background-color: #F9FAFB; --text-color: #111827; --border-radius: 8px; --font-size: 16px; } * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; background-color: var(--background-color); color: var(--text-color); font-size: var(--font-size); line-height: 1.5; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .line-clamp-1 { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; } .line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } .line-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; } /* 暗色模式支持 */ .dark { color-scheme: dark; } .dark body { background-color: #121212; color: #E5E7EB; } /* 滚动条美化 */ ::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background: #BFDBFE; border-radius: 3px; } ::-webkit-scrollbar-thumb:hover { background: #93C5FD; } /* 移动端点击高亮颜色 */ * { -webkit-tap-highlight-color: transparent; } `; document.head.appendChild(style); }; // 授权路由守卫 const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { const { isAuthenticated, isLoading } = useAuth(); const location = useLocation(); if (isLoading) { return (
); } if (!isAuthenticated) { return ; } return <>{children}; }; // 页面组件 const PageNotFound = () => (
404

页面不存在

您访问的页面不存在或已被移除

返回首页
); // 添加个人页面组件 const ProfilePage = () => (

我的

用户

用户名

个人信息

设置
账号安全
通知设置
隐私
关于
); // 添加通知页面组件 const NotificationsPage = () => (

通知

系统通知

欢迎使用移动应用!

今天 10:00

活动提醒

您有一个新的活动邀请

昨天 14:30

); // 移动端布局组件 - 包含底部导航 const MobileLayout = () => { const location = useLocation(); return (
{/* 底部导航栏 */}
); }; // 主应用组件 const App = () => { // 创建路由器配置 const router = createBrowserRouter([ { path: '/', element: }, { path: '/mobile/login', element: }, { path: '/mobile', element: ( ), children: [ { index: true, element: }, { path: 'profile', element: }, { path: 'notifications', element: } ] }, { path: '*', element: } ]); return ; }; // 渲染应用到DOM const initApp = () => { // 注入全局样式 injectGlobalStyles(); // 渲染应用 const root = createRoot(document.getElementById('root') as HTMLElement); root.render( ); }; // 初始化应用 initApp();