import { useLayoutEffect, useRef, type ComponentType, type ReactNode } from "react"; import { BrowserRouter, Navigate, Outlet, Route, Routes, useLocation, useNavigate } from "react-router"; import { AppShell } from "../components/layout/AppShell"; import { ProfileOverlayProvider, useProfileOverlay } from "../components/layout/ProfileOverlay"; import { SessionProvider, landingPathFor, loginPathFor, useSession } from "../auth/session"; import { useDemoIdentity } from "../lib/demo-session"; import { getActiveDemoNavigation, getDemoLandingPath, getDemoNavigation } from "../access/demo-navigation"; import { TeamMembersPage, TeamDispatchModePage } from "../pages/TeamWorkspacePages"; import { CustomerPlanPage, CustomerAccountsPage } from "../pages/CustomerSelfServicePages"; import { CustomerSubmitPage, CustomerTicketProgressPage } from "../pages/CustomerTicketPages"; import { OperatorBillDetailPage, OperatorReconPage, PartyBillDetailPage, PartyContractDetailPage, PartyContractListPage, PartyCustomerDetailPage, PartyCustomerListPage, ScopedBillListPage, ScopedReconPage, } from "../pages/PartyViewPages"; import { IllustratedLoginPage } from "../pages/IllustratedLoginPage"; import { AccountActivationPage } from "../pages/AccountActivationPage"; import { NotFoundPage } from "../pages/NotFoundPage"; import { ForbiddenPage } from "../pages/ForbiddenPage"; import { PackageManagementPage } from "../pages/PackageManagementPage"; import { StarterPage } from "../pages/StarterPage"; import { OrderManagementPage } from "../pages/OrderManagementPage"; import { OrderRecordPage } from "../pages/OrderRecordPage"; import { WorkOrderLedgerPage } from "../pages/WorkOrderManagementPage"; import { WorkOrderOverviewPage } from "../pages/WorkOrderOverviewPage"; import { WorkOrderMinePage } from "../pages/WorkOrderMinePage"; import { WorkOrderQueuePage } from "../pages/WorkOrderQueuePage"; import { WorkOrderDeliveryPage } from "../pages/WorkOrderDeliveryPage"; import { WorkOrderRecordPage } from "../pages/WorkOrderRecordPage"; import { MobileWorkOrderBackfillPage, MobileWorkOrderDetailPage, MobileWorkOrderMinePage, } from "../pages/mobile/MobileWorkOrderPages"; import { ScheduledJobManagementPage } from "../pages/ScheduledJobManagementPage"; import { ImportBatchPage } from "../pages/CustomerManagementPages"; import { CustomerListPage, CustomerEditorPage } from "../pages/CustomerRecordsPages"; import { CustomerWorkspacePage } from "../pages/CustomerWorkspacePage"; import { CustomerOrdersPage } from "../pages/CustomerOrdersPage"; import { ContractManagementPage } from "../pages/ContractManagementPage"; import { ContractEditorPage } from "../pages/ContractDetailPages"; import { ContractRecordPage } from "../pages/ContractRecordPage"; import { CostManagementPage, CorrectionNotesPage } from "../pages/FinanceReferencePages"; import { ReconciliationSettingsPage, ShareRulePage } from "../pages/SettlementPages"; import { SettlementStatementListPage, SettlementStatementRecordPage, SettlementBillListPage, SettlementBillRecordPage } from "../pages/SettlementRecordPages"; import { AuditLogPage } from "../pages/AuditLogPage"; import { MaintenanceTeamAccountsPage, MaintenanceTeamLedgerPage, OperationsTeamAccountsPage, OperationsTeamManagementPage, OperatorManagementPage, PartnerManagementPage, RegionManagementPage } from "../pages/OrganizationPages"; import { notifySessionNotice } from "../lib/session-notice"; import { RouteErrorBoundary } from "../components/RouteErrorBoundary"; function ScrollToTop() { const { pathname } = useLocation(); useLayoutEffect(() => { const previous = window.history.scrollRestoration; window.history.scrollRestoration = "manual"; return () => { window.history.scrollRestoration = previous; }; }, []); useLayoutEffect(() => { window.scrollTo(0, 0); }, [pathname]); return null; } const workspacePages: Record = { members: TeamMembersPage, mode: TeamDispatchModePage, plan: CustomerPlanPage, accounts: CustomerAccountsPage, logs: () => , submit: CustomerSubmitPage, /* 缺陷 P-21(2026-11-14 实测):这里原先挂运营侧 `WorkOrderLedgerPage`——客户账号打开 * `/workspace/progress` 拿到的是运营口径的行集与列集,既看不到自己的工单,也没有 * 「确认完成,关闭工单」/「撤回」入口,手册 P7 的客户侧闭环断在这里。 * 改挂客户侧列表(⛔ 在运营台账页里塞 `if (客户)` 分支:那会让一页同时背两套口径, * 台账已有的告警卡/待办队列/分派操作对客户全是噪声)。 */ progress: CustomerTicketProgressPage, }; function RoleWorkspacePage() { const identity = useDemoIdentity(); const { pathname } = useLocation(); const item = getDemoNavigation(identity).find((entry) => entry.path === pathname && entry.workspace); const Page = item ? workspacePages[item.id] : undefined; if (!item || !Page) return ; return ; } /** 侧栏没有的页面⛔ 直达(例:运营子账号缺「组织与区域」组,手输 URL 也不放行)。 */ function NavAllowed({ children }: { children: ReactNode }) { const identity = useDemoIdentity(); const { pathname } = useLocation(); const allowed = Boolean(getActiveDemoNavigation(getDemoNavigation(identity), pathname)); useLayoutEffect(() => { if (!allowed) notifySessionNotice("你没有该页面权限(页面未对当前角色开放)。错误码:NAV-01。如需开通,请联系总运营在权限矩阵中授予对应菜单/角色后重试。"); }, [allowed, pathname]); if (allowed) { return {children}; } // D-7/TC-FN-86:统一「无权访问」页(⛔ 仅 Navigate 落地、靠崩溃兜底)。 return ( ); } /** * `/work-orders` =**运营侧台账**(列集:序号/工单·客户/责任人·团队/下一步/待办计数)。 * * ⚠️ 2026-11-18 实测:客户账号能进这一页(侧栏「工单进度」的 `activePaths` 也含它), * 看到的是一张**与菜单「工单进度」格式不同**的表;工单详情的「返回工单列表」旧实现又固定指向 * 这里,于是客户从客户列表进详情、返回后落到台账口径,看起来「回去的不是原来那张列表」。 * 客户侧的工单列表只有 `/workspace/progress` 一张(门户册 9)⇒ 这里原样把筛选/页码带到那张表上。 * ⛔ 用「客户也渲染台账、只是少几列」的做法:同一批工单出现两种格式,就是本次缺陷的起因。 */ function CustomerTicketListOnly({ children }: { children: ReactNode }) { const identity = useDemoIdentity(); const { search } = useLocation(); if (identity?.role === "enterprise" || identity?.role === "sub") return ; return <>{children}; } /** 未登录不放行任何业务页(登录态唯一真源=后端 `GET /auth/context@v1`,⛔ 前端自判)。 */ function GuardedLayout() { const { identity, loading } = useSession(); /** * ④-B(2026-11-14 实测):⛔ 在「中转站身份」落位前放行子树。 * * `SessionProvider` 在 effect 里才把会话身份写进 `demo-session`,而 effect 跑在本次渲染**之后** * ⇒ 子树首帧 `useDemoIdentity()` 仍是 null ⇒ `RoleWorkspacePage` 的 * `if (!item || !Page) return ` 就地按「未登录/无此页」处理, * 把深链接弹回落地页(实测客户账号冷加载/F5 `/workspace/progress` 连续 5 次全落回 `/workspace/plan`)。 * 守卫与身份水合必须同帧:这里等两份身份一致再渲染 `Outlet`,⛔ 让首帧抢跑一次弹跳。 */ const hydrated = useDemoIdentity(); const location = useLocation(); if (loading || (identity && hydrated !== identity)) return (
正在恢复会话…
); // 会话恢复失败(401/AC 拒绝/网络抖动)也走这里:把被拦下的深链接带给登录页, // 登录成功后回原页,⛔ 一律落回首页(缺口清单 C-6)。 // `/m/*` 踢到 `/m/login`,登录后仍落在移动端界面。 if (!identity) { const from = `${location.pathname}${location.search}`; // D-CT-12:深链回跳备份——登录页刷新会丢 location.state,sessionStorage 兜住含 query 的完整 URL。 try { sessionStorage.setItem("oss:returnTo", from); } catch { /* 隐私模式等写失败 ⇒ 仍靠 state.from */ } return ; } return ( ); } /** * `/profile` 深链接兜底(业主 2026-11-14 定案:个人资料是浮层、⛔ 独立页面)。 * * 老书签/别处硬跳 `/profile` 时:先把浮层打开,再把 URL 原地换回本角色落地页—— * 用户看到的是「浮层叠在页面上」,⛔ 一个只剩资料页的空壳页面。 */ function ProfileDeepLink() { const { openProfile } = useProfileOverlay(); const { ctx } = useSession(); const navigate = useNavigate(); const landed = useRef(false); useLayoutEffect(() => { if (landed.current) return; landed.current = true; openProfile(); navigate(ctx ? landingPathFor(ctx) : "/", { replace: true }); }, [ctx, navigate, openProfile]); return null; } function Workspace() { const identity = useDemoIdentity(); const customerView = identity?.role === "enterprise" || identity?.role === "sub"; const readOnlyViewer = Boolean(identity && !["admin", "regAdmin"].includes(identity.role)); return ( } /> {/* 移动端 H5 登录:Token 失效从 `/m/*` 踢回这里,登录后仍落移动端。 */} } /> {/* 免登录激活页(手册 P2):注册在 GuardedLayout 之外,⛔ 会话守卫拦它去 /login。 */} } /> }> } /> } /> {/* 总则§16.2:AC-05 与 AC-06 同页(`/bos/me`),⛔ 不保留独立「设置」路由。 */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> : } /> {/* @deprecated 详情与编辑已二合一:旧的 /edit 深链落到同一个详情页,编辑在详情内联完成。 */} } /> } /> } /> } /> : } /> {/* @deprecated 详情与编辑已二合一:旧的 /edit 深链落到同一个详情页,编辑在详情内联完成。 */} } /> } /> } /> } /> } /> {/* D-7/TC-FN-86:分成与对账组按侧栏可见性守卫,越权直达⛔ 白屏崩溃兜底,提示 NAV-01 后回落地页。 */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* 运维现场移动端 H5(无 AppShell,触控优先) */} } /> } /> } /> } /> } /> } /> {/* ══ 册 8 只读视图(视图§14.1 路由表逐字) ══ */} {/* V-P4/V-P9 本方变更记录:同一读口、同一组件,按宿主身份换标题(作业§5.3 纪律 3) */} } /> } /> } /> } /> } /> {/* V-P2 合伙人客户清单 */} } /> {/* V-D1 客户详情宿主 */} } /> {/* V-P3 合伙人合同清单(行末只有查看) */} } /> } /> {/* V-D1 账单明细详情宿主 */} } /> } /> {/* V-P5 运营商对账清单 */} } /> {/* V-P6 运营商账单明细 */} } /> } /> {/* V-P7 运营商客户清单 */} } /> } /> {/* V-P8 运营商合同清单 */} } /> } /> } /> {/* V-D1 明细详情 teamLead 宿主(14.1 未列 tv 段,14.6 返回链路表含 teamLead 明细详情 ⇒ 按 14.6 补注册,分歧已登记) */} } /> } /> {/* D-21:旧菜单地址迁到 /bos/pv/recon,⛔ 再落 404 开发口吻页。 */} } /> } /> ); } export default function App() { return ( ); } import { WorkOrderSettingsPage } from "../pages/WorkOrderSettingsPage";