fix: 业务提供项点选后仅显示当前区块字段 #13

Merged
que01 merged 1 commits from fix/offering-editor-target-filter into main 2026-10-24 02:45:43 +00:00
4 changed files with 150 additions and 66 deletions

No files matched your search

@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"scope": "模板完成证据登记,保留命令、日志与产物哈希",
"generatedAt": "2026-10-24T02:02:12.474Z",
"generatedAt": "2026-10-24T02:35:52.145Z",
"templates": {
"acheng-campus-food": {
"real-manifest-interaction": {
@@ -256,5 +256,5 @@
}
}
},
"sourceTreeHash": "9d33ce8dbbddd34b91f045f49dc2316e36738ffec1429a93733d45d1b7b2a356"
"sourceTreeHash": "a5506179992f144e6b4afb0f0dfc295c5d722a5aadf7027fd785479a8276320f"
}
@@ -13,6 +13,14 @@ import type { PreviewSelection, PreviewTarget } from "../brand/preview-selection
import type { FormInstance } from "antd";
import "./ServicesPage.css";
const OFFERING_BASE_FIELD_BINDINGS: Record<string, string> = {
name: "offering.name",
summary: "offering.summary",
description: "offering.description",
priceText: "offering.priceText",
coverUrl: "offering.coverUrl",
};
type OfferingEditorModalProps = {
open: boolean;
editingOffering: Offering | null;
@@ -66,6 +74,23 @@ export function OfferingEditorModal({
? { targetKey: previewSelectionTarget.key, recordId: editingOffering.id }
: { targetKey: previewSelectionTarget.key }
: undefined;
// 点选某个区块后,右侧只保留该区块真正会展示的字段;未点选时仍展示完整表单。
const visibleBaseFields = (() => {
if (!selectedTarget) return undefined;
if (selectedTarget.source !== "offering") return new Set<string>();
const bindings = new Set(activePreviewBindings);
return new Set(
Object.entries(OFFERING_BASE_FIELD_BINDINGS)
.filter(([, binding]) => bindings.has(binding))
.map(([name]) => name),
);
})();
const isBaseFieldVisible = (name: string) => !visibleBaseFields || visibleBaseFields.has(name);
const showDescriptionField = !hasTemplateDetailCopy && isBaseFieldVisible("description");
const hasVisibleBaseFields =
["kind", "name", "summary", "priceText", "coverUrl", "sortOrder", "isEnabled"].some((name) =>
isBaseFieldVisible(name),
) || showDescriptionField;
// 点选区块后,在右侧滚动到并高亮对应的输入项;品牌通用区块没有对应输入项时只保留提示。
useEffect(() => {
@@ -106,9 +131,11 @@ export function OfferingEditorModal({
showIcon
title={previewPage === "offerings" ? "正在核对列表展示" : "正在核对详情展示"}
description={
previewPage === "offerings"
? "右侧「列表展示」字段修改后,会实时反映在当前卡片。"
: "右侧「详情展示」字段修改后,会实时反映在当前详情内容。"
selectedTarget
? `右侧只显示「${selectedTarget.label}」对应的字段,修改会实时反映在左侧预览;点击预览空白处或「查看全部字段」可恢复。`
: previewPage === "offerings"
? "点击左侧区块后,右侧只显示该区块对应的字段;未点选时显示全部列表展示字段。"
: "点击左侧区块后,右侧只显示该区块对应的字段;未点选时显示全部详情展示字段。"
}
/>
<ComponentTemplatePreview
@@ -129,33 +156,56 @@ export function OfferingEditorModal({
onFinish={onFinish}
>
<div ref={formScroll} className="service-offering-editor__form-scroll">
<h4 className="admin-subhead">基础信息</h4>
<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="名称"
data-presentation-binding="offering.name"
rules={[{ required: true }]}
>
<Input />
</Form.Item>
<Form.Item
name="summary"
label="一句话说明"
data-presentation-binding="offering.summary"
>
<Input />
</Form.Item>
{!hasTemplateDetailCopy ? (
{selectedTarget ? (
<div className="service-offering-editor__selection">
<div>
<strong>正在编辑「{selectedTarget.label}」</strong>
<p className="admin-section-description">
只显示这个区块对应的字段,其他字段已临时隐藏。
</p>
</div>
<Button
size="small"
htmlType="button"
onClick={() => onPreviewTargetSelected(undefined)}
>
查看全部字段
</Button>
</div>
) : null}
{hasVisibleBaseFields ? <h4 className="admin-subhead">基础信息</h4> : null}
{isBaseFieldVisible("kind") ? (
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
<Select
options={[
{ value: "service", label: "服务" },
{ value: "product", label: "定制产品" },
{ value: "package", label: "套餐" },
{ value: "subscription", label: "订阅" },
]}
/>
</Form.Item>
) : null}
{isBaseFieldVisible("name") ? (
<Form.Item
name="name"
label="名称"
data-presentation-binding="offering.name"
rules={[{ required: true }]}
>
<Input />
</Form.Item>
) : null}
{isBaseFieldVisible("summary") ? (
<Form.Item
name="summary"
label="一句话说明"
data-presentation-binding="offering.summary"
>
<Input />
</Form.Item>
) : null}
{showDescriptionField ? (
<Form.Item
name="description"
label="详细介绍"
@@ -164,37 +214,45 @@ export function OfferingEditorModal({
<Input.TextArea rows={5} />
</Form.Item>
) : null}
<Form.Item
name="priceText"
label="价格展示"
data-presentation-binding="offering.priceText"
>
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
</Form.Item>
<Form.Item
name="coverUrl"
label="封面图片地址"
help="点击上传,或粘贴服务/产品封面图片地址。"
data-presentation-binding="offering.coverUrl"
>
<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>
{isBaseFieldVisible("priceText") ? (
<Form.Item
name="priceText"
label="价格展示"
data-presentation-binding="offering.priceText"
>
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
</Form.Item>
) : null}
{isBaseFieldVisible("coverUrl") ? (
<Form.Item
name="coverUrl"
label="封面图片地址"
help="点击上传,或粘贴服务/产品封面图片地址。"
data-presentation-binding="offering.coverUrl"
>
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" scope="offering" />
</Form.Item>
) : null}
{isBaseFieldVisible("sortOrder") ? (
<Form.Item
name="sortOrder"
label="展示顺序"
help="数字越小越靠前,不确定时填写 0。"
rules={[{ type: "number", min: 0, max: 9999 }]}
>
<Input type="number" min={0} max={9999} />
</Form.Item>
) : null}
{isBaseFieldVisible("isEnabled") ? (
<Form.Item name="isEnabled" label="公开状态">
<Select
options={[
{ value: true, label: "已启用" },
{ value: false, label: "已停用" },
]}
/>
</Form.Item>
) : null}
{selectedTarget && selectedTarget.source !== "offering" ? (
<Alert
type="warning"
@@ -55,6 +55,22 @@
margin-top: 0;
}
.service-offering-editor__selection {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
padding: 12px 14px;
border: 1px solid rgba(22, 119, 255, 0.28);
border-radius: 10px;
background-color: rgba(22, 119, 255, 0.06);
}
.service-offering-editor__selection p {
margin: 4px 0 0;
}
.service-offering-editor__form-scroll .ant-form-item {
margin-bottom: 20px;
}
+13 -3
View File
@@ -195,6 +195,9 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
"acheng-campus-food.detail.dishDetail",
);
await expect(page.getByText("餐品与服务详情对应字段", { exact: true })).toBeVisible();
await expect(page.getByText("正在编辑「餐品与服务详情」", { exact: true })).toBeVisible();
await expect(page.getByLabel("名称", { exact: true })).toHaveCount(0);
await expect(page.getByLabel("类型", { exact: true })).toHaveCount(0);
await expect(
editor.locator('[data-presentation-binding="offering.config.details.background"]'),
).toHaveClass(/is-preview-active/);
@@ -209,6 +212,9 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
await preview.locator(".offering-card .dish-name").click();
await expect(page.getByText("业务卡片对应字段", { exact: true })).toBeVisible();
await expect(page.getByText("正在编辑「业务卡片」", { exact: true })).toBeVisible();
await expect(page.getByLabel("类型", { exact: true })).toHaveCount(0);
await expect(page.getByLabel("展示顺序", { exact: true })).toHaveCount(0);
await expect(editor.locator('[data-presentation-binding="offering.name"]')).toHaveClass(
/is-preview-active/,
);
@@ -219,10 +225,14 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
await preview.locator(".menu-head").click();
await expect(preview).toHaveAttribute("data-active-target", "acheng-campus-food.offerings.menu");
await expect(page.getByText("「菜单页说明」属于页面通用内容", { exact: true })).toBeVisible();
await expect(editor.locator('[data-presentation-binding="offering.name"]')).not.toHaveClass(
/is-preview-active/,
);
await expect(editor.locator('[data-presentation-binding="offering.name"]')).toHaveCount(0);
await expect(editor.getByText("详情主图", { exact: true })).toHaveCount(0);
await expect(page.getByLabel("名称", { exact: true })).toHaveCount(0);
await expect(page.getByLabel("类型", { exact: true })).toHaveCount(0);
await page.getByRole("button", { name: "查看全部字段" }).click();
await expect(page.getByLabel("名称", { exact: true })).toBeVisible();
await expect(page.getByLabel("类型", { exact: true })).toBeVisible();
await preview.locator(".offering-card .dish-name").click();
await expect(page.getByText("业务卡片对应字段", { exact: true })).toBeVisible();