feat: 业务提供项编辑弹窗支持区块点选联动 #12
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"scope": "模板完成证据登记,保留命令、日志与产物哈希",
|
"scope": "模板完成证据登记,保留命令、日志与产物哈希",
|
||||||
"generatedAt": "2026-10-23T14:07:47.923Z",
|
"generatedAt": "2026-10-24T02:02:12.474Z",
|
||||||
"templates": {
|
"templates": {
|
||||||
"acheng-campus-food": {
|
"acheng-campus-food": {
|
||||||
"real-manifest-interaction": {
|
"real-manifest-interaction": {
|
||||||
@@ -256,5 +256,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sourceTreeHash": "9394ffb025e5f6b777f2dd991cbb8b56026d5d63d9161a8639cc612bcc39f730"
|
"sourceTreeHash": "9d33ce8dbbddd34b91f045f49dc2316e36738ffec1429a93733d45d1b7b2a356"
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ export function RecordContentFields({
|
|||||||
return (
|
return (
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
{section.fields.map((field) => (
|
{section.fields.map((field) => (
|
||||||
<Col key={field.key} xs={24} md={24}>
|
<Col key={field.key} xs={24} md={24} data-presentation-binding={field.binding}>
|
||||||
{field.input === "list" ? (
|
{field.input === "list" ? (
|
||||||
<TemplateListField field={field} name={presentationFieldName(sectionKey, field.key)} />
|
<TemplateListField field={field} name={presentationFieldName(sectionKey, field.key)} />
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Alert, Button, Form, Input, Modal, Segmented, Select } from "antd";
|
import { Alert, Button, Form, Input, Modal, Segmented, Select } from "antd";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
import type {
|
import type {
|
||||||
Offering,
|
Offering,
|
||||||
RuntimeWorkspace,
|
RuntimeWorkspace,
|
||||||
@@ -8,7 +9,7 @@ import type {
|
|||||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||||
import { RecordContentFields } from "../../components/RecordContentEditor.js";
|
import { RecordContentFields } from "../../components/RecordContentEditor.js";
|
||||||
import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
||||||
import type { PreviewTarget } from "../brand/preview-selection.js";
|
import type { PreviewSelection, PreviewTarget } from "../brand/preview-selection.js";
|
||||||
import type { FormInstance } from "antd";
|
import type { FormInstance } from "antd";
|
||||||
import "./ServicesPage.css";
|
import "./ServicesPage.css";
|
||||||
|
|
||||||
@@ -20,6 +21,8 @@ type OfferingEditorModalProps = {
|
|||||||
previewWorkspace: RuntimeWorkspace | undefined;
|
previewWorkspace: RuntimeWorkspace | undefined;
|
||||||
previewTargets: Record<"offerings" | "detail", PreviewTarget[]>;
|
previewTargets: Record<"offerings" | "detail", PreviewTarget[]>;
|
||||||
activeTemplateFields: TemplateAdminField[];
|
activeTemplateFields: TemplateAdminField[];
|
||||||
|
activePreviewBindings: string[];
|
||||||
|
selectedTarget: PreviewTarget | undefined;
|
||||||
templateFieldSection: TemplateAdminSection;
|
templateFieldSection: TemplateAdminSection;
|
||||||
hasTemplateDetailCopy: boolean;
|
hasTemplateDetailCopy: boolean;
|
||||||
listTarget: PreviewTarget;
|
listTarget: PreviewTarget;
|
||||||
@@ -27,6 +30,7 @@ type OfferingEditorModalProps = {
|
|||||||
saving: boolean;
|
saving: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onPreviewPageChange: (page: "offerings" | "detail") => void;
|
onPreviewPageChange: (page: "offerings" | "detail") => void;
|
||||||
|
onPreviewTargetSelected: (selection?: PreviewSelection) => void;
|
||||||
onValuesChange: (values: Record<string, unknown>) => void;
|
onValuesChange: (values: Record<string, unknown>) => void;
|
||||||
onFinish: (values: Record<string, unknown>) => void;
|
onFinish: (values: Record<string, unknown>) => void;
|
||||||
onEditInBrand: () => void;
|
onEditInBrand: () => void;
|
||||||
@@ -40,6 +44,8 @@ export function OfferingEditorModal({
|
|||||||
previewWorkspace,
|
previewWorkspace,
|
||||||
previewTargets,
|
previewTargets,
|
||||||
activeTemplateFields,
|
activeTemplateFields,
|
||||||
|
activePreviewBindings,
|
||||||
|
selectedTarget,
|
||||||
templateFieldSection,
|
templateFieldSection,
|
||||||
hasTemplateDetailCopy,
|
hasTemplateDetailCopy,
|
||||||
listTarget,
|
listTarget,
|
||||||
@@ -47,10 +53,33 @@ export function OfferingEditorModal({
|
|||||||
saving,
|
saving,
|
||||||
onClose,
|
onClose,
|
||||||
onPreviewPageChange,
|
onPreviewPageChange,
|
||||||
|
onPreviewTargetSelected,
|
||||||
onValuesChange,
|
onValuesChange,
|
||||||
onFinish,
|
onFinish,
|
||||||
onEditInBrand,
|
onEditInBrand,
|
||||||
}: OfferingEditorModalProps) {
|
}: OfferingEditorModalProps) {
|
||||||
|
const formScroll = useRef<HTMLDivElement>(null);
|
||||||
|
const defaultPreviewTarget = previewPage === "offerings" ? listTarget : detailTarget;
|
||||||
|
const previewSelectionTarget = selectedTarget ?? defaultPreviewTarget;
|
||||||
|
const previewSelection: PreviewSelection | undefined = previewSelectionTarget
|
||||||
|
? previewSelectionTarget.source === "offering" && editingOffering
|
||||||
|
? { targetKey: previewSelectionTarget.key, recordId: editingOffering.id }
|
||||||
|
: { targetKey: previewSelectionTarget.key }
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
// 点选区块后,在右侧滚动到并高亮对应的输入项;品牌通用区块没有对应输入项时只保留提示。
|
||||||
|
useEffect(() => {
|
||||||
|
const host = formScroll.current;
|
||||||
|
if (!host || !selectedTarget || activePreviewBindings.length === 0) return;
|
||||||
|
const bindings = new Set(activePreviewBindings);
|
||||||
|
const nodes = Array.from(
|
||||||
|
host.querySelectorAll<HTMLElement>("[data-presentation-binding]"),
|
||||||
|
).filter((node) => bindings.has(node.dataset.presentationBinding ?? ""));
|
||||||
|
nodes.forEach((node) => node.classList.add("is-preview-active"));
|
||||||
|
nodes[0]?.scrollIntoView({ block: "center", behavior: "smooth" });
|
||||||
|
return () => nodes.forEach((node) => node.classList.remove("is-preview-active"));
|
||||||
|
}, [selectedTarget, activePreviewBindings]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
open={open}
|
open={open}
|
||||||
@@ -87,11 +116,8 @@ export function OfferingEditorModal({
|
|||||||
page={previewPage}
|
page={previewPage}
|
||||||
offeringId={editingOffering.id}
|
offeringId={editingOffering.id}
|
||||||
targets={previewTargets[previewPage]}
|
targets={previewTargets[previewPage]}
|
||||||
selection={{
|
{...(previewSelection ? { selection: previewSelection } : {})}
|
||||||
targetKey: previewPage === "offerings" ? listTarget.key : (detailTarget?.key ?? ""),
|
onTargetSelected={onPreviewTargetSelected}
|
||||||
recordId: editingOffering.id,
|
|
||||||
}}
|
|
||||||
onTargetSelected={() => {}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -102,7 +128,7 @@ export function OfferingEditorModal({
|
|||||||
onValuesChange={(_, allValues) => onValuesChange(allValues)}
|
onValuesChange={(_, allValues) => onValuesChange(allValues)}
|
||||||
onFinish={onFinish}
|
onFinish={onFinish}
|
||||||
>
|
>
|
||||||
<div className="service-offering-editor__form-scroll">
|
<div ref={formScroll} className="service-offering-editor__form-scroll">
|
||||||
<h4 className="admin-subhead">基础信息</h4>
|
<h4 className="admin-subhead">基础信息</h4>
|
||||||
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
||||||
<Select
|
<Select
|
||||||
@@ -114,24 +140,42 @@ export function OfferingEditorModal({
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
<Form.Item
|
||||||
|
name="name"
|
||||||
|
label="名称"
|
||||||
|
data-presentation-binding="offering.name"
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="summary" label="一句话说明">
|
<Form.Item
|
||||||
|
name="summary"
|
||||||
|
label="一句话说明"
|
||||||
|
data-presentation-binding="offering.summary"
|
||||||
|
>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{!hasTemplateDetailCopy ? (
|
{!hasTemplateDetailCopy ? (
|
||||||
<Form.Item name="description" label="详细介绍">
|
<Form.Item
|
||||||
|
name="description"
|
||||||
|
label="详细介绍"
|
||||||
|
data-presentation-binding="offering.description"
|
||||||
|
>
|
||||||
<Input.TextArea rows={5} />
|
<Input.TextArea rows={5} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
) : null}
|
) : null}
|
||||||
<Form.Item name="priceText" label="价格展示">
|
<Form.Item
|
||||||
|
name="priceText"
|
||||||
|
label="价格展示"
|
||||||
|
data-presentation-binding="offering.priceText"
|
||||||
|
>
|
||||||
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="coverUrl"
|
name="coverUrl"
|
||||||
label="封面图片地址"
|
label="封面图片地址"
|
||||||
help="点击上传,或粘贴服务/产品封面图片地址。"
|
help="点击上传,或粘贴服务/产品封面图片地址。"
|
||||||
|
data-presentation-binding="offering.coverUrl"
|
||||||
>
|
>
|
||||||
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" scope="offering" />
|
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" scope="offering" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -151,13 +195,28 @@ export function OfferingEditorModal({
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
{selectedTarget && selectedTarget.source !== "offering" ? (
|
||||||
|
<Alert
|
||||||
|
type="warning"
|
||||||
|
showIcon
|
||||||
|
className="admin-offset-bottom"
|
||||||
|
title={`「${selectedTarget.label}」属于页面通用内容`}
|
||||||
|
description="这项内容不在业务提供项里维护。可点击下方「在小程序页面编辑」到对应区块修改。"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
{activeTemplateFields.length ? (
|
{activeTemplateFields.length ? (
|
||||||
<div>
|
<div>
|
||||||
<h4 className="admin-subhead">
|
<h4 className="admin-subhead">
|
||||||
{previewPage === "offerings" ? "列表展示字段" : "详情展示字段"}
|
{selectedTarget
|
||||||
|
? `${selectedTarget.label}对应字段`
|
||||||
|
: previewPage === "offerings"
|
||||||
|
? "列表展示字段"
|
||||||
|
: "详情展示字段"}
|
||||||
</h4>
|
</h4>
|
||||||
<p className="admin-section-description admin-offset-bottom">
|
<p className="admin-section-description admin-offset-bottom">
|
||||||
这里只编辑左侧预览对应的字段;它们与小程序页面编辑的是同一份业务数据。
|
{selectedTarget
|
||||||
|
? "右侧已定位到该区块使用的字段,修改会实时反映在左侧预览。"
|
||||||
|
: "这里只编辑左侧预览对应的字段;它们与小程序页面编辑的是同一份业务数据。"}
|
||||||
</p>
|
</p>
|
||||||
<RecordContentFields
|
<RecordContentFields
|
||||||
section={{
|
section={{
|
||||||
@@ -167,6 +226,14 @@ export function OfferingEditorModal({
|
|||||||
sectionKey="offering"
|
sectionKey="offering"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
) : selectedTarget?.source === "offering" ? (
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
className="admin-offset-bottom"
|
||||||
|
title={`「${selectedTarget.label}」只包含基础信息`}
|
||||||
|
description="请修改上方基础信息,左侧预览会实时同步。"
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{editingOffering ? (
|
{editingOffering ? (
|
||||||
<Button htmlType="button" onClick={onEditInBrand}>
|
<Button htmlType="button" onClick={onEditInBrand}>
|
||||||
|
|||||||
@@ -59,6 +59,19 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__form-scroll [data-presentation-binding] {
|
||||||
|
scroll-margin-block: 24px;
|
||||||
|
border-radius: 8px;
|
||||||
|
transition:
|
||||||
|
background-color 180ms ease,
|
||||||
|
box-shadow 180ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__form-scroll [data-presentation-binding].is-preview-active {
|
||||||
|
background-color: rgba(22, 119, 255, 0.07);
|
||||||
|
box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.24);
|
||||||
|
}
|
||||||
|
|
||||||
.service-offering-editor__form-scroll .ant-typography h5.ant-typography {
|
.service-offering-editor__form-scroll .ant-typography h5.ant-typography {
|
||||||
margin: 28px 0 4px;
|
margin: 28px 0 4px;
|
||||||
padding-bottom: 8px;
|
padding-bottom: 8px;
|
||||||
|
|||||||
@@ -7,9 +7,14 @@ import { QueryState } from "../../components/QueryState.js";
|
|||||||
import { OfferingEditorModal } from "./OfferingEditorModal.js";
|
import { OfferingEditorModal } from "./OfferingEditorModal.js";
|
||||||
import { OfferingsTable } from "./OfferingsTable.js";
|
import { OfferingsTable } from "./OfferingsTable.js";
|
||||||
import { detailPageLabel, hasTemplateDetailCopy, offeringPageLabel } from "./offering-model.js";
|
import { detailPageLabel, hasTemplateDetailCopy, offeringPageLabel } from "./offering-model.js";
|
||||||
import { buildOfferingPreviewWorkspace, previewTargetsByPage } from "./offering-preview.js";
|
import {
|
||||||
|
buildOfferingPreviewWorkspace,
|
||||||
|
previewFieldsByTarget,
|
||||||
|
previewTargetsByPage,
|
||||||
|
} from "./offering-preview.js";
|
||||||
import { useOfferingEditor } from "./use-offering-editor.js";
|
import { useOfferingEditor } from "./use-offering-editor.js";
|
||||||
import { useOfferingMutations, useOfferingQueries } from "./use-offering-data.js";
|
import { useOfferingMutations, useOfferingQueries } from "./use-offering-data.js";
|
||||||
|
import type { PreviewSelection } from "../brand/preview-selection.js";
|
||||||
|
|
||||||
type PreviewPage = "offerings" | "detail";
|
type PreviewPage = "offerings" | "detail";
|
||||||
|
|
||||||
@@ -28,15 +33,23 @@ export function ServicesPage() {
|
|||||||
|
|
||||||
const sections = workspace.data?.templateContent?.admin.sections ?? [];
|
const sections = workspace.data?.templateContent?.admin.sections ?? [];
|
||||||
const previewTargets = useMemo(() => previewTargetsByPage(sections), [sections]);
|
const previewTargets = useMemo(() => previewTargetsByPage(sections), [sections]);
|
||||||
const listTarget = previewTargets.offerings.find((target) =>
|
const fieldsByTarget = useMemo(() => previewFieldsByTarget(sections), [sections]);
|
||||||
templateFields.some((field) => field.previewTarget === target.key),
|
const listTarget = useMemo(
|
||||||
) ?? {
|
() =>
|
||||||
key: "offering.list.item",
|
previewTargets.offerings.find((target) =>
|
||||||
label: "业务卡片",
|
templateFields.some((field) => field.previewTarget === target.key),
|
||||||
page: "offerings",
|
) ?? {
|
||||||
source: "offering",
|
key: "offering.list.item",
|
||||||
};
|
label: "业务卡片",
|
||||||
const detailTarget = previewTargets.detail.find((target) => target.source === "offering");
|
page: "offerings",
|
||||||
|
source: "offering" as const,
|
||||||
|
},
|
||||||
|
[previewTargets, templateFields],
|
||||||
|
);
|
||||||
|
const detailTarget = useMemo(
|
||||||
|
() => previewTargets.detail.find((target) => target.source === "offering"),
|
||||||
|
[previewTargets],
|
||||||
|
);
|
||||||
const listFields = useMemo(
|
const listFields = useMemo(
|
||||||
() => templateFields.filter((field) => field.previewTarget === listTarget.key),
|
() => templateFields.filter((field) => field.previewTarget === listTarget.key),
|
||||||
[templateFields, listTarget.key],
|
[templateFields, listTarget.key],
|
||||||
@@ -52,10 +65,37 @@ export function ServicesPage() {
|
|||||||
),
|
),
|
||||||
[templateFields, listFields, detailFields],
|
[templateFields, listFields, detailFields],
|
||||||
);
|
);
|
||||||
const activeTemplateFields: TemplateAdminField[] =
|
const pageTemplateFields = useMemo<TemplateAdminField[]>(
|
||||||
editor.previewPage === "offerings"
|
() =>
|
||||||
? [...listFields, ...otherFields.filter((field) => field.page === "offerings")]
|
editor.previewPage === "offerings"
|
||||||
: [...detailFields, ...otherFields.filter((field) => field.page === "detail")];
|
? [...listFields, ...otherFields.filter((field) => field.page === "offerings")]
|
||||||
|
: [...detailFields, ...otherFields.filter((field) => field.page === "detail")],
|
||||||
|
[editor.previewPage, listFields, detailFields, otherFields],
|
||||||
|
);
|
||||||
|
// 点选预览区块后,右侧只保留该区块对应的字段,与小程序页面点选编辑保持一致。
|
||||||
|
const selectedTarget = useMemo(() => {
|
||||||
|
if (!editor.previewTargetKey) return undefined;
|
||||||
|
return (
|
||||||
|
previewTargets[editor.previewPage].find((target) => target.key === editor.previewTargetKey) ??
|
||||||
|
(editor.previewTargetKey === listTarget.key ? listTarget : undefined) ??
|
||||||
|
(editor.previewTargetKey === detailTarget?.key ? detailTarget : undefined)
|
||||||
|
);
|
||||||
|
}, [editor.previewPage, editor.previewTargetKey, previewTargets, listTarget, detailTarget]);
|
||||||
|
const activeTemplateFields = useMemo<TemplateAdminField[]>(
|
||||||
|
() =>
|
||||||
|
selectedTarget
|
||||||
|
? pageTemplateFields.filter((field) => field.previewTarget === selectedTarget.key)
|
||||||
|
: pageTemplateFields,
|
||||||
|
[pageTemplateFields, selectedTarget],
|
||||||
|
);
|
||||||
|
// 区块字段的 binding 用于在右侧表单中滚动并高亮同一份数据。
|
||||||
|
const activePreviewBindings = useMemo(
|
||||||
|
() =>
|
||||||
|
selectedTarget
|
||||||
|
? (fieldsByTarget[selectedTarget.key] ?? []).map((field) => field.binding)
|
||||||
|
: [],
|
||||||
|
[fieldsByTarget, selectedTarget],
|
||||||
|
);
|
||||||
const previewWorkspaceDraft = useMemo(() => {
|
const previewWorkspaceDraft = useMemo(() => {
|
||||||
if (!previewWorkspace.data || !editor.editingOffering) return undefined;
|
if (!previewWorkspace.data || !editor.editingOffering) return undefined;
|
||||||
return buildOfferingPreviewWorkspace({
|
return buildOfferingPreviewWorkspace({
|
||||||
@@ -77,9 +117,10 @@ export function ServicesPage() {
|
|||||||
void navigate("/admin/brand", {
|
void navigate("/admin/brand", {
|
||||||
state: {
|
state: {
|
||||||
targetKey:
|
targetKey:
|
||||||
editor.previewPage === "offerings"
|
editor.previewTargetKey ??
|
||||||
|
(editor.previewPage === "offerings"
|
||||||
? listTarget.key
|
? listTarget.key
|
||||||
: (detailTarget?.key ?? listTarget.key),
|
: (detailTarget?.key ?? listTarget.key)),
|
||||||
recordId: editor.editingOffering.id,
|
recordId: editor.editingOffering.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -120,13 +161,18 @@ export function ServicesPage() {
|
|||||||
previewWorkspace={previewWorkspaceDraft}
|
previewWorkspace={previewWorkspaceDraft}
|
||||||
previewTargets={previewTargets}
|
previewTargets={previewTargets}
|
||||||
activeTemplateFields={activeTemplateFields}
|
activeTemplateFields={activeTemplateFields}
|
||||||
|
activePreviewBindings={activePreviewBindings}
|
||||||
|
selectedTarget={selectedTarget}
|
||||||
templateFieldSection={editor.templateFieldSection}
|
templateFieldSection={editor.templateFieldSection}
|
||||||
hasTemplateDetailCopy={hasTemplateDetailCopy(templateFields)}
|
hasTemplateDetailCopy={hasTemplateDetailCopy(templateFields)}
|
||||||
listTarget={listTarget}
|
listTarget={listTarget}
|
||||||
detailTarget={detailTarget}
|
detailTarget={detailTarget}
|
||||||
saving={mutations.saveOffering.isPending}
|
saving={mutations.saveOffering.isPending}
|
||||||
onClose={editor.closeOffering}
|
onClose={editor.closeOffering}
|
||||||
onPreviewPageChange={(page: PreviewPage) => editor.setPreviewPage(page)}
|
onPreviewPageChange={(page: PreviewPage) => editor.changePreviewPage(page)}
|
||||||
|
onPreviewTargetSelected={(selection?: PreviewSelection) =>
|
||||||
|
editor.selectPreviewTarget(selection?.targetKey)
|
||||||
|
}
|
||||||
onValuesChange={(values) => editor.handleValuesChange(null, values)}
|
onValuesChange={(values) => editor.handleValuesChange(null, values)}
|
||||||
onFinish={(values) => mutations.saveOffering.mutate(values)}
|
onFinish={(values) => mutations.saveOffering.mutate(values)}
|
||||||
onEditInBrand={navigateToBrand}
|
onEditInBrand={navigateToBrand}
|
||||||
|
|||||||
@@ -32,6 +32,19 @@ export function previewTargetsByPage(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function previewFieldsByTarget(
|
||||||
|
sections: AdminTemplateContent["admin"]["sections"],
|
||||||
|
): Record<string, TemplateAdminField[]> {
|
||||||
|
const result: Record<string, TemplateAdminField[]> = {};
|
||||||
|
for (const section of sections) {
|
||||||
|
for (const field of section.fields) {
|
||||||
|
if (!field.previewTarget) continue;
|
||||||
|
(result[field.previewTarget] ??= []).push(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
export function buildOfferingPreviewWorkspace(options: {
|
export function buildOfferingPreviewWorkspace(options: {
|
||||||
previewWorkspace: RuntimeWorkspace;
|
previewWorkspace: RuntimeWorkspace;
|
||||||
editingOffering: Offering;
|
editingOffering: Offering;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export function useOfferingEditor(templateFields: TemplateAdminField[]) {
|
|||||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||||
const [offeringDraftVersion, setOfferingDraftVersion] = useState(0);
|
const [offeringDraftVersion, setOfferingDraftVersion] = useState(0);
|
||||||
const [previewPage, setPreviewPage] = useState<OfferingPreviewPage>("detail");
|
const [previewPage, setPreviewPage] = useState<OfferingPreviewPage>("detail");
|
||||||
|
const [previewTargetKey, setPreviewTargetKey] = useState<string>();
|
||||||
const [formValues, setFormValues] = useState<Record<string, unknown>>({});
|
const [formValues, setFormValues] = useState<Record<string, unknown>>({});
|
||||||
|
|
||||||
const templateFieldSection = useMemo<TemplateAdminSection>(
|
const templateFieldSection = useMemo<TemplateAdminSection>(
|
||||||
@@ -32,6 +33,7 @@ export function useOfferingEditor(templateFields: TemplateAdminField[]) {
|
|||||||
const beginOffering = (item?: Offering) => {
|
const beginOffering = (item?: Offering) => {
|
||||||
setEditingOffering(item ?? null);
|
setEditingOffering(item ?? null);
|
||||||
setPreviewPage("detail");
|
setPreviewPage("detail");
|
||||||
|
setPreviewTargetKey(undefined);
|
||||||
setOfferingOpen(true);
|
setOfferingOpen(true);
|
||||||
offeringForm.setFieldsValue(
|
offeringForm.setFieldsValue(
|
||||||
item
|
item
|
||||||
@@ -44,9 +46,19 @@ export function useOfferingEditor(templateFields: TemplateAdminField[]) {
|
|||||||
const closeOffering = () => {
|
const closeOffering = () => {
|
||||||
setOfferingOpen(false);
|
setOfferingOpen(false);
|
||||||
setEditingOffering(null);
|
setEditingOffering(null);
|
||||||
|
setPreviewTargetKey(undefined);
|
||||||
offeringForm.resetFields();
|
offeringForm.resetFields();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 预览与右侧表单共用同一份选中状态:点选区块即定位到对应字段。
|
||||||
|
const selectPreviewTarget = (targetKey?: string) => setPreviewTargetKey(targetKey);
|
||||||
|
|
||||||
|
// 列表与详情是两张不同的页面,切换时清空区块选中,避免沿用另一页的 key。
|
||||||
|
const changePreviewPage = (page: OfferingPreviewPage) => {
|
||||||
|
setPreviewPage(page);
|
||||||
|
setPreviewTargetKey(undefined);
|
||||||
|
};
|
||||||
|
|
||||||
const handleValuesChange = (_: unknown, allValues: Record<string, unknown>) => {
|
const handleValuesChange = (_: unknown, allValues: Record<string, unknown>) => {
|
||||||
setFormValues(allValues);
|
setFormValues(allValues);
|
||||||
setOfferingDraftVersion((version) => version + 1);
|
setOfferingDraftVersion((version) => version + 1);
|
||||||
@@ -60,7 +72,9 @@ export function useOfferingEditor(templateFields: TemplateAdminField[]) {
|
|||||||
templateFieldSection,
|
templateFieldSection,
|
||||||
formValues,
|
formValues,
|
||||||
offeringDraftVersion,
|
offeringDraftVersion,
|
||||||
setPreviewPage,
|
previewTargetKey,
|
||||||
|
changePreviewPage,
|
||||||
|
selectPreviewTarget,
|
||||||
beginOffering,
|
beginOffering,
|
||||||
closeOffering,
|
closeOffering,
|
||||||
handleValuesChange,
|
handleValuesChange,
|
||||||
|
|||||||
@@ -189,6 +189,16 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
|
|||||||
await expect(editor.locator(".service-offering-editor__view")).toContainText("详情内容");
|
await expect(editor.locator(".service-offering-editor__view")).toContainText("详情内容");
|
||||||
await expect(page.getByText("正在核对详情展示")).toBeVisible();
|
await expect(page.getByText("正在核对详情展示")).toBeVisible();
|
||||||
|
|
||||||
|
await preview.locator(".food-detail .hero-copy").click();
|
||||||
|
await expect(preview).toHaveAttribute(
|
||||||
|
"data-active-target",
|
||||||
|
"acheng-campus-food.detail.dishDetail",
|
||||||
|
);
|
||||||
|
await expect(page.getByText("餐品与服务详情对应字段", { exact: true })).toBeVisible();
|
||||||
|
await expect(
|
||||||
|
editor.locator('[data-presentation-binding="offering.config.details.background"]'),
|
||||||
|
).toHaveClass(/is-preview-active/);
|
||||||
|
|
||||||
await page.getByLabel("餐品介绍").fill("弹窗编辑后的餐品介绍");
|
await page.getByLabel("餐品介绍").fill("弹窗编辑后的餐品介绍");
|
||||||
await expect(preview.locator(".food-detail .body")).toContainText("弹窗编辑后的餐品介绍");
|
await expect(preview.locator(".food-detail .body")).toContainText("弹窗编辑后的餐品介绍");
|
||||||
|
|
||||||
@@ -197,6 +207,25 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
|
|||||||
await expect(preview).toHaveAttribute("data-active-target", "acheng-campus-food.offerings.item");
|
await expect(preview).toHaveAttribute("data-active-target", "acheng-campus-food.offerings.item");
|
||||||
await expect(page.getByText("正在核对列表展示")).toBeVisible();
|
await expect(page.getByText("正在核对列表展示")).toBeVisible();
|
||||||
|
|
||||||
|
await preview.locator(".offering-card .dish-name").click();
|
||||||
|
await expect(page.getByText("业务卡片对应字段", { exact: true })).toBeVisible();
|
||||||
|
await expect(editor.locator('[data-presentation-binding="offering.name"]')).toHaveClass(
|
||||||
|
/is-preview-active/,
|
||||||
|
);
|
||||||
|
await expect(
|
||||||
|
editor.locator('[data-presentation-binding="offering.config.details.background"]'),
|
||||||
|
).toHaveCount(0);
|
||||||
|
|
||||||
|
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.getByText("详情主图", { exact: true })).toHaveCount(0);
|
||||||
|
|
||||||
|
await preview.locator(".offering-card .dish-name").click();
|
||||||
|
await expect(page.getByText("业务卡片对应字段", { exact: true })).toBeVisible();
|
||||||
await page.getByLabel("名称", { exact: true }).fill("列表实时预览餐品");
|
await page.getByLabel("名称", { exact: true }).fill("列表实时预览餐品");
|
||||||
await expect(preview.locator(".offering-card")).toContainText("列表实时预览餐品");
|
await expect(preview.locator(".offering-card")).toContainText("列表实时预览餐品");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user