import { useQuery } from "@tanstack/react-query";
import {
AppstoreOutlined,
BarsOutlined,
CloudUploadOutlined,
FormOutlined,
LayoutOutlined,
MessageOutlined,
MobileOutlined,
SafetyCertificateOutlined,
ShopOutlined,
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,
FeatureBrandsPage,
FeatureCapabilitiesPage,
FeatureCreateBrandPage,
FeatureInquiriesPage,
FeatureMembersPage,
FeatureOverviewPage,
FeaturePageSchemePage,
FeaturePublicationPage,
FeatureTemplateManagementPage,
FeatureServicesPage,
FeatureTrustContentPage,
FeatureWorkspacePage,
} from "./routes.js";
import { LoadingStack } from "../components/LoadingStack.js";
import { AdminMenu } from "../components/AdminMenu.js";
import { App } from "antd";
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 { createBrandRouteElement } from "./route-access.js";
import { Suspense } from "react";
import { AdminErrorBoundary } from "../components/AdminErrorBoundary.js";
import { toBrandDisplayName, toBrandSwitcherOptions } from "../lib/brand-switcher.js";
export function Dashboard({
onLogout,
role,
platformTemplateRole,
}: {
onLogout: () => void;
role: string;
platformTemplateRole: "none" | "template_admin";
}) {
const { message } = App.useApp();
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 brandName = toBrandDisplayName(brand.data?.name, "当前品牌");
const brandOptions = toBrandSwitcherOptions(memberships.data);
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: "brands", label: "品牌管理", icon: },
{ key: "page-scheme", label: "页面方案", icon: },
{ key: "capabilities", label: "能力插件", icon: },
{ key: "members", label: "团队成员", icon: },
...(platformTemplateRole === "template_admin"
? [{ key: "templates", label: "模板管理", icon: }]
: []),
],
},
]),
];
return (
品牌工作区
navigate(`/admin/${key}`)}
items={items}
/>
{brandName}
品牌工作区
{
if (value) void switchBrand(value);
}}
options={brandOptions}
/>
退出登录
}>
} />
} />
} />
} />
} />
} />
} />
} />
{role === "editor" ? null : (
<>
}
/>
)}
/>
} />
} />
} />
{platformTemplateRole === "template_admin" ? (
} />
) : null}
>
)}
} />
);
}