import { Suspense, useState, useEffect } from 'react' import { Routes, Route, Navigate } from 'react-router-dom' import { Toaster } from 'sonner' import { useAuthStore } from './store/authStore' import TopNav from './components/layout/TopNav' import SidebarNav from './components/layout/SidebarNav' import MobileTabBar from './components/layout/MobileTabBar' import OnboardingGuide from './components/OnboardingGuide' import PortalLayout from './components/layout/PortalLayout' import PageContainer from './components/layout/PageContainer' import { CommandPalette } from './components/ui/CommandPalette' import { SkeletonPage } from './components/ui/Skeleton' import ErrorBoundary from './components/ui/ErrorBoundary' import { lazyRetry } from './lib/lazyRetry' const Login = lazyRetry(() => import('./pages/auth/Login')) const Register = lazyRetry(() => import('./pages/auth/Register')) const ForgotPassword = lazyRetry(() => import('./pages/auth/ForgotPassword')) const Dashboard = lazyRetry(() => import('./pages/Dashboard')) const Money = lazyRetry(() => import('./pages/Money')) const SocialInsurance = lazyRetry(() => import('./pages/SocialInsurance')) const Roster = lazyRetry(() => import('./pages/Roster')) const OrgChart = lazyRetry(() => import('./pages/OrgChart')) const SupportDashboard = lazyRetry(() => import('./pages/support/SupportDashboard')) const Termination = lazyRetry(() => import('./pages/Termination')) const AIAssistant = lazyRetry(() => import('./pages/AIAssistant')) const Settings = lazyRetry(() => import('./pages/Settings')) const Evidence = lazyRetry(() => import('./pages/Evidence')) const Policies = lazyRetry(() => import('./pages/Policies')) const Attendance = lazyRetry(() => import('./pages/Attendance')) const Templates = lazyRetry(() => import('./pages/Templates')) const AuditLog = lazyRetry(() => import('./pages/AuditLog')) const Notifications = lazyRetry(() => import('./pages/Notifications')) const PortalLogin = lazyRetry(() => import('./pages/portal/PortalLogin')) const Payslip = lazyRetry(() => import('./pages/portal/Payslip')) const MyContract = lazyRetry(() => import('./pages/portal/MyContract')) const Onboarding = lazyRetry(() => import('./pages/portal/Onboarding')) const ContractConfirm = lazyRetry(() => import('./pages/portal/ContractConfirm')) const MyPolicies = lazyRetry(() => import('./pages/portal/MyPolicies')) const AutoLogin = lazyRetry(() => import('./pages/portal/AutoLogin')) const MedicalPeriodCalculator = lazyRetry(() => import('./pages/tools/MedicalPeriodCalculator')) const HealthCheck = lazyRetry(() => import('./pages/tools/HealthCheck')) const AnnualValueReport = lazyRetry(() => import('./pages/tools/AnnualValueReport')) const CalendarPage = lazyRetry(() => import('./pages/Calendar')) const MyAttendance = lazyRetry(() => import('./pages/portal/MyAttendance')) const MyLeave = lazyRetry(() => import('./pages/portal/MyLeave')) const SpecialStatus = lazyRetry(() => import('./pages/SpecialStatus')) const CompanyFiles = lazyRetry(() => import('./pages/CompanyFiles')) const LeaveApproval = lazyRetry(() => import('./pages/LeaveApproval')) const TrainingRecords = lazyRetry(() => import('./pages/roster/TrainingRecords')) const PerformanceRecords = lazyRetry(() => import('./pages/roster/PerformanceRecords')) const DisciplinaryRecords = lazyRetry(() => import('./pages/roster/DisciplinaryRecords')) // Sprint 4-5 新增页面 const EmployeeHome = lazyRetry(() => import('./pages/portal/EmployeeHome')) const OnboardingProgress = lazyRetry(() => import('./pages/portal/OnboardingProgress')) const ResignationApply = lazyRetry(() => import('./pages/portal/ResignationApply')) const MyEsign = lazyRetry(() => import('./pages/portal/MyEsign')) const MyRecords = lazyRetry(() => import('./pages/portal/MyRecords')) const RiskCenter = lazyRetry(() => import('./pages/compliance/RiskCenter')) const SalaryDashboard = lazyRetry(() => import('./pages/SalaryDashboard')) const CommercialInsurance = lazyRetry(() => import('./pages/CommercialInsurance')) const EmployeeBenefits = lazyRetry(() => import('./pages/EmployeeBenefits')) const ESign = lazyRetry(() => import('./pages/ESign')) const CommissionBonus = lazyRetry(() => import('./pages/CommissionBonus')) // 平台管理端 const PlatformLogin = lazyRetry(() => import('./pages/platform/PlatformLogin')) const PlatformDashboard = lazyRetry(() => import('./pages/platform/PlatformDashboard')) const PlatformOrgs = lazyRetry(() => import('./pages/platform/PlatformOrgs')) const PlatformUsers = lazyRetry(() => import('./pages/platform/PlatformUsers')) const PlatformSidebar = lazyRetry(() => import('./components/layout/PlatformSidebar')) function ProtectedRoute({ children }: { children: React.ReactNode }) { const isAuthenticated = useAuthStore((s) => s.isAuthenticated) if (!isAuthenticated) return return <>{children} } function PublicRoute({ children }: { children: React.ReactNode }) { const isAuthenticated = useAuthStore((s) => s.isAuthenticated) if (isAuthenticated) return return <>{children} } function AdminLayout({ children }: { children: React.ReactNode }) { const [sidebarOpen, setSidebarOpen] = useState(false) return (
setSidebarOpen(false)} />
setSidebarOpen(true)} />
}>{children}
) } function PlatformRoute({ children }: { children: React.ReactNode }) { const user = useAuthStore((s) => s.user) const isAuthenticated = useAuthStore((s) => s.isAuthenticated) if (!isAuthenticated || user?.role !== 'SUPER_ADMIN') return return <>{children} } function PlatformLayout({ children }: { children: React.ReactNode }) { const [sidebarOpen, setSidebarOpen] = useState(false) return (
setSidebarOpen(false)} />
平台管理后台 ADMIN
}>{children}
) } function PortalLayoutWrapper({ children, showNav = true }: { children: React.ReactNode; showNav?: boolean }) { if (!showNav) { return (
}>{children}
) } return ( }>{children} ) } export default function App() { const [cmdOpen, setCmdOpen] = useState(false) const isAuthenticated = useAuthStore((s) => s.isAuthenticated) useEffect(() => { const handler = (e: KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault() if (isAuthenticated) setCmdOpen(true) } } window.addEventListener('keydown', handler) return () => window.removeEventListener('keydown', handler) }, [isAuthenticated]) return ( <> setCmdOpen(false)} /> {/* 管理端认证页面 */} }>} /> }>} /> }>} /> {/* 管理端业务页面 */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* 平台管理端 */} }>} /> } /> } /> } /> {/* 员工端 */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* 兜底 */} } /> ) }