171 lines
6.4 KiB
TypeScript
171 lines
6.4 KiB
TypeScript
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: <AppstoreOutlined /> },
|
|
{ key: "publication", label: "配置与发布", icon: <CloudUploadOutlined /> },
|
|
{ key: "brand", label: "小程序页面", icon: <MobileOutlined /> },
|
|
{ key: "trust", label: "信任内容", icon: <SafetyCertificateOutlined /> },
|
|
{ key: "services", label: "业务提供项", icon: <BarsOutlined /> },
|
|
{ key: "inquiries", label: "咨询记录", icon: <MessageOutlined /> },
|
|
{ key: "workspace", label: "咨询表单与字段", icon: <FormOutlined /> },
|
|
],
|
|
},
|
|
...(role === "editor"
|
|
? []
|
|
: [
|
|
{
|
|
type: "group" as const,
|
|
label: "系统管理",
|
|
children: [
|
|
{ key: "capabilities", label: "能力插件", icon: <ThunderboltOutlined /> },
|
|
{ key: "members", label: "团队成员", icon: <TeamOutlined /> },
|
|
...(platformTemplateRole === "template_admin"
|
|
? [{ key: "templates", label: "模板管理", icon: <AppstoreOutlined /> }]
|
|
: []),
|
|
],
|
|
},
|
|
]),
|
|
];
|
|
return (
|
|
<AdminLayout className="admin-shell">
|
|
<AdminLayout.Sider className="admin-sider" breakpoint="lg" collapsedWidth={0} width={232}>
|
|
<div className="admin-sider-brand">
|
|
<BrandMark name={brand.data?.name} />
|
|
<span className="admin-sider-brand-name">品牌工作区</span>
|
|
</div>
|
|
<AdminMenu
|
|
selectedKeys={[page]}
|
|
onClick={({ key }) => navigate(`/admin/${key}`)}
|
|
items={items}
|
|
/>
|
|
</AdminLayout.Sider>
|
|
<AdminLayout className="admin-main">
|
|
<AdminLayout.Header className="admin-header">
|
|
<div className="admin-header-left">
|
|
<span className="admin-header-brand">{brand.data?.name || "当前品牌"}</span>
|
|
<span className="admin-header-context">品牌工作区</span>
|
|
<StatusTag
|
|
tone={role === "owner" ? "info" : "neutral"}
|
|
label={role === "owner" ? "负责人" : "内容编辑"}
|
|
/>
|
|
<AdminSelect
|
|
size="small"
|
|
variant="outlined"
|
|
className="admin-brand-switcher"
|
|
value={brand.data?.id}
|
|
loading={memberships.isLoading}
|
|
onChange={(value: string | undefined) => {
|
|
if (value) void switchBrand(value);
|
|
}}
|
|
options={(memberships.data ?? []).map((item) => ({
|
|
value: item.brand.id,
|
|
label: item.brand.name,
|
|
}))}
|
|
/>
|
|
</div>
|
|
<AdminButton type="text" onClick={onLogout}>
|
|
退出登录
|
|
</AdminButton>
|
|
</AdminLayout.Header>
|
|
<AdminLayout.Content className="admin-content">
|
|
<div className="admin-content-inner">
|
|
<Suspense fallback={<LoadingStack />}>
|
|
<Routes>
|
|
<Route index element={<AdminOverviewRedirect />} />
|
|
<Route path="overview" element={<FeatureOverviewPage />} />
|
|
<Route
|
|
path="publication"
|
|
element={<FeaturePublicationPage canManageTemplate={role !== "editor"} />}
|
|
/>
|
|
<Route path="brand" element={<FeatureBrandPage />} />
|
|
<Route path="trust" element={<FeatureTrustContentPage />} />
|
|
<Route path="services" element={<FeatureServicesPage />} />
|
|
<Route path="inquiries" element={<FeatureInquiriesPage />} />
|
|
<Route path="workspace" element={<FeatureWorkspacePage />} />
|
|
{role === "editor" ? null : (
|
|
<>
|
|
<Route path="capabilities" element={<FeatureCapabilitiesPage />} />
|
|
<Route path="members" element={<FeatureMembersPage />} />
|
|
{platformTemplateRole === "template_admin" ? (
|
|
<Route path="templates" element={<FeatureTemplateManagementPage />} />
|
|
) : null}
|
|
</>
|
|
)}
|
|
<Route path="*" element={<AdminOverviewRedirect />} />
|
|
</Routes>
|
|
</Suspense>
|
|
</div>
|
|
</AdminLayout.Content>
|
|
</AdminLayout>
|
|
</AdminLayout>
|
|
);
|
|
}
|