refactor: 拆分业务、信任内容与公共工作台模块
This commit is contained in:
1 parent
357f271639
commit
466dc66907
33 files changed
+4950
-4500
No files matched your search
@@ -1,128 +1,46 @@
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Popconfirm,
|
||||
Segmented,
|
||||
Select,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type {
|
||||
Offering,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminField,
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
import { useMemo, useState } from "react";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { RecordContentFields } from "../../components/RecordContentEditor.js";
|
||||
import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
||||
import type { PreviewTarget } from "../brand/preview-selection.js";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
} from "../brand/presentation-bindings.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { Button } from "antd";
|
||||
import type { Offering, TemplateAdminField } from "@personal-brand/api-client";
|
||||
import { useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import "./ServicesPage.css";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { QueryState } from "../../components/QueryState.js";
|
||||
import { OfferingEditorModal } from "./OfferingEditorModal.js";
|
||||
import { OfferingsTable } from "./OfferingsTable.js";
|
||||
import { detailPageLabel, hasTemplateDetailCopy, offeringPageLabel } from "./offering-model.js";
|
||||
import { buildOfferingPreviewWorkspace, previewTargetsByPage } from "./offering-preview.js";
|
||||
import { useOfferingEditor } from "./use-offering-editor.js";
|
||||
import { useOfferingMutations, useOfferingQueries } from "./use-offering-data.js";
|
||||
|
||||
type PreviewPage = "offerings" | "detail";
|
||||
|
||||
export function ServicesPage() {
|
||||
const navigate = useNavigate();
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
const [offeringForm] = Form.useForm();
|
||||
const [offeringOpen, setOfferingOpen] = useState(false);
|
||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||
const [offeringDraftVersion, setOfferingDraftVersion] = useState(0);
|
||||
const [previewPage, setPreviewPage] = useState<"offerings" | "detail">("detail");
|
||||
const [formValues, setFormValues] = useState<Record<string, unknown>>({});
|
||||
const offerings = useQuery({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => client.listAdminOfferings(),
|
||||
refetchOnMount: "always",
|
||||
const { offerings, workspace, previewWorkspace, templateFields, retry } = useOfferingQueries();
|
||||
const editor = useOfferingEditor(templateFields);
|
||||
const mutations = useOfferingMutations({
|
||||
editingOffering: editor.editingOffering,
|
||||
templateFields,
|
||||
onSuccess: () => {
|
||||
editor.closeOffering();
|
||||
editor.offeringForm.resetFields();
|
||||
},
|
||||
});
|
||||
const workspace = useQuery({
|
||||
queryKey: ["admin-workspace-offering-fields"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const previewWorkspace = useQuery({
|
||||
queryKey: ["admin-preview-workspace-services"],
|
||||
queryFn: () => client.getAdminPreviewWorkspace(),
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
const templateFields: TemplateAdminField[] = (
|
||||
workspace.data?.templateContent?.admin.sections ?? []
|
||||
)
|
||||
.filter((section) => section.target === "offering")
|
||||
.flatMap((section) =>
|
||||
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
|
||||
);
|
||||
const templateFieldSection = useMemo<TemplateAdminSection>(
|
||||
() => ({
|
||||
key: "offering",
|
||||
title: "模板内容",
|
||||
description: "",
|
||||
page: "detail",
|
||||
target: "offering",
|
||||
fields: templateFields,
|
||||
}),
|
||||
[templateFields],
|
||||
);
|
||||
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 visualOfferingTarget = (workspace.data?.templateContent?.admin.sections ?? [])
|
||||
.filter((section) => section.target === "offering" && section.page === "offerings")
|
||||
.flatMap((section) => section.previewTargets ?? [])
|
||||
.find((target) => templateFields.some((field) => field.previewTarget === target.key)) ?? {
|
||||
|
||||
const sections = workspace.data?.templateContent?.admin.sections ?? [];
|
||||
const previewTargets = useMemo(() => previewTargetsByPage(sections), [sections]);
|
||||
const listTarget = previewTargets.offerings.find((target) =>
|
||||
templateFields.some((field) => field.previewTarget === target.key),
|
||||
) ?? {
|
||||
key: "linjing-editorial.offerings.item",
|
||||
label: "业务卡片",
|
||||
page: "offerings",
|
||||
source: "offering",
|
||||
};
|
||||
const hasTemplateDetailCopy = templateFields.some(
|
||||
(field) => field.binding === "offering.config.details.background",
|
||||
);
|
||||
const previewTargets = useMemo<Record<string, PreviewTarget[]>>(
|
||||
() =>
|
||||
["offerings", "detail"].reduce<Record<string, PreviewTarget[]>>((result, page) => {
|
||||
result[page] = (workspace.data?.templateContent?.admin.sections ?? [])
|
||||
.filter((section) => section.page === page)
|
||||
.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
page: section.page,
|
||||
source: section.fields.some(
|
||||
(field) =>
|
||||
field.binding.startsWith("offering.") && field.previewTarget === target.key,
|
||||
)
|
||||
? "offering"
|
||||
: section.target,
|
||||
})),
|
||||
);
|
||||
return result;
|
||||
}, {}),
|
||||
[workspace.data?.templateContent],
|
||||
);
|
||||
const detailTarget = previewTargets.detail.find((target) => target.source === "offering");
|
||||
const listFields = useMemo(
|
||||
() => templateFields.filter((field) => field.previewTarget === visualOfferingTarget.key),
|
||||
[templateFields, visualOfferingTarget.key],
|
||||
() => templateFields.filter((field) => field.previewTarget === listTarget.key),
|
||||
[templateFields, listTarget.key],
|
||||
);
|
||||
const detailTarget = previewTargets.detail?.find((target) => target.source === "offering");
|
||||
const detailFields = useMemo(
|
||||
() => templateFields.filter((field) => field.previewTarget === detailTarget?.key),
|
||||
[templateFields, detailTarget?.key],
|
||||
@@ -134,426 +52,85 @@ export function ServicesPage() {
|
||||
),
|
||||
[templateFields, listFields, detailFields],
|
||||
);
|
||||
const activeTemplateFields =
|
||||
previewPage === "offerings"
|
||||
const activeTemplateFields: TemplateAdminField[] =
|
||||
editor.previewPage === "offerings"
|
||||
? [...listFields, ...otherFields.filter((field) => field.page === "offerings")]
|
||||
: [...detailFields, ...otherFields.filter((field) => field.page === "detail")];
|
||||
const previewWorkspaceDraft = useMemo<RuntimeWorkspace | undefined>(() => {
|
||||
if (!previewWorkspace.data || !editingOffering) return undefined;
|
||||
const values: Record<string, unknown> = Object.keys(formValues).length
|
||||
? formValues
|
||||
: (offeringForm.getFieldsValue(true) as Record<string, unknown>);
|
||||
const config = applyPresentationValues(
|
||||
editingOffering.config,
|
||||
[{ key: "offering", fields: templateFields }],
|
||||
values,
|
||||
);
|
||||
const offeringValues = {
|
||||
name: values.name,
|
||||
summary: values.summary,
|
||||
description: values.description,
|
||||
priceText: values.priceText,
|
||||
coverUrl: values.coverUrl,
|
||||
};
|
||||
return {
|
||||
...previewWorkspace.data,
|
||||
offerings: previewWorkspace.data.offerings.map((item) =>
|
||||
item.id === editingOffering.id
|
||||
? {
|
||||
...item,
|
||||
name:
|
||||
typeof offeringValues.name === "string" && offeringValues.name.trim()
|
||||
? offeringValues.name
|
||||
: item.name,
|
||||
summary:
|
||||
typeof offeringValues.summary === "string" ? offeringValues.summary : item.summary,
|
||||
priceText:
|
||||
typeof offeringValues.priceText === "string"
|
||||
? offeringValues.priceText
|
||||
: item.priceText,
|
||||
coverUrl:
|
||||
typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||
? offeringValues.coverUrl
|
||||
: item.coverUrl,
|
||||
config,
|
||||
presentation: {
|
||||
...item.presentation,
|
||||
...config,
|
||||
...(config.presentation && typeof config.presentation === "object"
|
||||
? (config.presentation as Record<string, unknown>)
|
||||
: {}),
|
||||
...(typeof config.area === "string" ? { area: config.area } : {}),
|
||||
...(typeof config.series === "string" ? { series: config.series } : {}),
|
||||
...(typeof config.spaceType === "string" ? { spaceType: config.spaceType } : {}),
|
||||
heroImage:
|
||||
typeof config.detailHero === "string"
|
||||
? config.detailHero
|
||||
: typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||
? offeringValues.coverUrl
|
||||
: (item.coverUrl ?? null),
|
||||
details: {
|
||||
...item.presentation.details,
|
||||
...(config.details && typeof config.details === "object"
|
||||
? {
|
||||
...item.presentation.details,
|
||||
...(config.details as Record<string, unknown>),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
}
|
||||
: item,
|
||||
),
|
||||
brand: previewWorkspace.data.brand,
|
||||
};
|
||||
const previewWorkspaceDraft = useMemo(() => {
|
||||
if (!previewWorkspace.data || !editor.editingOffering) return undefined;
|
||||
return buildOfferingPreviewWorkspace({
|
||||
previewWorkspace: previewWorkspace.data,
|
||||
editingOffering: editor.editingOffering,
|
||||
templateFields,
|
||||
formValues: editor.formValues,
|
||||
});
|
||||
}, [
|
||||
previewWorkspace.data,
|
||||
editingOffering,
|
||||
editor.editingOffering,
|
||||
templateFields,
|
||||
formValues,
|
||||
offeringDraftVersion,
|
||||
offeringForm,
|
||||
editor.formValues,
|
||||
editor.offeringDraftVersion,
|
||||
]);
|
||||
const saveOffering = useMutation({
|
||||
mutationFn: (values: Record<string, unknown>) => {
|
||||
const fields = Object.fromEntries(
|
||||
Object.entries(values).filter(([key]) => key !== "config" && !key.startsWith("offering:")),
|
||||
);
|
||||
const config = applyPresentationValues(
|
||||
editingOffering?.config,
|
||||
[{ key: "offering", fields: templateFields }],
|
||||
values,
|
||||
);
|
||||
const body = { ...fields, config };
|
||||
return editingOffering
|
||||
? client.updateAdminOffering(editingOffering.id, body)
|
||||
: client.createAdminOffering(body as Omit<Offering, "id" | "brandId">);
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项已保存");
|
||||
setOfferingOpen(false);
|
||||
setEditingOffering(null);
|
||||
offeringForm.resetFields();
|
||||
offeringForm.setFieldsValue({});
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace-offering-fields"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace-services"] });
|
||||
},
|
||||
});
|
||||
const deleteOffering = useMutation({
|
||||
mutationFn: (id: string) => client.deleteAdminOffering(id),
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项已删除");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
},
|
||||
});
|
||||
const toggleOffering = useMutation({
|
||||
mutationFn: ({ id, isEnabled }: { id: string; isEnabled: boolean }) =>
|
||||
client.updateAdminOffering(id, { isEnabled }),
|
||||
onSuccess: () => {
|
||||
message.success("业务提供项状态已更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-offerings"] });
|
||||
},
|
||||
});
|
||||
const beginOffering = (item?: Offering) => {
|
||||
setEditingOffering(item ?? null);
|
||||
setPreviewPage("detail");
|
||||
setOfferingOpen(true);
|
||||
offeringForm.setFieldsValue(
|
||||
item
|
||||
? {
|
||||
kind: item.kind,
|
||||
name: item.name,
|
||||
summary: item.summary ?? "",
|
||||
description: item.description ?? "",
|
||||
priceText: item.priceText ?? "",
|
||||
coverUrl: item.coverUrl ?? "",
|
||||
sortOrder: item.sortOrder,
|
||||
isEnabled: item.isEnabled,
|
||||
...Object.fromEntries(
|
||||
templateFields.map((field) => {
|
||||
const value = readPresentationValue(item.config, field.binding, field);
|
||||
return [
|
||||
presentationFieldName("offering", field.key),
|
||||
value === undefined || value === null || value === ""
|
||||
? field.input === "select"
|
||||
? field.options?.[0]?.value
|
||||
: field.input === "list"
|
||||
? []
|
||||
: undefined
|
||||
: value,
|
||||
];
|
||||
}),
|
||||
),
|
||||
}
|
||||
: {
|
||||
kind: "service",
|
||||
isEnabled: true,
|
||||
sortOrder: 0,
|
||||
...Object.fromEntries(
|
||||
templateFields.map((field) => [
|
||||
presentationFieldName("offering", field.key),
|
||||
field.input === "list" ? [] : undefined,
|
||||
]),
|
||||
),
|
||||
},
|
||||
);
|
||||
setFormValues(offeringForm.getFieldsValue(true) as Record<string, unknown>);
|
||||
|
||||
const navigateToBrand = () => {
|
||||
if (!editor.editingOffering) return;
|
||||
void navigate("/admin/brand", {
|
||||
state: {
|
||||
targetKey:
|
||||
editor.previewPage === "offerings"
|
||||
? listTarget.key
|
||||
: (detailTarget?.key ?? listTarget.key),
|
||||
recordId: editor.editingOffering.id,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<QueryState
|
||||
loading={offerings.isLoading || workspace.isLoading}
|
||||
error={offerings.error || workspace.error}
|
||||
onRetry={() => {
|
||||
void offerings.refetch();
|
||||
void workspace.refetch();
|
||||
}}
|
||||
onRetry={retry}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="小程序内容:业务展示与详情"
|
||||
description={`在「${offeringPageLabel}」管理访客能选择的服务、产品或案例;每项内容的补充资料会显示在对应的「${detailPageLabel}」。`}
|
||||
description={`在「${offeringPageLabel(workspace.data?.templateContent ?? undefined)}」管理访客能选择的服务、产品或案例;每项内容的补充资料会显示在对应的「${detailPageLabel(workspace.data?.templateContent ?? undefined)}」。`}
|
||||
extra={
|
||||
<Button type="primary" onClick={() => beginOffering()}>
|
||||
<Button type="primary" onClick={() => editor.beginOffering()}>
|
||||
新增业务提供项
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<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"
|
||||
loading={offerings.isLoading}
|
||||
dataSource={offerings.data ?? []}
|
||||
columns={[
|
||||
{ title: "名称", dataIndex: "name" },
|
||||
{
|
||||
title: "业务类型",
|
||||
dataIndex: "kind",
|
||||
render: (value) => (
|
||||
<Tag>
|
||||
{(
|
||||
{
|
||||
service: "服务",
|
||||
product: "定制产品",
|
||||
package: "套餐",
|
||||
subscription: "订阅",
|
||||
} as Record<string, string>
|
||||
)[String(value)] ?? String(value)}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{ title: "价格", dataIndex: "priceText" },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "isEnabled",
|
||||
render: (value) => (value ? "已启用" : "已停用"),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: Offering) => (
|
||||
<Space>
|
||||
<Button size="small" onClick={() => beginOffering(item)}>
|
||||
编辑详情
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
loading={toggleOffering.isPending && toggleOffering.variables?.id === item.id}
|
||||
onClick={() =>
|
||||
toggleOffering.mutate({ id: item.id, isEnabled: !item.isEnabled })
|
||||
}
|
||||
>
|
||||
{item.isEnabled ? "禁用" : "启用"}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确认删除这项业务提供项?"
|
||||
description="如果它已经关联咨询表单,系统会阻止删除。"
|
||||
onConfirm={() => deleteOffering.mutate(item.id)}
|
||||
okText="删除"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button
|
||||
danger
|
||||
size="small"
|
||||
loading={deleteOffering.isPending && deleteOffering.variables === item.id}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
{offerings.data?.length === 0 && (
|
||||
<Typography.Paragraph type="secondary">
|
||||
还没有公开业务提供项。创建后,小程序服务页会优先读取这些内容。
|
||||
</Typography.Paragraph>
|
||||
)}
|
||||
<MutationError error={saveOffering.error} />
|
||||
<MutationError error={toggleOffering.error} />
|
||||
<MutationError error={deleteOffering.error} />
|
||||
</section>
|
||||
<Modal
|
||||
open={offeringOpen}
|
||||
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
||||
width={960}
|
||||
onCancel={() => {
|
||||
setOfferingOpen(false);
|
||||
setEditingOffering(null);
|
||||
offeringForm.resetFields();
|
||||
}}
|
||||
onOk={() => offeringForm.submit()}
|
||||
confirmLoading={saveOffering.isPending}
|
||||
>
|
||||
<div className="service-offering-editor">
|
||||
{editingOffering && previewWorkspaceDraft ? (
|
||||
<div className="service-offering-editor__preview">
|
||||
<Segmented
|
||||
className="service-offering-editor__view"
|
||||
value={previewPage}
|
||||
options={[
|
||||
{ value: "offerings", label: "列表卡片" },
|
||||
{ value: "detail", label: "详情内容" },
|
||||
]}
|
||||
onChange={(value) => setPreviewPage(value as "offerings" | "detail")}
|
||||
/>
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message={previewPage === "offerings" ? "正在核对列表展示" : "正在核对详情展示"}
|
||||
description={
|
||||
previewPage === "offerings"
|
||||
? "右侧「列表展示」字段修改后,会实时反映在当前卡片。"
|
||||
: "右侧「详情展示」字段修改后,会实时反映在当前详情内容。"
|
||||
}
|
||||
/>
|
||||
<ComponentTemplatePreview
|
||||
workspace={previewWorkspaceDraft}
|
||||
page={previewPage}
|
||||
offeringId={editingOffering.id}
|
||||
targets={previewTargets[previewPage] ?? []}
|
||||
selection={{
|
||||
targetKey:
|
||||
previewPage === "offerings"
|
||||
? visualOfferingTarget.key
|
||||
: (detailTarget?.key ?? ""),
|
||||
recordId: editingOffering.id,
|
||||
}}
|
||||
onTargetSelected={() => {}}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<Form
|
||||
className="service-offering-editor__form"
|
||||
form={offeringForm}
|
||||
layout="vertical"
|
||||
onValuesChange={(_, allValues) => {
|
||||
setFormValues(allValues as Record<string, unknown>);
|
||||
setOfferingDraftVersion((version) => version + 1);
|
||||
}}
|
||||
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
|
||||
>
|
||||
<div className="service-offering-editor__form-scroll">
|
||||
<Typography.Title level={5}>基础信息</Typography.Title>
|
||||
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
||||
<Select
|
||||
options={[
|
||||
{ value: "service", label: "服务" },
|
||||
{ value: "product", label: "定制产品" },
|
||||
{ value: "package", label: "套餐" },
|
||||
{ value: "subscription", label: "订阅" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="summary" label="一句话说明">
|
||||
<Input />
|
||||
</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>
|
||||
<Form.Item
|
||||
name="coverUrl"
|
||||
label="封面图片地址"
|
||||
help="点击上传,或粘贴服务/产品封面图片地址。"
|
||||
>
|
||||
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" scope="offering" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="sortOrder"
|
||||
label="展示顺序"
|
||||
help="数字越小越靠前,不确定时填写 0。"
|
||||
rules={[{ type: "number", min: 0, max: 9999 }]}
|
||||
>
|
||||
<Input type="number" min={0} max={9999} />
|
||||
</Form.Item>
|
||||
<Form.Item name="isEnabled" label="公开状态">
|
||||
<Select
|
||||
options={[
|
||||
{ value: true, label: "已启用" },
|
||||
{ value: false, label: "已停用" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
{activeTemplateFields.length ? (
|
||||
<div>
|
||||
<Typography.Title level={5}>
|
||||
{previewPage === "offerings" ? "列表展示字段" : "详情展示字段"}
|
||||
</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
这里只编辑左侧预览对应的字段;它们与小程序页面编辑的是同一份业务数据。
|
||||
</Typography.Paragraph>
|
||||
<RecordContentFields
|
||||
section={{
|
||||
...templateFieldSection,
|
||||
fields: activeTemplateFields,
|
||||
}}
|
||||
sectionKey="offering"
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{editingOffering ? (
|
||||
<Button
|
||||
htmlType="button"
|
||||
onClick={() =>
|
||||
navigate("/admin/brand", {
|
||||
state: {
|
||||
targetKey:
|
||||
previewPage === "offerings"
|
||||
? visualOfferingTarget.key
|
||||
: (detailTarget?.key ?? visualOfferingTarget.key),
|
||||
recordId: editingOffering.id,
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
在小程序页面编辑
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
</Modal>
|
||||
<OfferingsTable
|
||||
pageLabel={offeringPageLabel(workspace.data?.templateContent ?? undefined)}
|
||||
detailSectionTitles={sections
|
||||
.filter((section) => section.target === "offering" && section.page === "detail")
|
||||
.map((section) => section.title)}
|
||||
items={offerings.data ?? []}
|
||||
loading={offerings.isLoading}
|
||||
saveError={mutations.saveOffering.error}
|
||||
toggleOffering={mutations.toggleOffering}
|
||||
deleteOffering={mutations.deleteOffering}
|
||||
onEdit={(item: Offering) => editor.beginOffering(item)}
|
||||
/>
|
||||
<OfferingEditorModal
|
||||
open={editor.offeringOpen}
|
||||
editingOffering={editor.editingOffering}
|
||||
form={editor.offeringForm}
|
||||
previewPage={editor.previewPage}
|
||||
previewWorkspace={previewWorkspaceDraft}
|
||||
previewTargets={previewTargets}
|
||||
activeTemplateFields={activeTemplateFields}
|
||||
templateFieldSection={editor.templateFieldSection}
|
||||
hasTemplateDetailCopy={hasTemplateDetailCopy(templateFields)}
|
||||
listTarget={listTarget}
|
||||
detailTarget={detailTarget}
|
||||
saving={mutations.saveOffering.isPending}
|
||||
onClose={editor.closeOffering}
|
||||
onPreviewPageChange={(page: PreviewPage) => editor.setPreviewPage(page)}
|
||||
onValuesChange={(values) => editor.handleValuesChange(null, values)}
|
||||
onFinish={(values) => mutations.saveOffering.mutate(values)}
|
||||
onEditInBrand={navigateToBrand}
|
||||
/>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user