196 lines
7.1 KiB
TypeScript
196 lines
7.1 KiB
TypeScript
import { Button, Card, Col, List, Progress, Row, Space, Statistic, Tag, Typography } from "antd";
|
|
import { useQueries, useQuery } from "@tanstack/react-query";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { createApiClient } from "../../lib/api.js";
|
|
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
|
import { QueryState } from "../../components/QueryState.js";
|
|
|
|
export function OverviewPage() {
|
|
const navigate = useNavigate();
|
|
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 readiness = useQuery({
|
|
queryKey: ["admin-overview-readiness"],
|
|
queryFn: () => client.getAdminReleaseReadiness(),
|
|
});
|
|
const loading = results.some((result) => result.isLoading);
|
|
const error = results.find((result) => result.isError)?.error ?? readiness.error;
|
|
const retry = () => {
|
|
results.forEach((result) => void result.refetch());
|
|
void readiness.refetch();
|
|
};
|
|
const brand = results[0].data;
|
|
const workspace = results[1].data as
|
|
| {
|
|
inquiryForm?: { isEnabled?: boolean };
|
|
templateContent?: { displayName?: string } | null;
|
|
}
|
|
| undefined;
|
|
const trust = results[2].data;
|
|
const offerings = results[3].data as Array<{ isEnabled?: boolean }> | undefined;
|
|
const submissions = results[4].data;
|
|
const checklist = [
|
|
{ label: "品牌定位已填写", done: Boolean(brand?.name && brand.tagline), path: "/admin/brand" },
|
|
{
|
|
label: "信任内容已发布",
|
|
done: Boolean(trust?.some((item) => item.isPublished)),
|
|
path: "/admin/trust",
|
|
},
|
|
{
|
|
label: "至少有一个公开业务提供项",
|
|
done: Boolean(offerings?.some((item) => item.isEnabled)),
|
|
path: "/admin/services",
|
|
},
|
|
{
|
|
label: "咨询入口已配置",
|
|
done: Boolean(workspace?.inquiryForm?.isEnabled),
|
|
path: "/admin/workspace",
|
|
},
|
|
];
|
|
const readinessChecks = readiness.data?.checks ?? [];
|
|
const checks = readinessChecks.length
|
|
? readinessChecks.map((check) => ({
|
|
key: check.key,
|
|
label: check.label,
|
|
passed: check.passed,
|
|
destination: check.destination,
|
|
}))
|
|
: checklist.map((check) => ({
|
|
key: check.path,
|
|
label: check.label,
|
|
passed: check.done,
|
|
destination: check.path,
|
|
}));
|
|
const incompleteChecks = checks.filter((check) => !check.passed);
|
|
const completionPercent = checks.length
|
|
? Math.round((checks.filter((check) => check.passed).length / checks.length) * 100)
|
|
: 0;
|
|
return (
|
|
<QueryState loading={loading || readiness.isLoading} 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">
|
|
当前模板:{workspace?.templateContent?.displayName ?? "尚未安装模板"}
|
|
</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>
|
|
</Row>
|
|
<Row gutter={[16, 16]}>
|
|
<Col xs={24} lg={12}>
|
|
<Card
|
|
title="发布准备度"
|
|
extra={
|
|
<Button type="link" onClick={() => navigate("/admin/publication")}>
|
|
查看发布页
|
|
</Button>
|
|
}
|
|
>
|
|
<Progress
|
|
percent={completionPercent}
|
|
status={readiness.data?.ready ? "success" : "active"}
|
|
/>
|
|
<Typography.Paragraph type="secondary">
|
|
{readiness.data?.ready
|
|
? "当前草稿已满足发布条件,可以进入发布页上线。"
|
|
: `还有 ${incompleteChecks.length} 项需要完善,完成后才能发布。`}
|
|
</Typography.Paragraph>
|
|
{incompleteChecks.length > 0 && (
|
|
<List
|
|
size="small"
|
|
dataSource={incompleteChecks.slice(0, 4)}
|
|
renderItem={(item) => (
|
|
<List.Item
|
|
actions={[
|
|
<Button
|
|
key={item.key}
|
|
type="link"
|
|
size="small"
|
|
onClick={() => navigate(item.destination ?? "/admin/publication")}
|
|
>
|
|
去处理
|
|
</Button>,
|
|
]}
|
|
>
|
|
{item.label}
|
|
</List.Item>
|
|
)}
|
|
/>
|
|
)}
|
|
</Card>
|
|
</Col>
|
|
<Col xs={24} lg={12}>
|
|
<Card title="品牌内容检查">
|
|
<List
|
|
dataSource={checks}
|
|
renderItem={(item) => (
|
|
<List.Item>
|
|
<Space>
|
|
<Tag color={item.passed ? "success" : "default"}>
|
|
{item.passed ? "已完成" : "待完善"}
|
|
</Tag>
|
|
<span>{item.label}</span>
|
|
{!item.passed && (
|
|
<Button
|
|
type="link"
|
|
size="small"
|
|
onClick={() => navigate(item.destination ?? "/admin/publication")}
|
|
>
|
|
去处理
|
|
</Button>
|
|
)}
|
|
</Space>
|
|
</List.Item>
|
|
)}
|
|
/>
|
|
</Card>
|
|
</Col>
|
|
</Row>
|
|
</Space>
|
|
</QueryState>
|
|
);
|
|
}
|