fix: 收敛模板编辑发布契约并还原餐饮页面视觉
This commit is contained in:
1 parent
20bcb43534
commit
f4061a24bd
102 files changed
+4510
-870
No files matched your search
@@ -33,7 +33,7 @@ export function BrandPage() {
|
||||
{!brand.data ? null : (
|
||||
<>
|
||||
<AdminPageHeader
|
||||
title="品牌表达"
|
||||
title="品牌资料"
|
||||
description="先让访客理解你是谁、服务谁,以及为什么值得信任。"
|
||||
extra={<Tag color="blue">{template.data?.name ?? "当前模板"}</Tag>}
|
||||
/>
|
||||
@@ -152,7 +152,9 @@ export function BrandPage() {
|
||||
</Col>
|
||||
<Col xs={24} xl={9}>
|
||||
<Card title="公开表达预览" style={{ position: "sticky", top: 24 }}>
|
||||
<Typography.Text type="secondary">小程序首页将优先使用以下信息</Typography.Text>
|
||||
<Typography.Text type="secondary">
|
||||
这些资料会用于小程序首页和联系区域
|
||||
</Typography.Text>
|
||||
<Typography.Title level={3}>{brand.data.name || "品牌名称"}</Typography.Title>
|
||||
<Typography.Title level={5}>{brand.data.tagline || "一句话定位"}</Typography.Title>
|
||||
<Typography.Paragraph>
|
||||
|
||||
@@ -2,17 +2,23 @@ import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Divider,
|
||||
Col,
|
||||
Form,
|
||||
Grid,
|
||||
Input,
|
||||
InputNumber,
|
||||
Row,
|
||||
Select,
|
||||
Segmented,
|
||||
Space,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
@@ -46,6 +52,22 @@ function renderField(field: TemplateAdminField) {
|
||||
return <ImageUrlField {...(field.placeholder ? { placeholder: field.placeholder } : {})} />;
|
||||
if (field.input === "number")
|
||||
return <InputNumber style={{ width: "100%" }} placeholder={field.placeholder} />;
|
||||
if (field.input === "boolean")
|
||||
return (
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "是" },
|
||||
{ value: false, label: "否" },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
if (field.input === "select" || field.input === "multi-select")
|
||||
return (
|
||||
<Select
|
||||
{...(field.input === "multi-select" ? { mode: "multiple" as const } : {})}
|
||||
options={field.options ?? []}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<Input
|
||||
type={field.input === "phone" ? "tel" : "text"}
|
||||
@@ -63,15 +85,88 @@ export function PresentationEditor({
|
||||
}: PresentationEditorProps) {
|
||||
const [form] = Form.useForm<PresentationValues>();
|
||||
const queryClient = useQueryClient();
|
||||
const sections = useMemo(
|
||||
() =>
|
||||
(templateContent?.admin.sections ?? [])
|
||||
.map((section) => ({
|
||||
...section,
|
||||
fields: section.fields.filter((field) => field.binding.startsWith("brand.config.")),
|
||||
}))
|
||||
.filter((section) => section.fields.length > 0),
|
||||
[templateContent],
|
||||
const navigate = useNavigate();
|
||||
const breakpoints = Grid.useBreakpoint();
|
||||
const [activePage, setActivePage] = useState<string>();
|
||||
const sections = useMemo(() => {
|
||||
const declaredTemplateFields = (templateContent?.templateFields ?? []).map((field) => ({
|
||||
...field,
|
||||
binding: field.binding ?? `brand.config.templateData.${field.key}`,
|
||||
}));
|
||||
return [
|
||||
...(declaredTemplateFields.length
|
||||
? [
|
||||
{
|
||||
key: "template-data",
|
||||
title: "模板专属内容",
|
||||
description: "这些字段由当前小程序模板定义,保存后发布才会对外展示。",
|
||||
page: templateContent?.templateFields?.[0]?.page ?? "home",
|
||||
target: "brand" as const,
|
||||
fields: declaredTemplateFields,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(templateContent?.admin.sections ?? []),
|
||||
]
|
||||
.map((section) => ({
|
||||
...section,
|
||||
fields: section.fields.filter(
|
||||
(field) =>
|
||||
field.binding.startsWith("brand.config.") ||
|
||||
[
|
||||
"brand.avatarUrl",
|
||||
"brand.description",
|
||||
"brand.contactPhone",
|
||||
"brand.contactWechat",
|
||||
"brand.address",
|
||||
].includes(field.binding),
|
||||
),
|
||||
}))
|
||||
.filter((section) => section.fields.length > 0);
|
||||
}, [templateContent]);
|
||||
const pageOptions = useMemo(() => {
|
||||
const pages = new Map<string, string>();
|
||||
for (const item of templateContent?.navigation ?? []) pages.set(item.page, item.label);
|
||||
for (const section of templateContent?.admin.sections ?? []) {
|
||||
const navigation = templateContent?.navigation.find((item) => item.page === section.page);
|
||||
if (!pages.has(section.page))
|
||||
pages.set(section.page, navigation?.label ?? pageTitle(section.page));
|
||||
}
|
||||
return [...pages].map(([value, label]) => ({ value, label }));
|
||||
}, [templateContent]);
|
||||
const selectedPage = pageOptions.some((item) => item.value === activePage)
|
||||
? activePage
|
||||
: pageOptions[0]?.value;
|
||||
const visibleSections = sections.filter((section) => section.page === selectedPage);
|
||||
const relatedTargets = [
|
||||
...(templateContent?.admin.sections ?? [])
|
||||
.filter((section) => section.page === selectedPage && section.target !== "brand")
|
||||
.map((section) => section.target),
|
||||
...((templateContent?.trustContentTypes ?? []).some((item) =>
|
||||
item.pages?.includes(selectedPage ?? ""),
|
||||
)
|
||||
? ["trust"]
|
||||
: []),
|
||||
];
|
||||
const pageLinks = [...new Set(relatedTargets)].flatMap((target) =>
|
||||
target === "trust"
|
||||
? (templateContent?.trustContentTypes ?? [])
|
||||
.filter((item) => item.pages?.includes(selectedPage ?? ""))
|
||||
.map((item) => ({
|
||||
target: `trust:${item.type}`,
|
||||
label: `编辑${item.label}`,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
target,
|
||||
label: (
|
||||
{ offering: "管理此页展示的业务内容", inquiry: "管理此页的咨询表单" } as Record<
|
||||
string,
|
||||
string
|
||||
>
|
||||
)[target],
|
||||
},
|
||||
],
|
||||
);
|
||||
const initialValues = useMemo(() => {
|
||||
const values: PresentationValues = {};
|
||||
@@ -105,10 +200,20 @@ export function PresentationEditor({
|
||||
form.setFieldsValue(initialValues);
|
||||
}, [form, initialValues]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!pageOptions.some((item) => item.value === activePage))
|
||||
setActivePage(pageOptions[0]?.value);
|
||||
}, [activePage, pageOptions]);
|
||||
|
||||
return (
|
||||
<Card title="小程序页面内容" style={{ marginTop: 24 }}>
|
||||
<Card
|
||||
title="小程序页面配置"
|
||||
extra={templateContent ? <Tag color="blue">{templateContent.displayName}</Tag> : null}
|
||||
style={{ marginTop: 32 }}
|
||||
styles={{ body: { minHeight: breakpoints.md ? 760 : 620 } }}
|
||||
>
|
||||
<Typography.Paragraph type="secondary">
|
||||
编辑访客在小程序中看到的文字和图片。不同模板会提供适合本行业的内容项目。
|
||||
按小程序页面查找内容。这里修改的是草稿,发布后访客才会看到更新。
|
||||
</Typography.Paragraph>
|
||||
{loading ? <Alert type="info" showIcon message="正在读取当前模板的编辑项目" /> : null}
|
||||
{error ? (
|
||||
@@ -119,51 +224,108 @@ export function PresentationEditor({
|
||||
) : null}
|
||||
{templateContent ? (
|
||||
<>
|
||||
<Typography.Title level={5}>{templateContent.displayName}</Typography.Title>
|
||||
<Space wrap style={{ marginBottom: 24 }}>
|
||||
{breakpoints.xs ? (
|
||||
<Select
|
||||
aria-label="选择小程序页面"
|
||||
value={selectedPage}
|
||||
options={pageOptions}
|
||||
onChange={setActivePage}
|
||||
style={{ minWidth: 180 }}
|
||||
/>
|
||||
) : (
|
||||
<Segmented
|
||||
value={selectedPage}
|
||||
options={pageOptions}
|
||||
onChange={(value) => setActivePage(String(value))}
|
||||
/>
|
||||
)}
|
||||
</Space>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
{sections.map((section) => (
|
||||
<Card
|
||||
key={section.key}
|
||||
size="small"
|
||||
title={section.title}
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col
|
||||
key={field.key}
|
||||
xs={24}
|
||||
md={field.input === "textarea" || field.input === "list" ? 24 : 12}
|
||||
>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
/>
|
||||
) : (
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
label={field.label}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? { rules: [{ required: true, message: `请填写${field.label}` }] }
|
||||
: {})}
|
||||
<div style={{ flex: 1 }}>
|
||||
{visibleSections.map((section, index) => (
|
||||
<section key={section.key} aria-labelledby={`section-${section.key}`}>
|
||||
{index > 0 ? <Divider /> : null}
|
||||
<Typography.Title id={`section-${section.key}`} level={5}>
|
||||
{section.title}
|
||||
</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
{section.description}
|
||||
</Typography.Paragraph>
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col
|
||||
key={field.key}
|
||||
xs={24}
|
||||
md={field.input === "textarea" || field.input === "list" ? 24 : 12}
|
||||
>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
/>
|
||||
) : (
|
||||
<Form.Item
|
||||
name={presentationFieldName(section.key, field.key)}
|
||||
label={field.label}
|
||||
{...(field.help ? { help: field.help } : {})}
|
||||
{...(field.required
|
||||
? { rules: [{ required: true, message: `请填写${field.label}` }] }
|
||||
: {})}
|
||||
>
|
||||
{renderField(field)}
|
||||
</Form.Item>
|
||||
)}
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</section>
|
||||
))}
|
||||
{pageLinks.length ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 24 }}
|
||||
message="这个页面还有关联内容"
|
||||
description={
|
||||
<Space wrap>
|
||||
{pageLinks.map((item) => (
|
||||
<Button
|
||||
key={item.target}
|
||||
type="link"
|
||||
onClick={() => {
|
||||
if (item.target.startsWith("trust:")) {
|
||||
void navigate(
|
||||
`/admin/trust?type=${encodeURIComponent(item.target.slice(6))}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
void navigate(
|
||||
item.target === "offering" ? "/admin/services" : "/admin/workspace",
|
||||
);
|
||||
}}
|
||||
style={{ padding: 0 }}
|
||||
>
|
||||
{renderField(field)}
|
||||
</Form.Item>
|
||||
)}
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</Card>
|
||||
))}
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{!visibleSections.length && !pageLinks.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
这个页面没有单独的品牌文案配置。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
</div>
|
||||
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||||
<MutationError error={save.error} />
|
||||
<Button type="primary" htmlType="submit" loading={save.isPending}>
|
||||
保存页面内容
|
||||
@@ -175,3 +337,20 @@ export function PresentationEditor({
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function pageTitle(page: string): string {
|
||||
return (
|
||||
(
|
||||
{
|
||||
home: "首页",
|
||||
offerings: "业务展示",
|
||||
service: "服务说明",
|
||||
detail: "详情页",
|
||||
inquiry: "咨询页",
|
||||
success: "提交成功页",
|
||||
records: "记录页",
|
||||
profile: "主理人页",
|
||||
} as Record<string, string>
|
||||
)[page] ?? page
|
||||
);
|
||||
}
|
||||
@@ -48,7 +48,10 @@ export function readPresentationValue(
|
||||
? (value as unknown[]).map((item) => ({ [field.itemValueKey as string]: item }))
|
||||
: value;
|
||||
}
|
||||
return typeof value === "string" || typeof value === "number" ? value : undefined;
|
||||
if (field?.input === "multi-select") return Array.isArray(value) ? value : [];
|
||||
return typeof value === "string" || typeof value === "number" || typeof value === "boolean"
|
||||
? value
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function writePath(
|
||||
|
||||
@@ -98,7 +98,7 @@ export function OverviewPage() {
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="信任内容"
|
||||
title="信任证明"
|
||||
value={trust?.filter((item) => item.isPublished).length ?? 0}
|
||||
suffix="条已发布"
|
||||
/>
|
||||
@@ -107,7 +107,7 @@ export function OverviewPage() {
|
||||
<Col xs={24} sm={12} lg={6}>
|
||||
<Card>
|
||||
<Statistic
|
||||
title="业务提供项"
|
||||
title="业务展示内容"
|
||||
value={offerings?.filter((item) => item.isEnabled).length ?? 0}
|
||||
suffix="项公开"
|
||||
/>
|
||||
|
||||
@@ -98,8 +98,12 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
});
|
||||
const importSample = useMutation({
|
||||
mutationFn: () => client.importAdminSampleContent(),
|
||||
onSuccess: () => {
|
||||
message.success("示例内容已导入草稿");
|
||||
onSuccess: ({ counts }) => {
|
||||
message.success(
|
||||
counts.inquiryForms
|
||||
? "示例内容和客户咨询表单已导入草稿"
|
||||
: "示例内容已导入草稿,现有客户咨询表单已保留",
|
||||
);
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
@@ -259,9 +263,9 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
.join("、") || "无"}
|
||||
</Typography.Text>
|
||||
<Space wrap>
|
||||
<Button onClick={() => navigate("/admin/brand")}>编辑品牌</Button>
|
||||
<Button onClick={() => navigate("/admin/services")}>编辑业务项</Button>
|
||||
<Button onClick={() => navigate("/admin/trust")}>编辑信任内容</Button>
|
||||
<Button onClick={() => navigate("/admin/brand")}>编辑小程序页面</Button>
|
||||
<Button onClick={() => navigate("/admin/services")}>编辑业务展示和详情</Button>
|
||||
<Button onClick={() => navigate("/admin/trust")}>编辑信任证明</Button>
|
||||
</Space>
|
||||
</Space>
|
||||
</section>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
@@ -47,6 +46,18 @@ export function ServicesPage() {
|
||||
.flatMap((section) =>
|
||||
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
|
||||
);
|
||||
const offeringPageLabel =
|
||||
workspace.data?.templateContent?.navigation.find((item) => item.page === "offerings")?.label ??
|
||||
"业务展示页";
|
||||
const detailPageLabel =
|
||||
workspace.data?.templateContent?.navigation.find((item) => item.page === "detail")?.label ??
|
||||
"详情页";
|
||||
const detailSections = (workspace.data?.templateContent?.admin.sections ?? []).filter(
|
||||
(section) => section.target === "offering" && section.page === "detail",
|
||||
);
|
||||
const hasTemplateDetailCopy = templateFields.some(
|
||||
(field) => field.binding === "offering.config.details.background",
|
||||
);
|
||||
const saveOffering = useMutation({
|
||||
mutationFn: (values: Record<string, unknown>) => {
|
||||
const fields = Object.fromEntries(
|
||||
@@ -129,15 +140,28 @@ export function ServicesPage() {
|
||||
}}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="业务提供项"
|
||||
description="管理你向外提供的服务、产品、套餐和合作项目,让访客清楚知道如何与你合作。"
|
||||
title="小程序内容:业务展示与详情"
|
||||
description={`在「${offeringPageLabel}」管理访客能选择的服务、产品或案例;每项内容的补充资料会显示在对应的「${detailPageLabel}」。`}
|
||||
extra={
|
||||
<Button type="primary" onClick={() => beginOffering()}>
|
||||
新增业务提供项
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<Card title="公开业务提供项" extra={<Tag color="blue">小程序优先展示</Tag>}>
|
||||
<section aria-label="业务提供项列表">
|
||||
<Space wrap style={{ marginBottom: 16 }}>
|
||||
<Typography.Title level={5} style={{ margin: 0 }}>
|
||||
{offeringPageLabel}中的内容
|
||||
</Typography.Title>
|
||||
<Tag color="blue">已启用的项目会公开展示</Tag>
|
||||
</Space>
|
||||
{detailSections.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
编辑单项详情时,附加字段将用于:
|
||||
{detailSections.map((section) => section.title).join("、")}
|
||||
。列表中的名称、说明、价格和封面也会显示在业务展示页。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<Table
|
||||
scroll={{ x: 760 }}
|
||||
rowKey="id"
|
||||
@@ -211,7 +235,7 @@ export function ServicesPage() {
|
||||
<MutationError error={saveOffering.error} />
|
||||
<MutationError error={toggleOffering.error} />
|
||||
<MutationError error={deleteOffering.error} />
|
||||
</Card>
|
||||
</section>
|
||||
<Modal
|
||||
open={offeringOpen}
|
||||
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
||||
@@ -244,9 +268,11 @@ export function ServicesPage() {
|
||||
<Form.Item name="summary" label="一句话说明">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="description" label="详细介绍">
|
||||
<Input.TextArea rows={5} />
|
||||
</Form.Item>
|
||||
{!hasTemplateDetailCopy ? (
|
||||
<Form.Item name="description" label="详细介绍">
|
||||
<Input.TextArea rows={5} />
|
||||
</Form.Item>
|
||||
) : null}
|
||||
<Form.Item name="priceText" label="价格展示">
|
||||
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
||||
</Form.Item>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Divider,
|
||||
Form,
|
||||
Input,
|
||||
List,
|
||||
@@ -14,12 +14,14 @@ import {
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { isTrustContentComplete } from "@personal-brand/api-client";
|
||||
import type {
|
||||
TemplateAdminField,
|
||||
TrustContent,
|
||||
TrustContentInput,
|
||||
} from "@personal-brand/api-client";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
@@ -61,14 +63,25 @@ const types = [
|
||||
type TrustTypeOption = {
|
||||
type: string;
|
||||
label: string;
|
||||
adminFields: {
|
||||
title: string;
|
||||
summary: string;
|
||||
content: string;
|
||||
summaryHelp?: string;
|
||||
summaryPlaceholder?: string;
|
||||
};
|
||||
pages?: string[];
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
configFields?: TemplateAdminField[];
|
||||
hideStandardFields?: Array<"summary" | "content">;
|
||||
maxPublishedItems?: number;
|
||||
};
|
||||
const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({
|
||||
type: value,
|
||||
label,
|
||||
adminFields: { title: "标题", summary: "摘要", content: "详细内容" },
|
||||
help,
|
||||
}));
|
||||
|
||||
@@ -78,6 +91,7 @@ export function TrustContentPage() {
|
||||
const [editing, setEditing] = useState<TrustContent | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form] = Form.useForm<TrustContentInput>();
|
||||
const [searchParams] = useSearchParams();
|
||||
const selectedType = Form.useWatch("type", form);
|
||||
const query = useQuery({
|
||||
queryKey: ["trust-content"],
|
||||
@@ -91,6 +105,21 @@ export function TrustContentPage() {
|
||||
?.length
|
||||
? workspace.data.templateContent.trustContentTypes
|
||||
: fallbackTypes;
|
||||
const pageLabel = (page: string) =>
|
||||
workspace.data?.templateContent?.navigation.find((item) => item.page === page)?.label ??
|
||||
(
|
||||
{ home: "首页", offerings: "业务展示页", detail: "详情页", profile: "主理人页" } as Record<
|
||||
string,
|
||||
string
|
||||
>
|
||||
)[page] ??
|
||||
page;
|
||||
const trustPageLabels = [
|
||||
...new Set(availableTypes.flatMap((item) => item.pages ?? []).map(pageLabel)),
|
||||
];
|
||||
const trustPlacement = trustPageLabels.length
|
||||
? `小程序的${trustPageLabels.join("、")}中`
|
||||
: "小程序对应的信任展示区域中";
|
||||
const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType);
|
||||
const contentByType = new Map<string, TrustContent>();
|
||||
for (const item of query.data ?? []) {
|
||||
@@ -109,13 +138,14 @@ export function TrustContentPage() {
|
||||
availableTypes.find((item) => item.required && !contentByType.has(item.type))?.type ??
|
||||
availableTypes[0]?.type ??
|
||||
"credential";
|
||||
const requestedType = searchParams.get("type");
|
||||
const save = useMutation({
|
||||
mutationFn: (values: TrustContentInput) =>
|
||||
editing
|
||||
? client.updateAdminTrustContent(editing.id, values)
|
||||
: client.createAdminTrustContent(values),
|
||||
onSuccess: () => {
|
||||
message.success("信任内容已保存");
|
||||
message.success("品牌内容已保存为草稿,发布后小程序才会更新");
|
||||
setOpen(false);
|
||||
setEditing(null);
|
||||
form.resetFields();
|
||||
@@ -125,7 +155,7 @@ export function TrustContentPage() {
|
||||
const remove = useMutation({
|
||||
mutationFn: (id: string) => client.deleteAdminTrustContent(id),
|
||||
onSuccess: () => {
|
||||
message.success("内容已删除");
|
||||
message.success("品牌内容已删除");
|
||||
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
|
||||
},
|
||||
});
|
||||
@@ -146,6 +176,10 @@ export function TrustContentPage() {
|
||||
: { type: type ?? firstMissingRequiredType, isPublished: false, config: {} },
|
||||
);
|
||||
};
|
||||
useEffect(() => {
|
||||
if (!requestedType || !availableTypes.some((item) => item.type === requestedType)) return;
|
||||
begin(contentByType.get(requestedType), requestedType);
|
||||
}, [requestedType, availableTypes.length]);
|
||||
return (
|
||||
<QueryState
|
||||
loading={query.isLoading || workspace.isLoading}
|
||||
@@ -153,24 +187,32 @@ export function TrustContentPage() {
|
||||
onRetry={() => void Promise.all([query.refetch(), workspace.refetch()])}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="信任内容"
|
||||
description="用经历、案例、资历、流程和反馈,让访客知道为什么可以信任你。"
|
||||
title="小程序内容:品牌介绍与信任"
|
||||
description={`填写真实的经历、案例、资历、流程和服务说明。这些内容会显示在${trustPlacement};保存后需发布品牌,小程序才会更新。`}
|
||||
extra={
|
||||
<Button type="primary" onClick={() => begin()}>
|
||||
新增信任内容
|
||||
添加品牌内容
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<Card title="当前模板需要哪些信任内容?" style={{ marginBottom: 24 }}>
|
||||
<section aria-labelledby="trust-requirements-title">
|
||||
<Typography.Title id="trust-requirements-title" level={5}>
|
||||
当前模板需要配置的内容
|
||||
</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
这些内容会帮助访客判断你是否值得信任。带有“发布必需”的项目需要填写完整后,才能发布小程序。
|
||||
标记为“发布必填”的项目需要填写完整后,才能发布小程序。
|
||||
</Typography.Paragraph>
|
||||
<List
|
||||
size="small"
|
||||
dataSource={availableTypes}
|
||||
renderItem={(item) => {
|
||||
const content = contentByType.get(item.type);
|
||||
const complete = Boolean(content?.title?.trim() && content?.content?.trim());
|
||||
const publishedCount = (query.data ?? []).filter(
|
||||
(record) => record.type === item.type && record.isPublished,
|
||||
).length;
|
||||
const tooMany =
|
||||
item.maxPublishedItems !== undefined && publishedCount > item.maxPublishedItems;
|
||||
const complete = Boolean(content && isTrustContentComplete(content, item) && !tooMany);
|
||||
return (
|
||||
<List.Item
|
||||
actions={[
|
||||
@@ -186,9 +228,18 @@ export function TrustContentPage() {
|
||||
>
|
||||
<Space wrap>
|
||||
<Typography.Text strong>{item.label}</Typography.Text>
|
||||
{item.required && <Tag color="orange">发布必需</Tag>}
|
||||
{item.required && <Tag color="orange">发布必填</Tag>}
|
||||
{(item.pages ?? []).map((page) => (
|
||||
<Tag key={page}>{pageLabel(page)}</Tag>
|
||||
))}
|
||||
<Tag color={complete ? "success" : "default"}>
|
||||
{complete ? "内容完整" : content ? "需要完善" : "尚未填写"}
|
||||
{tooMany
|
||||
? `公开内容过多(${publishedCount} 条)`
|
||||
: complete
|
||||
? "内容完整"
|
||||
: content
|
||||
? "需要完善"
|
||||
: "尚未填写"}
|
||||
</Tag>
|
||||
{item.help && <Typography.Text type="secondary">{item.help}</Typography.Text>}
|
||||
</Space>
|
||||
@@ -196,15 +247,16 @@ export function TrustContentPage() {
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
<Card>
|
||||
</section>
|
||||
<Divider />
|
||||
<section aria-label="已配置的品牌内容">
|
||||
<Table
|
||||
rowKey="id"
|
||||
dataSource={query.data ?? []}
|
||||
locale={{ emptyText: "还没有信任内容,请先按上方模板要求添加。" }}
|
||||
locale={{ emptyText: "还没有品牌内容,请先按上方模板要求添加。" }}
|
||||
columns={[
|
||||
{
|
||||
title: "证据类型",
|
||||
title: "内容类型",
|
||||
dataIndex: "type",
|
||||
render: (value) => (
|
||||
<Tag>{availableTypes.find((item) => item.type === value)?.label ?? value}</Tag>
|
||||
@@ -212,15 +264,32 @@ export function TrustContentPage() {
|
||||
},
|
||||
{ title: "标题", dataIndex: "title" },
|
||||
{
|
||||
title: "摘要",
|
||||
dataIndex: "summary",
|
||||
render: (value) => (typeof value === "string" && value ? value : "未填写"),
|
||||
title: "内容预览",
|
||||
ellipsis: { showTitle: true },
|
||||
render: (_value: unknown, item: TrustContent) => {
|
||||
const meta = availableTypes.find((type) => type.type === item.type);
|
||||
if (meta?.hideStandardFields?.includes("content")) {
|
||||
return (
|
||||
meta.configFields
|
||||
?.flatMap((field) => {
|
||||
const value = item.config?.[field.key];
|
||||
if (Array.isArray(value))
|
||||
return value.length ? [`${field.label}:${value.length} 项`] : [];
|
||||
return typeof value === "string" && value.trim()
|
||||
? [`${field.label}:${value}`]
|
||||
: [];
|
||||
})
|
||||
.join(";") || "尚未填写区块内容"
|
||||
);
|
||||
}
|
||||
return item.summary || item.content || "未填写";
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "状态",
|
||||
title: "发布状态",
|
||||
dataIndex: "isPublished",
|
||||
render: (value) => (
|
||||
<Tag color={value ? "success" : "default"}>{value ? "已公开" : "草稿"}</Tag>
|
||||
<Tag color={value ? "success" : "default"}>{value ? "随发布展示" : "草稿"}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
@@ -232,7 +301,7 @@ export function TrustContentPage() {
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确认删除这条信任内容?"
|
||||
description="删除后小程序将不再展示。"
|
||||
description="删除后需发布品牌,才会更新小程序展示。"
|
||||
onConfirm={() => remove.mutate(item.id)}
|
||||
>
|
||||
<Button size="small" danger loading={remove.isPending}>
|
||||
@@ -245,10 +314,10 @@ export function TrustContentPage() {
|
||||
]}
|
||||
/>
|
||||
<MutationError error={remove.error} />
|
||||
</Card>
|
||||
</section>
|
||||
<Modal
|
||||
open={open}
|
||||
title={editing ? "编辑信任内容" : "新增信任内容"}
|
||||
title={editing ? "编辑品牌内容" : "添加品牌内容"}
|
||||
onCancel={() => {
|
||||
setOpen(false);
|
||||
setEditing(null);
|
||||
@@ -258,48 +327,70 @@ export function TrustContentPage() {
|
||||
confirmLoading={save.isPending}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form form={form} layout="vertical" onFinish={(values) => save.mutate(values)}>
|
||||
<Form.Item name="type" label="内容用途" rules={[{ required: true }]}>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={(values) => save.mutate({ ...values, content: values.content ?? "" })}
|
||||
>
|
||||
<Form.Item name="type" label="内容类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={availableTypes.map((item) => ({ value: item.type, label: item.label }))}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="title" label="标题" rules={[{ required: true }]}>
|
||||
<Input placeholder="例如:服务过 30+ 位独立创作者" />
|
||||
</Form.Item>
|
||||
<Form.Item name="summary" label="摘要">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
{selectedTypeMeta?.pages?.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
这类内容会显示在:
|
||||
{selectedTypeMeta.pages.map(pageLabel).join("、")}
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<Form.Item
|
||||
name="content"
|
||||
label="详细内容"
|
||||
help={
|
||||
selectedTypeMeta?.help ?? "每行写一项,页面会按模板样式展示。不要填写 HTML 或代码。"
|
||||
}
|
||||
name="title"
|
||||
label={selectedTypeMeta?.adminFields.title ?? "标题"}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={8}
|
||||
showCount
|
||||
maxLength={2000}
|
||||
placeholder={selectedTypeMeta?.placeholder ?? "例如:\n第一项内容\n第二项内容"}
|
||||
/>
|
||||
<Input placeholder="例如:服务过 30+ 位独立创作者" />
|
||||
</Form.Item>
|
||||
{(!editing || contentByType.get(selectedType)?.id === editing.id) &&
|
||||
selectedTypeMeta?.configFields?.map((field) =>
|
||||
field.input === "list" ? (
|
||||
<TemplateListField key={field.key} field={field} name={["config", field.key]} />
|
||||
) : (
|
||||
<Form.Item
|
||||
key={field.key}
|
||||
name={["config", field.key]}
|
||||
label={field.label}
|
||||
help={field.help}
|
||||
>
|
||||
{field.input === "textarea" ? <Input.TextArea rows={3} /> : <Input />}
|
||||
</Form.Item>
|
||||
),
|
||||
)}
|
||||
{!selectedTypeMeta?.hideStandardFields?.includes("summary") && (
|
||||
<Form.Item
|
||||
name="summary"
|
||||
label={selectedTypeMeta?.adminFields.summary ?? "摘要"}
|
||||
help={selectedTypeMeta?.adminFields.summaryHelp}
|
||||
>
|
||||
<Input placeholder={selectedTypeMeta?.adminFields.summaryPlaceholder} />
|
||||
</Form.Item>
|
||||
)}
|
||||
{!selectedTypeMeta?.hideStandardFields?.includes("content") && (
|
||||
<Form.Item
|
||||
name="content"
|
||||
label={selectedTypeMeta?.adminFields.content ?? "详细内容"}
|
||||
help={
|
||||
selectedTypeMeta?.help ?? "每行写一项,页面会按模板样式展示。不要填写 HTML 或代码。"
|
||||
}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={8}
|
||||
showCount
|
||||
maxLength={2000}
|
||||
placeholder={selectedTypeMeta?.placeholder ?? "例如:\n第一项内容\n第二项内容"}
|
||||
/>
|
||||
</Form.Item>
|
||||
)}
|
||||
{selectedTypeMeta?.configFields?.map((field) =>
|
||||
field.input === "list" ? (
|
||||
<TemplateListField key={field.key} field={field} name={["config", field.key]} />
|
||||
) : (
|
||||
<Form.Item
|
||||
key={field.key}
|
||||
name={["config", field.key]}
|
||||
label={field.label}
|
||||
help={field.help}
|
||||
rules={[{ required: field.required === true }]}
|
||||
>
|
||||
{field.input === "textarea" ? <Input.TextArea rows={3} /> : <Input />}
|
||||
</Form.Item>
|
||||
),
|
||||
)}
|
||||
<Form.Item
|
||||
name="coverUrl"
|
||||
label="配图地址"
|
||||
@@ -310,7 +401,7 @@ export function TrustContentPage() {
|
||||
<Form.Item name="isPublished" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "立即公开" },
|
||||
{ value: true, label: "随品牌发布展示" },
|
||||
{ value: false, label: "保存为草稿" },
|
||||
]}
|
||||
/>
|
||||
|
||||
@@ -256,16 +256,16 @@ export function WorkspacePage() {
|
||||
<Space direction="vertical" size="large" style={{ width: "100%" }}>
|
||||
<AdminPageHeader
|
||||
title="模板与表单设置"
|
||||
description="日常内容请从品牌表达、业务提供项和信任内容进入;这里主要管理模板、咨询入口和负责人设置。"
|
||||
description="日常小程序内容请从页面配置、业务展示和信任证明进入;这里主要管理模板、咨询入口和负责人设置。"
|
||||
/>
|
||||
<Card title="先完成日常配置" style={{ marginBottom: 24 }}>
|
||||
<Typography.Paragraph type="secondary">
|
||||
下面这些入口面向日常经营,不需要理解模板或技术设置。完成后回到“配置与发布”统一检查并上线。
|
||||
</Typography.Paragraph>
|
||||
<Space wrap>
|
||||
<Button onClick={() => navigate("/admin/brand")}>完善品牌表达</Button>
|
||||
<Button onClick={() => navigate("/admin/services")}>添加业务提供项</Button>
|
||||
<Button onClick={() => navigate("/admin/trust")}>补充信任内容</Button>
|
||||
<Button onClick={() => navigate("/admin/brand")}>配置小程序页面</Button>
|
||||
<Button onClick={() => navigate("/admin/services")}>添加业务展示内容</Button>
|
||||
<Button onClick={() => navigate("/admin/trust")}>补充信任证明</Button>
|
||||
<Button type="primary" onClick={() => navigate("/admin/publication")}>
|
||||
检查并发布
|
||||
</Button>
|
||||
|
||||
Reference in new issue
Block a user