feat: 重构后台品牌工作台基础骨架

This commit is contained in:
que01 committed 2026-09-20 16:41:57 +08:00
1 parent ac4abc1305
commit e402ba58d9
4 files changed
+209 -5

No files matched your search

@@ -0,0 +1,31 @@
import { Space, Typography } from "antd";
import type { ReactNode } from "react";
export function AdminPageHeader({
title,
description,
extra,
}: {
title: string;
description?: string;
extra?: ReactNode;
}) {
return (
<Space
align="start"
style={{ width: "100%", justifyContent: "space-between", marginBottom: 24 }}
>
<div>
<Typography.Title level={2} style={{ margin: 0 }}>
{title}
</Typography.Title>
{description && (
<Typography.Paragraph type="secondary" style={{ margin: "8px 0 0" }}>
{description}
</Typography.Paragraph>
)}
</div>
{extra}
</Space>
);
}
+47
View File
@@ -0,0 +1,47 @@
import { Alert, Button, Card, Empty, Result, Spin } from "antd";
import type { ReactNode } from "react";
export function QueryState({
loading,
error,
onRetry,
children,
}: {
loading?: boolean;
error?: unknown;
onRetry?: () => void;
children: ReactNode;
}) {
if (loading)
return (
<Card>
<Spin />
</Card>
);
if (error) {
return (
<Result
status="error"
title="内容加载失败"
subTitle={error instanceof Error ? error.message : "请检查 API 服务后重试"}
extra={onRetry ? <Button onClick={onRetry}>重新加载</Button> : undefined}
/>
);
}
return <>{children}</>;
}
export function EmptyState({ description }: { description: string }) {
return <Empty description={description} image={Empty.PRESENTED_IMAGE_SIMPLE} />;
}
export function MutationError({ error }: { error?: unknown }) {
if (!error) return null;
return (
<Alert
type="error"
showIcon
message={error instanceof Error ? error.message : "操作失败,请重试"}
/>
);
}
@@ -0,0 +1,119 @@
import { Card, Col, List, Row, Space, Statistic, Tag, Typography } from "antd";
import { useQueries } from "@tanstack/react-query";
import { createApiClient } from "../../lib/api.js";
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
import { QueryState } from "../../components/QueryState.js";
export function OverviewPage() {
const client = createApiClient();
const results = useQueries({
queries: [
{ queryKey: ["admin-overview-brand"], queryFn: () => client.getAdminBrand() },
{ queryKey: ["admin-overview-workspace"], queryFn: () => client.getAdminWorkspace() },
{ queryKey: ["admin-overview-trust"], queryFn: () => client.listAdminTrustContent() },
{ queryKey: ["admin-overview-offerings"], queryFn: () => client.listAdminOfferings() },
{
queryKey: ["admin-overview-submissions"],
queryFn: () => client.listAdminInquirySubmissions(),
},
],
});
const loading = results.some((result) => result.isLoading);
const error = results.find((result) => result.isError)?.error;
const retry = () => results.forEach((result) => void result.refetch());
const brand = results[0].data;
const workspace = results[1].data;
const trust = results[2].data;
const offerings = results[3].data;
const submissions = results[4].data;
const checklist = [
{ label: "品牌定位已填写", done: Boolean(brand?.name && brand.tagline) },
{ label: "信任内容已发布", done: Boolean(trust?.some((item) => item.isPublished)) },
{ label: "至少有一个公开业务提供项", done: Boolean(offerings?.some((item) => item.isEnabled)) },
{ label: "咨询入口已配置", done: Boolean(workspace?.inquiryForm?.isEnabled) },
];
return (
<QueryState loading={loading} error={error} onRetry={retry}>
<AdminPageHeader
title="品牌概览"
description="从这里检查品牌表达、信任内容和业务承接是否完整。"
/>
<Space direction="vertical" size={24} style={{ width: "100%" }}>
<Card>
<Typography.Title level={3} style={{ marginTop: 0 }}>
{brand?.name || "未命名品牌"}
</Typography.Title>
<Typography.Paragraph type="secondary">
{brand?.tagline || "还没有设置一句话定位"}
</Typography.Paragraph>
<Tag color="blue">
当前模板:{brand?.templateKey === "food" ? "餐饮模板" : "个人品牌"}
</Tag>
</Card>
<Row gutter={[16, 16]}>
<Col xs={24} sm={12} lg={6}>
<Card>
<Statistic
title="信任内容"
value={trust?.filter((item) => item.isPublished).length ?? 0}
suffix="条已发布"
/>
</Card>
</Col>
<Col xs={24} sm={12} lg={6}>
<Card>
<Statistic
title="业务提供项"
value={offerings?.filter((item) => item.isEnabled).length ?? 0}
suffix="项公开"
/>
</Card>
</Col>
<Col xs={24} sm={12} lg={6}>
<Card>
<Statistic title="咨询提交" value={submissions?.length ?? 0} suffix="条" />
</Card>
</Col>
<Col xs={24} sm={12} lg={6}>
<Card>
<Statistic
title="工作空间模块"
value={workspace?.modules.filter((item) => item.isEnabled).length ?? 0}
suffix="个启用"
/>
</Card>
</Col>
</Row>
<Row gutter={[16, 16]}>
<Col xs={24} lg={12}>
<Card title="品牌完整度">
<List
dataSource={checklist}
renderItem={(item) => (
<List.Item>
<Space>
<Tag color={item.done ? "success" : "default"}>
{item.done ? "已完成" : "待完善"}
</Tag>
<span>{item.label}</span>
</Space>
</List.Item>
)}
/>
</Card>
</Col>
<Col xs={24} lg={12}>
<Card title="下一步建议">
<Typography.Paragraph>
先完善品牌定位和信任证明,再配置业务提供项与咨询入口。所有内容发布前都应通过小程序预览确认。
</Typography.Paragraph>
<Typography.Paragraph type="secondary" style={{ marginBottom: 0 }}>
餐饮模板只是业务表达样例,品牌信任主线仍应优先维护。
</Typography.Paragraph>
</Card>
</Col>
</Row>
</Space>
</QueryState>
);
}
+12 -5
View File
@@ -49,6 +49,11 @@ const FeatureWorkspacePage = React.lazy(() =>
default: module.WorkspacePage,
})),
);
const FeatureOverviewPage = React.lazy(() =>
import("./features/overview/OverviewPage.js").then((module) => ({
default: module.OverviewPage,
})),
);
import { BrowserRouter, Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
import type {
BrandProfile,
@@ -96,12 +101,13 @@ function Login({ onLogin }: { onLogin: () => void }) {
function Dashboard({ onLogout }: { onLogout: () => void }) {
const navigate = useNavigate();
const location = useLocation();
const page = location.pathname.split("/")[2] || "brand";
const page = location.pathname.split("/")[2] || "overview";
const items = [
{ key: "brand", label: "品牌信任" },
{ key: "workspace", label: "工作空间" },
{ key: "overview", label: "品牌概览" },
{ key: "brand", label: "品牌表达" },
{ key: "trust", label: "信任内容" },
{ key: "services", label: "服务与合作" },
{ key: "services", label: "业务提供项" },
{ key: "workspace", label: "模板与设置" },
{ key: "inquiries", label: "咨询记录" },
];
return (
@@ -134,12 +140,13 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
<Layout.Content style={{ padding: 24 }}>
<Suspense fallback={<Card loading />}>
<Routes>
<Route path="/admin/overview" element={<FeatureOverviewPage />} />
<Route path="/admin/brand" element={<FeatureBrandPage />} />
<Route path="/admin/workspace" element={<FeatureWorkspacePage />} />
<Route path="/admin/trust" element={<FeatureTrustContentPage />} />
<Route path="/admin/services" element={<FeatureServicesPage />} />
<Route path="/admin/inquiries" element={<FeatureInquiriesPage />} />
<Route path="*" element={<Navigate to="/admin/brand" replace />} />
<Route path="*" element={<Navigate to="/admin/overview" replace />} />
</Routes>
</Suspense>
</Layout.Content>