import { useQuery } from "@tanstack/react-query"; import { AppstoreOutlined, BarsOutlined, CloudUploadOutlined, FormOutlined, MessageOutlined, MobileOutlined, SafetyCertificateOutlined, TeamOutlined, ThunderboltOutlined, } from "@ant-design/icons"; import { useLocation, useNavigate } from "react-router-dom"; import { createApiClient } from "../lib/api.js"; import { BrandMark } from "../components/BrandMark.js"; import { StatusTag } from "../components/StatusTag.js"; import { FeatureBrandPage, FeatureCapabilitiesPage, FeatureInquiriesPage, FeatureMembersPage, FeatureOverviewPage, FeaturePublicationPage, FeatureTemplateManagementPage, FeatureServicesPage, FeatureTrustContentPage, FeatureWorkspacePage, } from "./routes.js"; import { LoadingStack } from "../components/LoadingStack.js"; import { AdminMenu } from "../components/AdminMenu.js"; import { adminMessage as message } from "../components/AdminMessage.js"; import { AdminButton } from "../components/AdminButton.js"; import { AdminSelect } from "../components/AdminSelect.js"; import { AdminLayout } from "../components/AdminLayout.js"; import { Route, Routes } from "react-router-dom"; import { AdminOverviewRedirect } from "./AdminRouter.js"; import { Suspense } from "react"; export function Dashboard({ onLogout, role, platformTemplateRole, }: { onLogout: () => void; role: string; platformTemplateRole: "none" | "template_admin"; }) { const navigate = useNavigate(); const location = useLocation(); const brand = useQuery({ queryKey: ["admin-shell-brand"], queryFn: () => createApiClient().getAdminBrand(), }); const memberships = useQuery({ queryKey: ["admin-brand-memberships"], queryFn: () => createApiClient().listAdminBrands(), }); const switchBrand = async (brandId: string) => { try { await createApiClient().switchAdminBrand(brandId); window.location.reload(); } catch (error) { message.error(error instanceof Error ? error.message : "品牌切换失败"); } }; const page = location.pathname.split("/")[2] || "overview"; const items = [ { type: "group" as const, label: "日常经营", children: [ { key: "overview", label: "当前品牌概览", icon: }, { key: "publication", label: "配置与发布", icon: }, { key: "brand", label: "小程序页面", icon: }, { key: "trust", label: "信任内容", icon: }, { key: "services", label: "业务提供项", icon: }, { key: "inquiries", label: "咨询记录", icon: }, { key: "workspace", label: "咨询表单与字段", icon: }, ], }, ...(role === "editor" ? [] : [ { type: "group" as const, label: "系统管理", children: [ { key: "capabilities", label: "能力插件", icon: }, { key: "members", label: "团队成员", icon: }, ...(platformTemplateRole === "template_admin" ? [{ key: "templates", label: "模板管理", icon: }] : []), ], }, ]), ]; return (
品牌工作区
navigate(`/admin/${key}`)} items={items} />
{brand.data?.name || "当前品牌"} 品牌工作区 { if (value) void switchBrand(value); }} options={(memberships.data ?? []).map((item) => ({ value: item.brand.id, label: item.brand.name, }))} />
退出登录
}> } /> } /> } /> } /> } /> } /> } /> } /> {role === "editor" ? null : ( <> } /> } /> {platformTemplateRole === "template_admin" ? ( } /> ) : null} )} } />
); }