import React from 'react';
import Home from './user/Home';
const ParkMap = React.lazy(() => import('./user/ParkMap')); // 载体地图懒加载(含 1.8MB 预计算点阵,独立分包)
import System from './platform/System';
import Structures from './platform/Structures';
import Schedule from './platform/Schedule';
import Cards from './platform/Cards';
import Tools from './platform/Tools';
import OPCTest from './user/OPCTest';
import Events from './user/Events';
import EventDetail from './user/EventDetail';
import PolicyTest from './user/PolicyTest';
import StartPlan from './user/StartPlan';
import OPCSurvey from './user/OPCSurvey';
import Profile from './user/Profile';
import PineHome from './platform/PineHome';
import PineOps from './platform/PineOps';
import PineBookings from './platform/PineBookings';
import PineEvents from './platform/PineEvents';
import PineTests from './platform/PineTests';
import ReportHome from './platform/report/ReportHome';
import ReportBiz from './platform/report/ReportBiz';
import ReportPolicy from './platform/report/ReportPolicy';
import ReportData from './platform/report/ReportData';
import PineLogs from './platform/PineLogs';
import Login from './platform/Login';
import { ParticleField } from './components/organisms';
import { isAuthed } from './services/auth';
import { initTheme } from './services/theme';
import ParkApply from './user/ParkApply';
import CertApply from './user/CertApply';
import ParkTransfer from './user/ParkTransfer';
import Content from './user/Content';
import ContentDetail from './user/ContentDetail';
import Tasks from './user/Tasks';
import TaskDetail from './user/TaskDetail';
import Enterprise from './platform/Enterprise';
import ParkCenter from './platform/ParkCenter';
import MyBookings from './user/MyBookings';
import MyTasks from './user/MyTasks';
import MyPark from './user/MyPark';
import MyCert from './user/MyCert';
import Parks from './user/Parks';
import ParkDetail from './user/ParkDetail';
import Hall from './user/Hall';
import HallTasks from './user/HallTasks';
import HallTaskDetail from './user/HallTaskDetail';
import HallTaskPublish from './user/HallTaskPublish';
import HallTalents from './user/HallTalents';
import TalentDetail from './user/TalentDetail';
import HallJobs from './user/HallJobs';
import JobDetail from './user/JobDetail';
import HallServices from './user/HallServices';
import ServiceDetail from './user/ServiceDetail';
import Community from './user/Community';
import CommunityPost from './user/CommunityPost';
import HallServicePublish from './user/HallServicePublish';
/* 公开路由(无需登录) */
const PUBLIC_ROUTES = [
{ path: '', Page: Home },
{ path: 'events', Page: Events },
{ path: 'event-detail', Page: EventDetail },
{ path: 'opc-test', Page: OPCTest },
{ path: 'policy-test', Page: PolicyTest },
{ path: 'start-plan', Page: StartPlan },
{ path: 'survey', Page: OPCSurvey },
{ path: 'park-apply', Page: ParkApply },
{ path: 'cert-apply', Page: CertApply },
{ path: 'park-transfer', Page: ParkTransfer },
{ path: 'content', Page: Content },
{ path: 'content-detail', Page: ContentDetail },
{ path: 'tasks', Page: Tasks },
{ path: 'hall', Page: Hall },
{ path: 'hall/tasks', Page: HallTasks },
{ path: 'hall/tasks/publish', Page: HallTaskPublish },
{ path: 'hall/task-detail', Page: HallTaskDetail },
{ path: 'hall/talents', Page: HallTalents },
{ path: 'hall/talent-detail', Page: TalentDetail },
{ path: 'hall/jobs', Page: HallJobs },
{ path: 'hall/job-detail', Page: JobDetail },
{ path: 'hall/services', Page: HallServices },
{ path: 'hall/services/publish', Page: HallServicePublish },
{ path: 'hall/service-detail', Page: ServiceDetail },
{ path: 'community', Page: Community },
{ path: 'community/post', Page: CommunityPost },
{ path: 'task-detail', Page: TaskDetail },
{ path: 'enterprise', Page: Enterprise },
{ path: 'park-center', Page: ParkCenter },
{ path: 'map', Page: ParkMap },
{ path: 'parks', Page: Parks },
{ path: 'park-detail', Page: ParkDetail },
{ path: 'profile', Page: Profile },
{ path: 'my-bookings', Page: MyBookings },
{ path: 'my-tasks', Page: MyTasks },
{ path: 'my-park', Page: MyPark },
{ path: 'my-cert', Page: MyCert }
];
/* 内部路由(/pine,需登录) */
const PINE_ROUTES = [
{ path: 'pine', Page: PineHome },
{ path: 'pine/ops', Page: PineOps },
{ path: 'pine/bookings', Page: PineBookings },
{ path: 'pine/events', Page: PineEvents },
{ path: 'pine/tests', Page: PineTests },
{ path: 'pine/logs', Page: PineLogs },
{ path: 'pine/report', Page: ReportHome },
{ path: 'pine/report/biz', Page: ReportBiz },
{ path: 'pine/report/policy', Page: ReportPolicy },
{ path: 'pine/report/data', Page: ReportData },
{ path: 'pine/system', Page: System },
{ path: 'pine/structures', Page: Structures },
{ path: 'pine/schedule', Page: Schedule },
{ path: 'pine/cards', Page: Cards },
{ path: 'pine/tools', Page: Tools }
];
const ALL_ROUTES = [...PUBLIC_ROUTES, ...PINE_ROUTES];
const isPine = (p) => p === 'pine' || p.startsWith('pine/');
function parseHash() {
return window.location.hash.replace(/^#\/?/, '').split('?')[0].trim();
}
export default function App() {
const [path, setPath] = React.useState(parseHash);
React.useEffect(() => {
initTheme();
const onHash = () => setPath(parseHash());
window.addEventListener('hashchange', onHash);
return () => window.removeEventListener('hashchange', onHash);
}, []);
// 切换页面时回到顶部:滚动位置不跨页面共享(同一页面内的锚点/局部滚动不受影响)
React.useEffect(() => {
window.scrollTo({ top: 0, left: 0, behavior: 'auto' });
}, [path]);
const route = ALL_ROUTES.find((r) => r.path === path) || PUBLIC_ROUTES[0];
// 路由守卫:内部路由未登录 → 登录门(目标路径回传,登录后跳回)
if (isPine(route.path) && !isAuthed()) {
return (
<>
>
);
}
const { Page } = route;
return (
<>
>
);
}