feat: 重构业务提供项管理工作台

This commit is contained in:
que01 committed 2026-09-20 17:16:01 +08:00
1 parent ecda0d0b00
commit 07866f48d0
1 file changed
+70 -42
@@ -8,6 +8,7 @@ import {
Space, Space,
Table, Table,
Tag, Tag,
Typography,
message, message,
Divider, Divider,
} from "antd"; } from "antd";
@@ -15,6 +16,8 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type { Offering, PublicService } from "@personal-brand/api-client"; import type { Offering, PublicService } from "@personal-brand/api-client";
import { useState } from "react"; import { useState } from "react";
import { createApiClient } from "../../lib/api.js"; import { createApiClient } from "../../lib/api.js";
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
import { MutationError, QueryState } from "../../components/QueryState.js";
export function ServicesPage() { export function ServicesPage() {
const client = createApiClient(); const client = createApiClient();
@@ -90,58 +93,46 @@ export function ServicesPage() {
); );
}; };
return ( return (
<Card <QueryState
title="服务与合作" loading={query.isLoading || offerings.isLoading}
extra={ error={query.error ?? offerings.error}
<Button type="primary" onClick={() => begin()}> onRetry={() => {
新增服务 void query.refetch();
</Button> void offerings.refetch();
} }}
> >
<Table <AdminPageHeader
rowKey="id" title="业务提供项"
loading={query.isLoading} description="管理你向外提供的服务、产品、套餐和合作项目,让访客清楚知道如何与你合作。"
dataSource={query.data ?? []}
columns={[
{ title: "服务名称", dataIndex: "name" },
{ title: "分类", dataIndex: "categoryKey", render: (value) => <Tag>{value}</Tag> },
{ title: "价格展示", dataIndex: "priceText" },
{
title: "状态",
dataIndex: "isEnabled",
render: (value) => (value ? "已上架" : "已下架"),
},
{
title: "操作",
render: (_: unknown, item: PublicService) => (
<Space>
<Button size="small" onClick={() => begin(item)}>
编辑
</Button>
<Button size="small" onClick={() => toggle.mutate(item)}>
{item.isEnabled ? "下架" : "上架"}
</Button>
</Space>
),
},
]}
/>
<Divider orientation="left">通用业务提供项</Divider>
<Card
size="small"
extra={ extra={
<Button type="primary" onClick={() => beginOffering()}> <Button type="primary" onClick={() => beginOffering()}>
新增提供项 新增业务提供项
</Button> </Button>
} }
> />
<Card title="公开业务提供项" extra={<Tag color="blue">小程序优先展示</Tag>}>
<Table <Table
rowKey="id" rowKey="id"
loading={offerings.isLoading} loading={offerings.isLoading}
dataSource={offerings.data ?? []} dataSource={offerings.data ?? []}
columns={[ columns={[
{ title: "名称", dataIndex: "name" }, { title: "名称", dataIndex: "name" },
{ title: "类型", dataIndex: "kind", render: (value) => <Tag>{value}</Tag> }, {
title: "业务类型",
dataIndex: "kind",
render: (value) => (
<Tag>
{(
{
service: "服务",
product: "定制产品",
package: "套餐",
subscription: "订阅",
} as Record<string, string>
)[value] ?? value}
</Tag>
),
},
{ title: "价格", dataIndex: "priceText" }, { title: "价格", dataIndex: "priceText" },
{ {
title: "状态", title: "状态",
@@ -158,6 +149,43 @@ export function ServicesPage() {
}, },
]} ]}
/> />
{offerings.data?.length === 0 && (
<Typography.Paragraph type="secondary">
还没有公开业务提供项。创建后,小程序服务页会优先读取这些内容。
</Typography.Paragraph>
)}
<Divider orientation="left">兼容旧版服务</Divider>
<Table
rowKey="id"
size="small"
dataSource={query.data ?? []}
pagination={false}
columns={[
{ title: "名称", dataIndex: "name" },
{ title: "分类", dataIndex: "categoryKey" },
{
title: "状态",
dataIndex: "isEnabled",
render: (value) => (value ? "已公开" : "已下架"),
},
{
title: "操作",
render: (_: unknown, item: PublicService) => (
<Space>
<Button size="small" onClick={() => begin(item)}>
编辑
</Button>
<Button size="small" onClick={() => toggle.mutate(item)}>
{item.isEnabled ? "下架" : "上架"}
</Button>
</Space>
),
},
]}
/>
<MutationError error={saveOffering.error} />
<MutationError error={save.error} />
<MutationError error={toggle.error} />
</Card> </Card>
<Modal <Modal
open={offeringOpen} open={offeringOpen}
@@ -330,6 +358,6 @@ export function ServicesPage() {
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>
</Card> </QueryState>
); );
} }