// chrome.jsx — Sidebar, Topbar shared chrome (route-aware) const SIDEBAR_ITEMS = [ { id: "overview", icon: "map", label: "实时地图" }, { id: "detail", icon: "car", label: "车辆详情" }, { id: "history", icon: "history", label: "历史查询" }, { id: "playback", icon: "route", label: "轨迹回放" }, { id: "alarm", icon: "bell", label: "事件规则" }, { id: "inbox", icon: "inbox", label: "通知中心" }, { id: "integration", icon: "plug", label: "数据接入监控" }, ]; const SIDEBAR_SUB = [ { id: "esg", icon: "chart", label: "ESG·碳减排" }, { id: "canvas", icon: "settings", label: "设计画板" }, ]; const Sidebar = ({ active }) => { // resolve current route from context if present, fall back to prop const ctx = (typeof window.useRoute === "function") ? window.useRoute() : null; const cur = (ctx && ctx.route) || active || "overview"; const nav = (ctx && ctx.navigate) || ((p) => { window.location.hash = "#/" + p; }); return (
nav("overview")} style={{ cursor:"pointer", background:"#FFFFFF", border:"1px solid var(--border-1)", boxShadow:"0 1px 2px rgba(47,40,40,.06)", overflow:"hidden", padding:0, }}> 羚牛
{SIDEBAR_ITEMS.map(i => (
nav(i.id)} style={{cursor:"pointer"}}>
))}
{SIDEBAR_SUB.map(i => (
nav(i.id)} style={{cursor:"pointer"}}>
))}
ZG
); }; const Topbar = ({ crumbs = ["羚牛车辆数据中心", "实时监控"], kpis = [], showSearch = true }) => { const ctx = (typeof window.useRoute === "function") ? window.useRoute() : null; const isMobile = ctx && ctx.isMobile; return (
{isMobile && ( )}
{crumbs.map((c, i) => ( {i > 0 && /} {c} ))}
{kpis.map((k, i) => (
{k.lbl} {k.val} {k.delta && {k.deltaUp ? "▲" : "▼"} {k.delta}}
))}
{showSearch && (
⌘K
)}
); }; // Role badge — shows current logged-in user, opens tweaks panel on click const RoleBadge = () => { const { role } = (typeof window.useCurrentRole === "function") ? window.useCurrentRole() : { role: null }; if (!role) return
; const initial = role.name.replace(/.*·/,"").charAt(0) || role.name.charAt(0); const isAdmin = role.scope === "all"; const tip = role.scope === "dept" ? `仅可见 ${role.deptId === "biz1" ? "业务一部" : "业务二部"} 车辆` : role.desc; return (
{role.name} {role.scope === "all" ? "FULL ACCESS" : role.scope === "dept" ? "DEPT SCOPE" : role.scope === "ops" ? "OPS" : "FINANCE"}
{initial}
); }; // Theme toggle — switches between light & dark themes const ThemeToggle = () => { const ctx = (typeof window.useTheme === "function") ? window.useTheme() : null; if (!ctx) return null; const { theme, setTheme } = ctx; const isDark = theme === "dark"; return ( ); }; window.Sidebar = Sidebar; window.Topbar = Topbar;