feat: 完善后台信任内容工作台
This commit is contained in:
1 parent
24ab55c0d0
commit
ecda0d0b00
1 file changed
+80
-47
@@ -15,8 +15,18 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { TrustContent, TrustContentInput } from "@personal-brand/api-client";
|
||||
import { useState } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
|
||||
const types = [
|
||||
{ value: "profile", label: "个人经历" },
|
||||
{ value: "experience", label: "工作经验" },
|
||||
{ value: "credential", label: "资历与证明" },
|
||||
{ value: "portfolio", label: "案例与作品" },
|
||||
{ value: "process", label: "合作流程" },
|
||||
{ value: "testimonial", label: "客户反馈" },
|
||||
];
|
||||
|
||||
const types = ["profile", "experience", "credential", "portfolio", "process", "testimonial"];
|
||||
export function TrustContentPage() {
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -57,49 +67,67 @@ export function TrustContentPage() {
|
||||
title: item.title,
|
||||
summary: item.summary ?? undefined,
|
||||
content: item.content,
|
||||
coverUrl: item.coverUrl ?? undefined,
|
||||
isPublished: item.isPublished,
|
||||
}
|
||||
: { type: "profile", isPublished: true },
|
||||
: { type: "profile", isPublished: false },
|
||||
);
|
||||
};
|
||||
return (
|
||||
<Card
|
||||
title="信任内容"
|
||||
extra={
|
||||
<Button type="primary" onClick={() => begin()}>
|
||||
新增内容
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={query.isLoading}
|
||||
dataSource={query.data ?? []}
|
||||
columns={[
|
||||
{ title: "类型", dataIndex: "type", render: (value) => <Tag>{value}</Tag> },
|
||||
{ title: "标题", dataIndex: "title" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "isPublished",
|
||||
render: (value) => (value ? "已发布" : "草稿"),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: TrustContent) => (
|
||||
<Space>
|
||||
<Button size="small" onClick={() => begin(item)}>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm title="确认删除?" onConfirm={() => remove.mutate(item.id)}>
|
||||
<Button size="small" danger>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
<QueryState loading={query.isLoading} error={query.error} onRetry={() => void query.refetch()}>
|
||||
<AdminPageHeader
|
||||
title="信任内容"
|
||||
description="用经历、案例、资历、流程和反馈,让访客知道为什么可以信任你。"
|
||||
extra={
|
||||
<Button type="primary" onClick={() => begin()}>
|
||||
新增信任内容
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<Card>
|
||||
<Table
|
||||
rowKey="id"
|
||||
dataSource={query.data ?? []}
|
||||
columns={[
|
||||
{
|
||||
title: "证据类型",
|
||||
dataIndex: "type",
|
||||
render: (value) => (
|
||||
<Tag>{types.find((item) => item.value === value)?.label ?? value}</Tag>
|
||||
),
|
||||
},
|
||||
{ title: "标题", dataIndex: "title" },
|
||||
{ title: "摘要", dataIndex: "summary", render: (value) => value || "未填写" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "isPublished",
|
||||
render: (value) => (
|
||||
<Tag color={value ? "success" : "default"}>{value ? "已公开" : "草稿"}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: TrustContent) => (
|
||||
<Space>
|
||||
<Button size="small" onClick={() => begin(item)}>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确认删除这条信任内容?"
|
||||
description="删除后小程序将不再展示。"
|
||||
onConfirm={() => remove.mutate(item.id)}
|
||||
>
|
||||
<Button size="small" danger loading={remove.isPending}>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<MutationError error={remove.error} />
|
||||
</Card>
|
||||
<Modal
|
||||
open={open}
|
||||
title={editing ? "编辑信任内容" : "新增信任内容"}
|
||||
@@ -110,30 +138,35 @@ export function TrustContentPage() {
|
||||
}}
|
||||
onOk={() => form.submit()}
|
||||
confirmLoading={save.isPending}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form form={form} layout="vertical" onFinish={(values) => save.mutate(values)}>
|
||||
<Form.Item name="type" label="内容类型" rules={[{ required: true }]}>
|
||||
<Select options={types.map((value) => ({ value, label: value }))} />
|
||||
<Form.Item name="type" label="证据类型" rules={[{ required: true }]}>
|
||||
<Select options={types} />
|
||||
</Form.Item>
|
||||
<Form.Item name="title" label="标题" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
<Input placeholder="例如:服务过 30+ 位独立创作者" />
|
||||
</Form.Item>
|
||||
<Form.Item name="summary" label="摘要">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="content" label="内容" rules={[{ required: true }]}>
|
||||
<Input.TextArea rows={7} />
|
||||
<Form.Item name="content" label="详细内容" rules={[{ required: true }]}>
|
||||
<Input.TextArea rows={8} showCount maxLength={2000} />
|
||||
</Form.Item>
|
||||
<Form.Item name="isPublished" label="发布状态">
|
||||
<Form.Item name="coverUrl" label="封面图片 URL">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="isPublished" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "已发布" },
|
||||
{ value: false, label: "草稿" },
|
||||
{ value: true, label: "立即公开" },
|
||||
{ value: false, label: "保存为草稿" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<MutationError error={save.error} />
|
||||
</Form>
|
||||
</Modal>
|
||||
</Card>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user