CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
189 lines
7.4 KiB
TypeScript
189 lines
7.4 KiB
TypeScript
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: <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: "brands", label: "品牌管理", icon: <ShopOutlined /> },
|
|
{ key: "page-scheme", label: "页面方案", icon: <LayoutOutlined /> },
|
|
{ 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={toBrandDisplayName(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">{brandName}</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={brandOptions}
|
|
/>
|
|
</div>
|
|
<AdminButton type="text" onClick={onLogout}>
|
|
退出登录
|
|
</AdminButton>
|
|
</AdminLayout.Header>
|
|
<AdminLayout.Content className="admin-content">
|
|
<div className="admin-content-inner">
|
|
<AdminErrorBoundary key={location.pathname}>
|
|
<Suspense fallback={<LoadingStack />}>
|
|
<Routes>
|
|
<Route index element={<AdminOverviewRedirect />} />
|
|
<Route path="overview" element={<FeatureOverviewPage />} />
|
|
<Route path="publication" element={<FeaturePublicationPage />} />
|
|
<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="brands"
|
|
element={<FeatureBrandsPage canCreate={role === "owner"} />}
|
|
/>
|
|
<Route
|
|
path="brands/new"
|
|
element={createBrandRouteElement(role, <FeatureCreateBrandPage />)}
|
|
/>
|
|
<Route path="page-scheme" element={<FeaturePageSchemePage />} />
|
|
<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>
|
|
</AdminErrorBoundary>
|
|
</div>
|
|
</AdminLayout.Content>
|
|
</AdminLayout>
|
|
</AdminLayout>
|
|
);
|
|
}
|