Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa2b6f35b0 | ||
|
|
29116678aa | ||
|
|
b6fedd9f63 |
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"scope": "模板完成证据登记,保留命令、日志与产物哈希",
|
||||
"generatedAt": "2026-10-29T04:18:53.512Z",
|
||||
"generatedAt": "2026-10-29T06:24:26.667Z",
|
||||
"templates": {
|
||||
"acheng-campus-food": {
|
||||
"real-manifest-interaction": {
|
||||
@@ -256,5 +256,5 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"sourceTreeHash": "c360b68fa3e19dc9aab34eef007e6a6fa8cd502809a494324b537198c4c1a0eb"
|
||||
"sourceTreeHash": "5d81aec11fe39aa90095a7855b1cef41d7d48efc92aa19f7c9fd9a2c0b872b11"
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type PresentationValues,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import type { RecordContentSource } from "./types.js";
|
||||
import { getFullFormValues } from "../../lib/form-values.js";
|
||||
|
||||
function createInitialValues(
|
||||
record: Offering | TrustContent,
|
||||
@@ -96,12 +97,12 @@ export function useRecordContentEditorState({
|
||||
});
|
||||
|
||||
const submit = (values: PresentationValues) => {
|
||||
const currentValues = form.getFieldsValue(true) as PresentationValues;
|
||||
const currentValues = getFullFormValues<PresentationValues>(form);
|
||||
save.mutate({ ...draftValues, ...values, ...currentValues });
|
||||
};
|
||||
|
||||
const handleValuesChange = (_values: PresentationValues) => {
|
||||
const currentValues = form.getFieldsValue(true) as PresentationValues;
|
||||
const currentValues = getFullFormValues<PresentationValues>(form);
|
||||
const next = { ...draftValues, ..._values, ...currentValues };
|
||||
setDraftValues(next);
|
||||
onDraft?.(next);
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import { fieldTargetTitle } from "./presentation-editor-helpers.js";
|
||||
import type { PreviewTarget } from "./preview-selection.js";
|
||||
import { getFullFormValues } from "../../lib/form-values.js";
|
||||
|
||||
interface PresentationFormPanelProps {
|
||||
form: FormInstance<PresentationValues>;
|
||||
@@ -44,7 +45,7 @@ export function PresentationFormPanel({
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
onValuesChange={onValuesChange}
|
||||
onFinish={() => save.mutate(form.getFieldsValue(true) as PresentationValues)}
|
||||
onFinish={() => save.mutate(getFullFormValues<PresentationValues>(form))}
|
||||
className="presentation-editor__form"
|
||||
>
|
||||
<div className="presentation-editor__form-body">
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
TrustContent,
|
||||
} from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { getFullFormValues } from "../../lib/form-values.js";
|
||||
import {
|
||||
applyBrandPreviewValues,
|
||||
applyPresentationValues,
|
||||
@@ -161,7 +162,7 @@ export function useBrandPreviewDraft({
|
||||
const handleValuesChange = (changed: PresentationValues, allValues: PresentationValues) => {
|
||||
onDirty();
|
||||
const synchronized: PresentationValues = {
|
||||
...(form.getFieldsValue(true) as PresentationValues),
|
||||
...getFullFormValues<PresentationValues>(form),
|
||||
...allValues,
|
||||
};
|
||||
for (const section of sections) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
||||
import type { PreviewSelection, PreviewTarget } from "../brand/preview-selection.js";
|
||||
import type { FormInstance } from "antd";
|
||||
import "./ServicesPage.css";
|
||||
import { getFullFormValues } from "../../lib/form-values.js";
|
||||
|
||||
type OfferingEditorModalProps = {
|
||||
open: boolean;
|
||||
@@ -140,7 +141,7 @@ export function OfferingEditorModal({
|
||||
onValuesChange={(_, allValues) => onValuesChange(allValues)}
|
||||
// 动态隐藏的字段会被卸载,onFinish 默认只返回仍挂载的字段。
|
||||
// 提交时读取完整表单存储,避免切换区块后隐藏字段的修改丢失。
|
||||
onFinish={() => onFinish(form.getFieldsValue(true) as Record<string, unknown>)}
|
||||
onFinish={() => onFinish(getFullFormValues(form))}
|
||||
>
|
||||
<div ref={formScroll} className="service-offering-editor__form-scroll">
|
||||
{selectedTarget ? (
|
||||
|
||||
@@ -9,6 +9,7 @@ import { OfferingsTable } from "./OfferingsTable.js";
|
||||
import { detailPageLabel, hasTemplateDetailCopy, offeringPageLabel } from "./offering-model.js";
|
||||
import {
|
||||
buildOfferingPreviewWorkspace,
|
||||
pageTemplateFields as collectPageTemplateFields,
|
||||
previewFieldsByTarget,
|
||||
previewTargetsByPage,
|
||||
} from "./offering-preview.js";
|
||||
@@ -45,17 +46,16 @@ export function ServicesPage() {
|
||||
);
|
||||
// 页面级字段必须按该页所有真实预览区域收集,不能只取列表/详情首个区域,
|
||||
// 否则模板把详情拆成多个区域后,未点选的“全部字段”会漏掉后续区域。
|
||||
const pageTemplateFields = useMemo<TemplateAdminField[]>(() => {
|
||||
const targets =
|
||||
editor.previewPage === "offerings" ? previewTargets.offerings : previewTargets.detail;
|
||||
const targetKeys = new Set(targets.map((target) => target.key));
|
||||
return templateFields.filter(
|
||||
(field) =>
|
||||
(field.previewTarget && targetKeys.has(field.previewTarget)) ||
|
||||
(!field.previewTarget &&
|
||||
field.page === (editor.previewPage === "offerings" ? listTarget?.page : "detail")),
|
||||
);
|
||||
}, [editor.previewPage, listTarget?.page, previewTargets, templateFields]);
|
||||
const pageTemplateFields = useMemo<TemplateAdminField[]>(
|
||||
() =>
|
||||
collectPageTemplateFields({
|
||||
previewPage: editor.previewPage,
|
||||
previewTargets,
|
||||
templateFields,
|
||||
listPage: listTarget?.page,
|
||||
}),
|
||||
[editor.previewPage, listTarget?.page, previewTargets, templateFields],
|
||||
);
|
||||
// 点选预览区块后,右侧只保留该区块对应的字段,与小程序页面点选编辑保持一致。
|
||||
const selectedTarget = useMemo(() => {
|
||||
if (!editor.previewTargetKey) return undefined;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client";
|
||||
import type { PreviewTarget } from "../brand/preview-selection.js";
|
||||
|
||||
export function previewTargetsByPage(
|
||||
sections: AdminTemplateContent["admin"]["sections"],
|
||||
): Record<"offerings" | "detail", PreviewTarget[]> {
|
||||
const targets = sections.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
page: section.page,
|
||||
source: section.fields.some(
|
||||
(field) => field.binding.startsWith("offering.") && field.previewTarget === target.key,
|
||||
)
|
||||
? ("offering" as const)
|
||||
: section.target,
|
||||
})),
|
||||
);
|
||||
const pages = [...new Set(sections.map((section) => section.page))];
|
||||
const offeringPages = pages.filter(
|
||||
(page) =>
|
||||
page !== "detail" &&
|
||||
targets.some((target) => target.page === page && target.source === "offering"),
|
||||
);
|
||||
// 业务卡片不一定在“服务页”:独立工坊把案例卡片放在首页。优先使用专门的
|
||||
// offerings 页,没有时退回第一个包含业务记录的页面。
|
||||
const listPage = offeringPages.find((page) => page === "offerings") ?? offeringPages[0];
|
||||
return {
|
||||
offerings: listPage ? targets.filter((target) => target.page === listPage) : [],
|
||||
detail: targets.filter((target) => target.page === "detail"),
|
||||
};
|
||||
}
|
||||
|
||||
export function pageTemplateFields(options: {
|
||||
previewPage: "offerings" | "detail";
|
||||
previewTargets: Record<"offerings" | "detail", PreviewTarget[]>;
|
||||
templateFields: TemplateAdminField[];
|
||||
listPage?: string | undefined;
|
||||
}): TemplateAdminField[] {
|
||||
const { previewPage, previewTargets, templateFields, listPage } = options;
|
||||
const targets = previewPage === "offerings" ? previewTargets.offerings : previewTargets.detail;
|
||||
const targetKeys = new Set(targets.map((target) => target.key));
|
||||
return templateFields.filter(
|
||||
(field) =>
|
||||
(field.previewTarget && targetKeys.has(field.previewTarget)) ||
|
||||
(!field.previewTarget && field.page === (previewPage === "offerings" ? listPage : "detail")),
|
||||
);
|
||||
}
|
||||
@@ -1,41 +1,13 @@
|
||||
export { pageTemplateFields, previewTargetsByPage } from "./offering-preview-targets.js";
|
||||
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
Offering,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminField,
|
||||
} from "@personal-brand/api-client";
|
||||
import type { PreviewTarget } from "../brand/preview-selection.js";
|
||||
import { applyPresentationValues } from "../../lib/presentation/presentation-bindings.js";
|
||||
|
||||
export function previewTargetsByPage(
|
||||
sections: AdminTemplateContent["admin"]["sections"],
|
||||
): Record<"offerings" | "detail", PreviewTarget[]> {
|
||||
const targets = sections.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
page: section.page,
|
||||
source: section.fields.some(
|
||||
(field) => field.binding.startsWith("offering.") && field.previewTarget === target.key,
|
||||
)
|
||||
? ("offering" as const)
|
||||
: section.target,
|
||||
})),
|
||||
);
|
||||
const pages = [...new Set(sections.map((section) => section.page))];
|
||||
const offeringPages = pages.filter(
|
||||
(page) =>
|
||||
page !== "detail" &&
|
||||
targets.some((target) => target.page === page && target.source === "offering"),
|
||||
);
|
||||
// 业务卡片不一定在“服务页”:独立工坊把案例卡片放在首页。优先使用专门的
|
||||
// offerings 页,没有时退回第一个包含业务记录的页面。
|
||||
const listPage = offeringPages.find((page) => page === "offerings") ?? offeringPages[0];
|
||||
return {
|
||||
offerings: listPage ? targets.filter((target) => target.page === listPage) : [],
|
||||
detail: targets.filter((target) => target.page === "detail"),
|
||||
};
|
||||
}
|
||||
|
||||
export function previewFieldsByTarget(
|
||||
sections: AdminTemplateContent["admin"]["sections"],
|
||||
): Record<string, TemplateAdminField[]> {
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
import { offeringDefaultFormValues, offeringEditFormValues } from "./offering-form.js";
|
||||
import { getFullFormValues } from "../../lib/form-values.js";
|
||||
|
||||
export type OfferingPreviewPage = "offerings" | "detail";
|
||||
|
||||
@@ -40,7 +41,7 @@ export function useOfferingEditor(templateFields: TemplateAdminField[]) {
|
||||
? offeringEditFormValues(item, templateFields)
|
||||
: offeringDefaultFormValues(templateFields),
|
||||
);
|
||||
setFormValues(offeringForm.getFieldsValue(true) as Record<string, unknown>);
|
||||
setFormValues(getFullFormValues(offeringForm));
|
||||
};
|
||||
|
||||
const closeOffering = () => {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { FormInstance } from "antd";
|
||||
|
||||
// 动态隐藏的字段会被 Ant Design Form 卸载,onFinish 默认只返回仍挂载的字段。
|
||||
// 提交时读取完整表单存储,避免切换区块后隐藏字段的修改丢失。
|
||||
export function getFullFormValues<T = Record<string, unknown>>(form: FormInstance): T {
|
||||
return form.getFieldsValue(true) as T;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import {
|
||||
pageTemplateFields,
|
||||
previewTargetsByPage,
|
||||
} from "../src/features/services/offering-preview-targets.ts";
|
||||
|
||||
function section(page, target, fields) {
|
||||
return {
|
||||
key: `${page}-${target}`,
|
||||
title: target,
|
||||
description: "",
|
||||
page,
|
||||
target,
|
||||
fields,
|
||||
previewTargets: [{ key: `${page}.${target}`, label: target }],
|
||||
};
|
||||
}
|
||||
|
||||
test("previewTargetsByPage prefers the offerings page for list targets", () => {
|
||||
const sections = [
|
||||
section("home", "homeCard", [{ binding: "offering.name", previewTarget: "home.homeCard" }]),
|
||||
section("offerings", "offeringCard", [
|
||||
{ binding: "offering.name", previewTarget: "offerings.offeringCard" },
|
||||
]),
|
||||
section("detail", "projectHero", [
|
||||
{ binding: "offering.name", previewTarget: "detail.projectHero" },
|
||||
]),
|
||||
];
|
||||
|
||||
const result = previewTargetsByPage(sections);
|
||||
assert.deepEqual(
|
||||
result.offerings.map((target) => target.key),
|
||||
["offerings.offeringCard"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
result.detail.map((target) => target.key),
|
||||
["detail.projectHero"],
|
||||
);
|
||||
});
|
||||
|
||||
test("previewTargetsByPage falls back to the first non-detail page with offering records", () => {
|
||||
const sections = [
|
||||
section("home", "homeCard", [{ binding: "offering.name", previewTarget: "home.homeCard" }]),
|
||||
section("detail", "projectHero", []),
|
||||
];
|
||||
|
||||
const result = previewTargetsByPage(sections);
|
||||
assert.equal(result.offerings.length, 1);
|
||||
assert.equal(result.offerings[0].key, "home.homeCard");
|
||||
assert.equal(result.offerings[0].source, "offering");
|
||||
});
|
||||
|
||||
test("previewTargetsByPage returns no list targets without offering-backed pages", () => {
|
||||
const sections = [
|
||||
section("detail", "projectHero", [
|
||||
{ binding: "brand.name", previewTarget: "detail.projectHero" },
|
||||
]),
|
||||
];
|
||||
|
||||
const result = previewTargetsByPage(sections);
|
||||
assert.deepEqual(result.offerings, []);
|
||||
assert.deepEqual(
|
||||
result.detail.map((target) => target.key),
|
||||
["detail.projectHero"],
|
||||
);
|
||||
assert.notEqual(result.detail[0].source, "offering");
|
||||
});
|
||||
|
||||
test("pageTemplateFields collects every detail target field", () => {
|
||||
const previewTargets = previewTargetsByPage([
|
||||
section("detail", "projectHero", [
|
||||
{ binding: "offering.name", previewTarget: "detail.projectHero" },
|
||||
]),
|
||||
section("detail", "projectFacts", [
|
||||
{ binding: "offering.priceText", previewTarget: "detail.projectFacts" },
|
||||
]),
|
||||
section("home", "homeCard", [{ binding: "offering.summary", previewTarget: "home.homeCard" }]),
|
||||
]);
|
||||
const templateFields = [
|
||||
{ key: "name", binding: "offering.name", previewTarget: "detail.projectHero" },
|
||||
{ key: "priceText", binding: "offering.priceText", previewTarget: "detail.projectFacts" },
|
||||
{ key: "summary", binding: "offering.summary", previewTarget: "home.homeCard" },
|
||||
];
|
||||
|
||||
const result = pageTemplateFields({
|
||||
previewPage: "detail",
|
||||
previewTargets,
|
||||
templateFields,
|
||||
});
|
||||
assert.deepEqual(
|
||||
result.map((field) => field.key),
|
||||
["name", "priceText"],
|
||||
);
|
||||
});
|
||||
|
||||
test("pageTemplateFields falls back to page fields without previewTarget", () => {
|
||||
const previewTargets = previewTargetsByPage([
|
||||
section("detail", "projectHero", [
|
||||
{ binding: "offering.name", previewTarget: "detail.projectHero" },
|
||||
]),
|
||||
]);
|
||||
const templateFields = [
|
||||
{ key: "name", binding: "offering.name", previewTarget: "detail.projectHero" },
|
||||
{ key: "legacy", binding: "offering.config.legacy", page: "detail" },
|
||||
{ key: "other", binding: "offering.config.other", previewTarget: "unknown.target" },
|
||||
];
|
||||
|
||||
const result = pageTemplateFields({
|
||||
previewPage: "detail",
|
||||
previewTargets,
|
||||
templateFields,
|
||||
});
|
||||
assert.deepEqual(
|
||||
result.map((field) => field.key),
|
||||
["name", "legacy"],
|
||||
);
|
||||
});
|
||||
|
||||
test("pageTemplateFields uses the inferred list page for offerings", () => {
|
||||
const previewTargets = previewTargetsByPage([
|
||||
section("home", "homeCard", [{ binding: "offering.name", previewTarget: "home.homeCard" }]),
|
||||
section("detail", "projectHero", []),
|
||||
]);
|
||||
const templateFields = [
|
||||
{ key: "name", binding: "offering.name", previewTarget: "home.homeCard" },
|
||||
{ key: "legacy", binding: "offering.config.legacy", page: "home" },
|
||||
{ key: "detail", binding: "offering.config.detail", previewTarget: "detail.projectHero" },
|
||||
];
|
||||
|
||||
const result = pageTemplateFields({
|
||||
previewPage: "offerings",
|
||||
previewTargets,
|
||||
templateFields,
|
||||
listPage: previewTargets.offerings[0]?.page,
|
||||
});
|
||||
assert.deepEqual(
|
||||
result.map((field) => field.key),
|
||||
["name", "legacy"],
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user