import { useEffect, useMemo, useState } from "react"; import { Blocks, Home, LogOut, MapPin, Package, UserRoundCheck } from "lucide-react"; import { clearToken, getDestinations } from "@/api"; import type { Destination } from "@/api"; import { ToastStack } from "@/components/admin/ToastStack"; import { Button } from "@/components/ui/button"; import { LeadsPage } from "@/pages/leads/LeadsPage"; import { ProductsPage } from "@/pages/products/ProductsPage"; import { StructurePage } from "@/pages/structure/StructurePage"; import type { Tab, Toast } from "@/types/admin"; const sidebarGroups: { id: string; label: string; items: { id: Tab; label: string; icon: typeof Home; description: string }[] }[] = [ { id: "workspace", label: "工作台", items: [{ id: "structure", label: "维护地图", icon: Blocks, description: "前台结构总览" }], }, { id: "frontend", label: "前台页面", items: [ { id: "home", label: "小程序首页", icon: Home, description: "轮播、主题、CTA" }, { id: "destinations", label: "目的地页", icon: MapPin, description: "主视觉、热门、省内" }, { id: "products", label: "商品维护", icon: Package, description: "列表、卡片、详情" }, ], }, { id: "operations", label: "业务处理", items: [{ id: "leads", label: "需求线索", icon: UserRoundCheck, description: "表单和跟进" }], }, ]; const tabs = sidebarGroups.flatMap((group) => group.items); const hiddenTabs: Partial> = { leadList: { label: "线索查询跟进", description: "表单查询和状态流转" }, }; export function AdminShell({ onLogout }: { onLogout: () => void }) { const [activeTab, setActiveTab] = useState("structure"); const [destinations, setDestinations] = useState([]); const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); const [toasts, setToasts] = useState([]); useEffect(() => { getDestinations() .then((result) => setDestinations(result.items)) .catch(() => setDestinations([])); }, [activeTab]); useEffect(() => { setHasUnsavedChanges(false); }, [activeTab]); const activeMeta = useMemo(() => tabs.find((tab) => tab.id === activeTab) ?? hiddenTabs[activeTab], [activeTab]); const activeLabel = activeMeta?.label ?? ""; const activeDescription = activeMeta?.description ?? ""; const notify = (toast: Omit) => { const id = `toast-${Date.now()}-${Math.random().toString(16).slice(2)}`; setToasts((items) => [...items, { ...toast, id }]); window.setTimeout(() => { setToasts((items) => items.filter((item) => item.id !== id)); }, 4200); }; const logout = () => { clearToken(); onLogout(); }; return (
{activeLabel} {activeDescription} · 结构化维护 · 内存开发模式
{hasUnsavedChanges ? "有未提交修改" : "内容已同步"}
{activeTab === "structure" ? ( ) : activeTab === "home" ? ( ) : activeTab === "destinations" ? ( ) : activeTab === "products" ? ( ) : activeTab === "leads" ? ( ) : ( )}
setToasts((items) => items.filter((item) => item.id !== id))} />
); }