feat: 完善后台可视化模板编辑与区域绑定
This commit is contained in:
1 parent
0b14b5a814
commit
5b85fe769f
18 files changed
+1620
-239
No files matched your search
@@ -1,12 +1,36 @@
|
||||
.component-template-preview-shell {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.component-template-preview__tools {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid #e8e8e8;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.component-template-preview__tools button {
|
||||
padding: 4px 12px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.component-template-preview__tools button[aria-pressed="true"] {
|
||||
border-color: #1677ff;
|
||||
color: #1677ff;
|
||||
}
|
||||
|
||||
.component-template-preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: min(76vh, 820px);
|
||||
min-height: 620px;
|
||||
height: calc(100% - 49px);
|
||||
min-height: 510px;
|
||||
padding: 24px 16px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #e8e8e8;
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
@@ -61,42 +85,36 @@
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.component-template-preview [data-editor-target] {
|
||||
position: relative;
|
||||
.component-template-preview[data-editor-mode="edit"] [data-editor-target] {
|
||||
cursor: pointer;
|
||||
outline: 2px solid transparent;
|
||||
outline-offset: 3px;
|
||||
transition:
|
||||
outline-color 120ms ease,
|
||||
background-color 120ms ease,
|
||||
box-shadow 120ms ease;
|
||||
}
|
||||
|
||||
.component-template-preview [data-editor-target]:hover {
|
||||
outline-color: #91caff;
|
||||
background-color: rgba(22, 119, 255, 0.04);
|
||||
}
|
||||
|
||||
.component-template-preview [data-editor-target].editor-target-selected {
|
||||
z-index: 2;
|
||||
outline: 2px solid #1677ff;
|
||||
outline-offset: 4px;
|
||||
background-color: rgba(22, 119, 255, 0.1);
|
||||
box-shadow: 0 0 0 5px rgba(22, 119, 255, 0.14);
|
||||
}
|
||||
|
||||
.component-template-preview [data-editor-target].editor-target-selected::before {
|
||||
.component-template-preview__outline {
|
||||
position: absolute;
|
||||
top: -10px;
|
||||
left: -2px;
|
||||
z-index: 3;
|
||||
padding: 2px 7px;
|
||||
z-index: 5;
|
||||
pointer-events: none;
|
||||
border: 2px solid #91caff;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.component-template-preview__outline.is-selected {
|
||||
z-index: 6;
|
||||
border-color: #1677ff;
|
||||
box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.16);
|
||||
}
|
||||
|
||||
.component-template-preview__outline span {
|
||||
position: absolute;
|
||||
bottom: 100%;
|
||||
left: 0;
|
||||
max-width: 100%;
|
||||
padding: 2px 7px;
|
||||
overflow: hidden;
|
||||
border-radius: 4px 4px 0 0;
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
content: attr(data-editor-target);
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
pointer-events: none;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||
import { Alert } from "antd";
|
||||
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
||||
import type { PreviewSelection, PreviewTarget } from "./preview-selection.js";
|
||||
import "../../../../../packages/template-acheng-campus-food/taro/style.css";
|
||||
import "../../../../../packages/template-linjing-editorial/taro/style.css";
|
||||
import "./ComponentTemplatePreview.css";
|
||||
@@ -9,54 +11,177 @@ type PreviewProps = {
|
||||
workspace: RuntimeWorkspace;
|
||||
page: string;
|
||||
offeringId?: string;
|
||||
targetKey?: string;
|
||||
onTargetSelected: (targetKey: string) => void;
|
||||
selection?: PreviewSelection;
|
||||
targets: PreviewTarget[];
|
||||
onTargetSelected: (selection?: PreviewSelection) => void;
|
||||
};
|
||||
|
||||
type Outline = { top: number; left: number; width: number; height: number; label: string };
|
||||
|
||||
export function ComponentTemplatePreview({
|
||||
workspace,
|
||||
page,
|
||||
offeringId,
|
||||
targetKey,
|
||||
selection,
|
||||
targets,
|
||||
onTargetSelected,
|
||||
}: PreviewProps) {
|
||||
const Renderer = resolveTemplateRenderer(workspace);
|
||||
const root = useRef<HTMLDivElement>(null);
|
||||
const [mode, setMode] = useState<"edit" | "browse">("edit");
|
||||
const [hovered, setHovered] = useState<HTMLElement | null>(null);
|
||||
const [hoverOutline, setHoverOutline] = useState<Outline | null>(null);
|
||||
const [selectedOutline, setSelectedOutline] = useState<Outline | null>(null);
|
||||
const targetFor = useCallback(
|
||||
(element: Element | null): HTMLElement | null => {
|
||||
let candidate = element?.closest<HTMLElement>("[data-editor-target]");
|
||||
while (candidate && root.current?.contains(candidate)) {
|
||||
if (targets.some((target) => target.key === candidate?.dataset.editorTarget))
|
||||
return candidate;
|
||||
candidate = candidate.parentElement?.closest<HTMLElement>("[data-editor-target]") ?? null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
[targets],
|
||||
);
|
||||
const selectedElement = useCallback(() => {
|
||||
if (!selection) return null;
|
||||
return (
|
||||
Array.from(root.current?.querySelectorAll<HTMLElement>("[data-editor-target]") ?? []).find(
|
||||
(element) =>
|
||||
element.dataset.editorTarget === selection.targetKey &&
|
||||
(element.dataset.editorRecordId || undefined) === selection.recordId,
|
||||
) ?? null
|
||||
);
|
||||
}, [selection]);
|
||||
const measure = useCallback(
|
||||
(element: HTMLElement | null): Outline | null => {
|
||||
const viewport = root.current;
|
||||
if (!element || !viewport || !viewport.contains(element)) return null;
|
||||
const box = element.getBoundingClientRect();
|
||||
const parent = viewport.getBoundingClientRect();
|
||||
const target = targets.find((item) => item.key === element.dataset.editorTarget);
|
||||
if (!target || !box.width || !box.height) return null;
|
||||
return {
|
||||
top: box.top - parent.top + viewport.scrollTop,
|
||||
left: box.left - parent.left + viewport.scrollLeft,
|
||||
width: box.width,
|
||||
height: box.height,
|
||||
label: target.label,
|
||||
};
|
||||
},
|
||||
[targets],
|
||||
);
|
||||
useLayoutEffect(() => {
|
||||
const viewport = root.current;
|
||||
if (!viewport) return;
|
||||
let frame = 0;
|
||||
const update = () => {
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
setSelectedOutline(measure(selectedElement()));
|
||||
setHoverOutline(measure(hovered));
|
||||
});
|
||||
};
|
||||
update();
|
||||
const resize = new ResizeObserver(update);
|
||||
resize.observe(viewport);
|
||||
viewport
|
||||
.querySelectorAll<HTMLElement>("[data-editor-target]")
|
||||
.forEach((node) => resize.observe(node));
|
||||
window.addEventListener("resize", update);
|
||||
viewport.addEventListener("scroll", update);
|
||||
viewport.addEventListener("load", update, true);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
resize.disconnect();
|
||||
window.removeEventListener("resize", update);
|
||||
viewport.removeEventListener("scroll", update);
|
||||
viewport.removeEventListener("load", update, true);
|
||||
};
|
||||
}, [hovered, measure, selectedElement, workspace, page]);
|
||||
useEffect(() => {
|
||||
root.current?.querySelectorAll<HTMLElement>("[data-editor-target]").forEach((element) => {
|
||||
element.classList.toggle(
|
||||
"editor-target-selected",
|
||||
element.dataset.editorTarget === targetKey,
|
||||
);
|
||||
});
|
||||
const selected = targetKey
|
||||
? root.current?.querySelector<HTMLElement>(`[data-editor-target="${CSS.escape(targetKey)}"]`)
|
||||
: null;
|
||||
selected?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||
}, [targetKey, workspace, page]);
|
||||
selectedElement()?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||
}, [selectedElement]);
|
||||
useEffect(() => {
|
||||
const clear = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") onTargetSelected(undefined);
|
||||
};
|
||||
window.addEventListener("keydown", clear);
|
||||
return () => window.removeEventListener("keydown", clear);
|
||||
}, [onTargetSelected]);
|
||||
if (!Renderer)
|
||||
return <Alert type="warning" showIcon message="此模板尚无组件预览,请使用页面预览" />;
|
||||
return (
|
||||
<div
|
||||
ref={root}
|
||||
className="component-template-preview"
|
||||
data-active-target={targetKey || undefined}
|
||||
onClickCapture={(event) => {
|
||||
const element =
|
||||
event.target instanceof Element
|
||||
? event.target.closest<HTMLElement>("[data-editor-target]")
|
||||
: null;
|
||||
const key = element?.dataset.editorTarget;
|
||||
if (!key) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
onTargetSelected(key);
|
||||
}}
|
||||
>
|
||||
<div className="component-template-preview__canvas">
|
||||
<Renderer workspace={workspace} page={page} {...(offeringId ? { offeringId } : {})} />
|
||||
<div className="component-template-preview-shell">
|
||||
<div className="component-template-preview__tools" aria-label="预览操作模式">
|
||||
<button type="button" aria-pressed={mode === "edit"} onClick={() => setMode("edit")}>
|
||||
点选编辑
|
||||
</button>
|
||||
<button type="button" aria-pressed={mode === "browse"} onClick={() => setMode("browse")}>
|
||||
浏览页面
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
ref={root}
|
||||
className="component-template-preview"
|
||||
data-active-target={selection?.targetKey}
|
||||
data-active-record-id={selection?.recordId}
|
||||
data-editor-mode={mode}
|
||||
onPointerMoveCapture={(event) => {
|
||||
if (mode !== "edit") return;
|
||||
const next = targetFor(event.target instanceof Element ? event.target : null);
|
||||
if (next !== hovered) setHovered(next);
|
||||
}}
|
||||
onPointerLeave={() => setHovered(null)}
|
||||
onClickCapture={(event) => {
|
||||
if (mode !== "edit") return;
|
||||
const element = targetFor(event.target instanceof Element ? event.target : null);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
onTargetSelected(
|
||||
element
|
||||
? {
|
||||
targetKey: element.dataset.editorTarget!,
|
||||
...(element.dataset.editorRecordId
|
||||
? { recordId: element.dataset.editorRecordId }
|
||||
: {}),
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<div className="component-template-preview__canvas">
|
||||
<Renderer workspace={workspace} page={page} {...(offeringId ? { offeringId } : {})} />
|
||||
</div>
|
||||
{mode === "edit" && hoverOutline ? (
|
||||
<div
|
||||
className="component-template-preview__outline is-hovered"
|
||||
style={{
|
||||
top: hoverOutline.top,
|
||||
left: hoverOutline.left,
|
||||
width: hoverOutline.width,
|
||||
height: hoverOutline.height,
|
||||
}}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : null}
|
||||
{mode === "edit" && selectedOutline ? (
|
||||
<div
|
||||
className="component-template-preview__outline is-selected"
|
||||
style={{
|
||||
top: selectedOutline.top,
|
||||
left: selectedOutline.left,
|
||||
width: selectedOutline.width,
|
||||
height: selectedOutline.height,
|
||||
}}
|
||||
data-selected-target={selection?.targetKey}
|
||||
data-selected-record-id={selection?.recordId}
|
||||
>
|
||||
<span>{selectedOutline.label}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
{targetKey ? (
|
||||
<div className="component-template-preview__selection" data-selected-target={targetKey} />
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,24 +16,29 @@ import {
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminField,
|
||||
TemplateAdminSection,
|
||||
Offering,
|
||||
TrustContent,
|
||||
} from "@personal-brand/api-client";
|
||||
import type { BrandProfile } from "@personal-brand/api-client";
|
||||
import { projectBrandAliases } from "@personal-brand/api-client";
|
||||
import { projectBrandAliases, projectTrustPresentation } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
import { TemplatePreview } from "./TemplatePreview.js";
|
||||
import { resolvePreviewSelection, type PreviewSelection } from "./preview-selection.js";
|
||||
import {
|
||||
applyBrandPreviewValues,
|
||||
applyStandardBrandValues,
|
||||
applyStandardEntityValues,
|
||||
applyPresentationValues,
|
||||
filterSectionsForPreviewTarget,
|
||||
presentationFieldName,
|
||||
@@ -50,6 +55,47 @@ interface PresentationEditorProps {
|
||||
error?: unknown;
|
||||
}
|
||||
|
||||
function trustSection(
|
||||
declaration: NonNullable<AdminTemplateContent["trustContentTypes"]>[number],
|
||||
page: string,
|
||||
): TemplateAdminSection {
|
||||
const key = `trust:${declaration.type}`;
|
||||
return {
|
||||
key,
|
||||
title: declaration.label,
|
||||
description: declaration.help ?? "编辑当前展示内容。",
|
||||
page,
|
||||
target: "trust",
|
||||
previewTargets: [{ key, label: declaration.label }],
|
||||
fields: [
|
||||
{
|
||||
key: "title",
|
||||
binding: "trust.title",
|
||||
label: declaration.adminFields.title,
|
||||
input: "text" as const,
|
||||
required: true,
|
||||
},
|
||||
...(["summary", "content"] as const)
|
||||
.filter((field) => !declaration.hideStandardFields?.includes(field))
|
||||
.map((field) => ({
|
||||
key: field,
|
||||
binding: `trust.${field}`,
|
||||
label: declaration.adminFields[field],
|
||||
input: "textarea" as const,
|
||||
previewTarget: `trust:${declaration.type}`,
|
||||
...(field === "summary" && declaration.adminFields.summaryHelp
|
||||
? { help: declaration.adminFields.summaryHelp }
|
||||
: {}),
|
||||
...(field === "content" && declaration.required ? { required: true } : {}),
|
||||
})),
|
||||
...(declaration.configFields ?? []).map((field) => ({
|
||||
...field,
|
||||
previewTarget: `trust:${declaration.type}`,
|
||||
})),
|
||||
].map((field) => ({ ...field, previewTarget: `trust:${declaration.type}` })),
|
||||
};
|
||||
}
|
||||
|
||||
function renderField(field: TemplateAdminField) {
|
||||
if (field.input === "textarea")
|
||||
return (
|
||||
@@ -102,7 +148,13 @@ export function PresentationEditor({
|
||||
const navigate = useNavigate();
|
||||
const breakpoints = Grid.useBreakpoint();
|
||||
const [activePage, setActivePage] = useState<string>();
|
||||
const [activeTarget, setActiveTarget] = useState<string>();
|
||||
const [selection, setSelection] = useState<PreviewSelection>();
|
||||
const [detailOfferingId, setDetailOfferingId] = useState<string>();
|
||||
const [recordDraft, setRecordDraft] = useState<{
|
||||
source: "offering" | "trust";
|
||||
id: string;
|
||||
values: PresentationValues;
|
||||
}>();
|
||||
const [previewConfig, setPreviewConfig] = useState(config ?? {});
|
||||
const [previewBrandValues, setPreviewBrandValues] = useState<Record<string, unknown>>({});
|
||||
const sections = useMemo(() => {
|
||||
@@ -153,24 +205,83 @@ export function PresentationEditor({
|
||||
? activePage
|
||||
: pageOptions[0]?.value;
|
||||
const visibleSections = sections.filter((section) => section.page === selectedPage);
|
||||
const visibleTargets = (templateContent?.admin.sections ?? [])
|
||||
.filter((section) => section.page === selectedPage)
|
||||
.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
page: section.page,
|
||||
source: section.target,
|
||||
})),
|
||||
);
|
||||
const selectedTarget = visibleTargets.find((target) => target.key === activeTarget);
|
||||
const selectedSection = (templateContent?.admin.sections ?? []).find((section) =>
|
||||
section.previewTargets?.some((target) => target.key === selectedTarget?.key),
|
||||
const recordSections = useMemo(
|
||||
() =>
|
||||
(templateContent?.trustContentTypes ?? [])
|
||||
.filter((item) => item.pages?.includes(selectedPage ?? ""))
|
||||
.map((item) => trustSection(item, selectedPage ?? "home")),
|
||||
[templateContent, selectedPage],
|
||||
);
|
||||
const visibleTargets = useMemo(
|
||||
() =>
|
||||
[...(templateContent?.admin.sections ?? []), ...recordSections]
|
||||
.filter((section) => section.page === selectedPage)
|
||||
.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
page: section.page,
|
||||
source: section.target,
|
||||
})),
|
||||
),
|
||||
[templateContent, selectedPage, recordSections],
|
||||
);
|
||||
const activeTarget = selection?.targetKey;
|
||||
const selectedTarget = visibleTargets.find((target) => target.key === activeTarget);
|
||||
const selectedSection = [...(templateContent?.admin.sections ?? []), ...recordSections].find(
|
||||
(section) =>
|
||||
section.page === selectedPage &&
|
||||
section.previewTargets?.some((target) => target.key === selectedTarget?.key),
|
||||
);
|
||||
const selectedRecordSource =
|
||||
selectedTarget?.source === "offering" || selectedTarget?.source === "trust"
|
||||
? selectedTarget.source
|
||||
: undefined;
|
||||
const offeringsQuery = useQuery({
|
||||
queryKey: ["admin-offerings"],
|
||||
queryFn: () => createApiClient().listAdminOfferings(),
|
||||
enabled: selectedRecordSource === "offering",
|
||||
});
|
||||
const trustQuery = useQuery({
|
||||
queryKey: ["trust-content"],
|
||||
queryFn: () => createApiClient().listAdminTrustContent(),
|
||||
enabled: selectedRecordSource === "trust",
|
||||
});
|
||||
const selectedRecord =
|
||||
selectedRecordSource === "offering"
|
||||
? offeringsQuery.data?.find((item) => item.id === selection?.recordId)
|
||||
: selectedRecordSource === "trust"
|
||||
? trustQuery.data?.find((item) => item.id === selection?.recordId)
|
||||
: undefined;
|
||||
const editableSections = filterSectionsForPreviewTarget(
|
||||
visibleSections.filter((section) => section.target === "brand"),
|
||||
selectedTarget?.key,
|
||||
);
|
||||
const handleTargetSelected = useCallback((key: string) => setActiveTarget(key), []);
|
||||
const recordSection = useMemo(
|
||||
() =>
|
||||
selectedSection && selection?.targetKey
|
||||
? {
|
||||
...selectedSection,
|
||||
fields: selectedSection.fields.filter(
|
||||
(field) => field.previewTarget === selection.targetKey,
|
||||
),
|
||||
}
|
||||
: undefined,
|
||||
[selectedSection, selection?.targetKey],
|
||||
);
|
||||
const handleTargetSelected = useCallback(
|
||||
(next?: PreviewSelection) =>
|
||||
setSelection(
|
||||
next
|
||||
? resolvePreviewSelection(
|
||||
next.targetKey,
|
||||
next.recordId,
|
||||
visibleTargets,
|
||||
selectedPage ?? "home",
|
||||
)
|
||||
: undefined,
|
||||
),
|
||||
[visibleTargets, selectedPage],
|
||||
);
|
||||
const relatedTargets = [
|
||||
...(templateContent?.admin.sections ?? [])
|
||||
.filter((section) => section.page === selectedPage && section.target !== "brand")
|
||||
@@ -235,6 +346,7 @@ export function PresentationEditor({
|
||||
window.dispatchEvent(new Event("template-preview-refresh"));
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["publication-readiness"] });
|
||||
},
|
||||
@@ -248,7 +360,24 @@ export function PresentationEditor({
|
||||
if (!pageOptions.some((item) => item.value === activePage))
|
||||
setActivePage(pageOptions[0]?.value);
|
||||
}, [activePage, pageOptions]);
|
||||
useEffect(() => setActiveTarget(undefined), [selectedPage]);
|
||||
useEffect(() => setSelection(undefined), [selectedPage, templateContent?.displayName]);
|
||||
useEffect(() => {
|
||||
if (!selection?.recordId) return;
|
||||
const records =
|
||||
selectedTarget?.source === "trust"
|
||||
? previewWorkspace?.trustItems
|
||||
: previewWorkspace?.offerings;
|
||||
if (records && !records.some((item) => item.id === selection.recordId)) setSelection(undefined);
|
||||
}, [
|
||||
previewWorkspace?.offerings,
|
||||
previewWorkspace?.trustItems,
|
||||
selectedTarget?.source,
|
||||
selection,
|
||||
]);
|
||||
useEffect(
|
||||
() => setRecordDraft(undefined),
|
||||
[selection?.targetKey, selection?.recordId, selectedPage],
|
||||
);
|
||||
useEffect(() => {
|
||||
setPreviewConfig(config ?? {});
|
||||
setPreviewBrandValues({});
|
||||
@@ -270,6 +399,96 @@ export function PresentationEditor({
|
||||
},
|
||||
[brand, config, sections],
|
||||
);
|
||||
const draftWorkspace = useMemo(() => {
|
||||
if (!previewWorkspace) return undefined;
|
||||
const next: RuntimeWorkspace = {
|
||||
...previewWorkspace,
|
||||
brand: projectBrandAliases(
|
||||
{
|
||||
...previewWorkspace.brand,
|
||||
...(previewBrand as unknown as Record<string, unknown>),
|
||||
config: previewConfig,
|
||||
},
|
||||
previewConfig,
|
||||
),
|
||||
};
|
||||
if (!recordDraft || !selectedRecord || !recordSection || recordDraft.id !== selectedRecord.id)
|
||||
return next;
|
||||
const values = recordDraft.values;
|
||||
const config = applyPresentationValues(selectedRecord.config, [recordSection], values);
|
||||
const standard = applyStandardEntityValues(
|
||||
selectedRecord as unknown as Record<string, unknown>,
|
||||
recordDraft.source,
|
||||
[recordSection],
|
||||
values,
|
||||
);
|
||||
if (recordDraft.source === "trust") {
|
||||
next.trustItems = next.trustItems.map((item) =>
|
||||
item.id === recordDraft.id
|
||||
? {
|
||||
...item,
|
||||
title: typeof standard.title === "string" ? standard.title : item.title,
|
||||
summary: typeof standard.summary === "string" ? standard.summary : item.summary,
|
||||
content: typeof standard.content === "string" ? standard.content : item.content,
|
||||
config,
|
||||
}
|
||||
: item,
|
||||
);
|
||||
next.trustPresentation = projectTrustPresentation(
|
||||
next.trustItems,
|
||||
templateContent?.trustContentTypes ?? [],
|
||||
);
|
||||
} else {
|
||||
next.offerings = next.offerings.map((item) =>
|
||||
item.id === recordDraft.id
|
||||
? {
|
||||
...item,
|
||||
name: typeof standard.name === "string" ? standard.name : item.name,
|
||||
summary:
|
||||
typeof standard.summary === "string"
|
||||
? standard.summary
|
||||
: typeof standard.description === "string"
|
||||
? standard.description
|
||||
: item.summary,
|
||||
priceText: typeof standard.priceText === "string" ? standard.priceText : null,
|
||||
coverUrl: typeof standard.coverUrl === "string" ? standard.coverUrl : null,
|
||||
presentation: {
|
||||
...item.presentation,
|
||||
...config,
|
||||
...(config.presentation && typeof config.presentation === "object"
|
||||
? (config.presentation as Record<string, unknown>)
|
||||
: {}),
|
||||
heroImage:
|
||||
typeof config.detailHero === "string"
|
||||
? config.detailHero
|
||||
: typeof standard.coverUrl === "string"
|
||||
? standard.coverUrl
|
||||
: null,
|
||||
details: {
|
||||
...item.presentation.details,
|
||||
...(config.details && typeof config.details === "object"
|
||||
? (config.details as Record<string, unknown>)
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
}
|
||||
: item,
|
||||
);
|
||||
}
|
||||
return next;
|
||||
}, [
|
||||
previewWorkspace,
|
||||
previewBrand,
|
||||
previewConfig,
|
||||
recordDraft,
|
||||
selectedRecord,
|
||||
recordSection,
|
||||
templateContent,
|
||||
]);
|
||||
const selectedDetailOfferingId =
|
||||
detailOfferingId && draftWorkspace?.offerings.some((item) => item.id === detailOfferingId)
|
||||
? detailOfferingId
|
||||
: draftWorkspace?.offerings[0]?.id;
|
||||
|
||||
return (
|
||||
<Card
|
||||
@@ -310,27 +529,31 @@ export function PresentationEditor({
|
||||
<Row gutter={[24, 24]} align="top">
|
||||
<Col xs={24} xl={12}>
|
||||
<Typography.Title level={5}>页面预览</Typography.Title>
|
||||
{selectedPage === "detail" && draftWorkspace?.offerings.length ? (
|
||||
<Select
|
||||
aria-label="选择详情页业务内容"
|
||||
style={{ width: "100%", marginBottom: 12 }}
|
||||
value={selectedDetailOfferingId}
|
||||
options={draftWorkspace.offerings.map((item) => ({
|
||||
value: item.id,
|
||||
label: item.name,
|
||||
}))}
|
||||
onChange={(value) => {
|
||||
setDetailOfferingId(value);
|
||||
setSelection(undefined);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
<TemplatePreview
|
||||
brand={previewBrand}
|
||||
{...(previewWorkspace
|
||||
? {
|
||||
workspace: {
|
||||
...previewWorkspace,
|
||||
brand: {
|
||||
...projectBrandAliases(
|
||||
{
|
||||
...previewWorkspace.brand,
|
||||
...(previewBrand as unknown as Record<string, unknown>),
|
||||
config: previewConfig,
|
||||
},
|
||||
previewConfig,
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
: {})}
|
||||
{...(draftWorkspace ? { workspace: draftWorkspace } : {})}
|
||||
page={selectedPage ?? "home"}
|
||||
{...(selectedPage === "detail" && selectedDetailOfferingId
|
||||
? { offeringId: selectedDetailOfferingId }
|
||||
: {})}
|
||||
{...(activeTarget ? { targetKey: activeTarget } : {})}
|
||||
{...(selection ? { selection } : {})}
|
||||
targets={visibleTargets}
|
||||
onTargetSelected={handleTargetSelected}
|
||||
/>
|
||||
{visibleTargets.length ? (
|
||||
@@ -339,7 +562,22 @@ export function PresentationEditor({
|
||||
<Button
|
||||
key={target.key}
|
||||
type={activeTarget === target.key ? "primary" : "default"}
|
||||
onClick={() => setActiveTarget(target.key)}
|
||||
onClick={() => {
|
||||
const recordId =
|
||||
target.source === "offering"
|
||||
? selectedPage === "detail"
|
||||
? selectedDetailOfferingId
|
||||
: draftWorkspace?.offerings[0]?.id
|
||||
: target.source === "trust"
|
||||
? draftWorkspace?.trustItems.find(
|
||||
(item) => target.key === `trust:${item.type}`,
|
||||
)?.id
|
||||
: undefined;
|
||||
handleTargetSelected({
|
||||
targetKey: target.key,
|
||||
...(recordId ? { recordId } : {}),
|
||||
});
|
||||
}}
|
||||
>
|
||||
{target.label}
|
||||
</Button>
|
||||
@@ -351,112 +589,182 @@ export function PresentationEditor({
|
||||
<Typography.Title level={5}>
|
||||
{selectedTarget?.label ?? pageTitle(selectedPage ?? "home")}
|
||||
</Typography.Title>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
onValuesChange={handleValuesChange}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
{editableSections.map((section, index) => (
|
||||
<section key={section.key} aria-labelledby={`section-${section.key}`}>
|
||||
{selectedTarget && index > 0 ? <Divider /> : null}
|
||||
<Typography.Title id={`section-${section.key}`} level={5}>
|
||||
{selectedTarget
|
||||
? fieldTargetTitle(section, selectedTarget.label)
|
||||
: section.title}
|
||||
</Typography.Title>
|
||||
{!selectedTarget ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
{section.description}
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<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>
|
||||
))}
|
||||
{relevantPageLinks.length ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 24 }}
|
||||
message="这个页面还有关联内容"
|
||||
description={
|
||||
<Space wrap>
|
||||
{relevantPageLinks.map((item) => (
|
||||
{selectedRecordSource && selection?.recordId && selectedSection ? (
|
||||
selectedRecord ? (
|
||||
<RecordEditor
|
||||
key={`${selectedRecordSource}:${selectedRecord.id}:${selectedSection.key}`}
|
||||
source={selectedRecordSource}
|
||||
record={selectedRecord}
|
||||
section={recordSection!}
|
||||
onDraft={(values) =>
|
||||
setRecordDraft({
|
||||
source: selectedRecordSource,
|
||||
id: selectedRecord.id,
|
||||
values,
|
||||
})
|
||||
}
|
||||
onSaved={() => setRecordDraft(undefined)}
|
||||
/>
|
||||
) : (
|
||||
<Alert
|
||||
type={
|
||||
(
|
||||
selectedRecordSource === "offering"
|
||||
? offeringsQuery.isError
|
||||
: trustQuery.isError
|
||||
)
|
||||
? "error"
|
||||
: "info"
|
||||
}
|
||||
message={
|
||||
(
|
||||
selectedRecordSource === "offering"
|
||||
? offeringsQuery.isError
|
||||
: trustQuery.isError
|
||||
)
|
||||
? "内容读取失败"
|
||||
: (
|
||||
selectedRecordSource === "offering"
|
||||
? offeringsQuery.isSuccess
|
||||
: trustQuery.isSuccess
|
||||
)
|
||||
? "对应内容已不存在,请重新选择页面中的区域"
|
||||
: "正在读取对应内容"
|
||||
}
|
||||
{...((
|
||||
selectedRecordSource === "offering"
|
||||
? offeringsQuery.isError
|
||||
: trustQuery.isError
|
||||
)
|
||||
? {
|
||||
action: (
|
||||
<Button
|
||||
key={item.target}
|
||||
type="link"
|
||||
size="small"
|
||||
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",
|
||||
);
|
||||
if (selectedRecordSource === "offering")
|
||||
void offeringsQuery.refetch();
|
||||
else void trustQuery.refetch();
|
||||
}}
|
||||
style={{ padding: 0 }}
|
||||
>
|
||||
{item.label}
|
||||
重试
|
||||
</Button>
|
||||
),
|
||||
}
|
||||
: {})}
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
onValuesChange={handleValuesChange}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
{editableSections.map((section, index) => (
|
||||
<section key={section.key} aria-labelledby={`section-${section.key}`}>
|
||||
{selectedTarget && index > 0 ? <Divider /> : null}
|
||||
<Typography.Title id={`section-${section.key}`} level={5}>
|
||||
{selectedTarget
|
||||
? fieldTargetTitle(section, selectedTarget.label)
|
||||
: section.title}
|
||||
</Typography.Title>
|
||||
{!selectedTarget ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
{section.description}
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<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>
|
||||
))}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{!editableSections.some((section) => section.fields.length) &&
|
||||
!relevantPageLinks.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
这个页面没有单独的品牌文案配置。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
{selectedTarget &&
|
||||
!editableSections.some((section) => section.fields.length) &&
|
||||
relevantPageLinks.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}>
|
||||
保存页面内容
|
||||
</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
</Row>
|
||||
</section>
|
||||
))}
|
||||
{relevantPageLinks.length ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 24 }}
|
||||
message="这个页面还有关联内容"
|
||||
description={
|
||||
<Space wrap>
|
||||
{relevantPageLinks.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 }}
|
||||
>
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{!editableSections.some((section) => section.fields.length) &&
|
||||
!relevantPageLinks.length ? (
|
||||
<Typography.Paragraph type="secondary">
|
||||
这个页面没有单独的品牌文案配置。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
{selectedTarget &&
|
||||
!editableSections.some((section) => section.fields.length) &&
|
||||
relevantPageLinks.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}>
|
||||
保存页面内容
|
||||
</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
</>
|
||||
@@ -465,6 +773,116 @@ export function PresentationEditor({
|
||||
);
|
||||
}
|
||||
|
||||
function RecordEditor({
|
||||
source,
|
||||
record,
|
||||
section,
|
||||
onDraft,
|
||||
onSaved,
|
||||
}: {
|
||||
source: "offering" | "trust";
|
||||
record: Offering | TrustContent;
|
||||
section: TemplateAdminSection;
|
||||
onDraft: (values: PresentationValues) => void;
|
||||
onSaved: () => void;
|
||||
}) {
|
||||
const [form] = Form.useForm<PresentationValues>();
|
||||
const queryClient = useQueryClient();
|
||||
const initialValues = useMemo(
|
||||
() =>
|
||||
Object.fromEntries(
|
||||
section.fields.map((field) => [
|
||||
presentationFieldName(section.key, field.key),
|
||||
readPresentationValue(
|
||||
record.config,
|
||||
field.binding,
|
||||
field,
|
||||
record as unknown as Record<string, unknown>,
|
||||
),
|
||||
]),
|
||||
),
|
||||
[record, section],
|
||||
);
|
||||
useEffect(() => form.setFieldsValue(initialValues), [form, initialValues]);
|
||||
const save = useMutation({
|
||||
mutationFn: async (values: PresentationValues): Promise<void> => {
|
||||
const config = applyPresentationValues(record.config, [section], values);
|
||||
const standard = applyStandardEntityValues(
|
||||
record as unknown as Record<string, unknown>,
|
||||
source,
|
||||
[section],
|
||||
values,
|
||||
);
|
||||
const changed = Object.fromEntries(
|
||||
Object.entries(standard).filter(
|
||||
([key, value]) =>
|
||||
key !== "config" && value !== (record as unknown as Record<string, unknown>)[key],
|
||||
),
|
||||
);
|
||||
const client = createApiClient();
|
||||
if (source === "offering")
|
||||
await client.updateAdminOffering(record.id, { ...changed, config });
|
||||
else await client.updateAdminTrustContent(record.id, { ...changed, config });
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("内容已保存为草稿,发布后访客才会看到更新");
|
||||
onSaved();
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: [source === "offering" ? "admin-offerings" : "trust-content"],
|
||||
});
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||
},
|
||||
});
|
||||
return (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
onValuesChange={(_, values) => onDraft(values)}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
|
||||
<div style={{ flex: 1 }}>
|
||||
<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>
|
||||
</div>
|
||||
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||||
<MutationError error={save.error} />
|
||||
<Button type="primary" htmlType="submit" loading={save.isPending}>
|
||||
保存此项内容
|
||||
</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
function pageTitle(page: string): string {
|
||||
return (
|
||||
(
|
||||
|
||||
@@ -8,22 +8,31 @@ import type {
|
||||
} from "@personal-brand/api-client";
|
||||
import { templatePreviewUrl } from "../../lib/template-preview.js";
|
||||
import { ComponentTemplatePreview } from "./ComponentTemplatePreview.js";
|
||||
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
||||
import type { PreviewSelection, PreviewTarget } from "./preview-selection.js";
|
||||
import "./TemplatePreview.css";
|
||||
|
||||
export function TemplatePreview({
|
||||
brand,
|
||||
workspace,
|
||||
page,
|
||||
offeringId,
|
||||
targetKey,
|
||||
selection,
|
||||
targets,
|
||||
onTargetSelected,
|
||||
}: {
|
||||
brand: BrandProfile;
|
||||
workspace?: RuntimeWorkspace;
|
||||
page: string;
|
||||
offeringId?: string;
|
||||
targetKey?: string;
|
||||
onTargetSelected: (key: string) => void;
|
||||
selection?: PreviewSelection;
|
||||
targets: PreviewTarget[];
|
||||
onTargetSelected: (selection?: PreviewSelection) => void;
|
||||
}) {
|
||||
const frame = useRef<HTMLIFrameElement>(null);
|
||||
const useComponent = Boolean(workspace && resolveTemplateRenderer(workspace));
|
||||
const [ready, setReady] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [reloadKey, setReloadKey] = useState(0);
|
||||
@@ -70,7 +79,7 @@ export function TemplatePreview({
|
||||
if (message?.protocol !== "personal-brand-editor-preview" || message.version !== 1) return;
|
||||
if (message.type === "ready") setReady(true);
|
||||
if (message.type === "targetSelected" && message.page === page)
|
||||
onTargetSelected(message.targetKey);
|
||||
onTargetSelected({ targetKey: message.targetKey });
|
||||
};
|
||||
window.addEventListener("message", onMessage);
|
||||
return () => window.removeEventListener("message", onMessage);
|
||||
@@ -110,7 +119,7 @@ export function TemplatePreview({
|
||||
return () => window.removeEventListener("template-preview-refresh", refresh);
|
||||
}, []);
|
||||
|
||||
if (!url)
|
||||
if (!useComponent && !url)
|
||||
return (
|
||||
<Alert
|
||||
type="warning"
|
||||
@@ -122,15 +131,18 @@ export function TemplatePreview({
|
||||
|
||||
return (
|
||||
<div className="template-preview">
|
||||
{workspace ? (
|
||||
{workspace && useComponent ? (
|
||||
<ComponentTemplatePreview
|
||||
workspace={workspace}
|
||||
page={page}
|
||||
{...(offeringId ? { offeringId } : {})}
|
||||
{...(targetKey ? { targetKey } : {})}
|
||||
{...(selection ? { selection } : {})}
|
||||
targets={targets}
|
||||
onTargetSelected={onTargetSelected}
|
||||
/>
|
||||
) : null}
|
||||
{!workspace ? (
|
||||
{!useComponent ? (
|
||||
<>
|
||||
{!ready && !error ? (
|
||||
<div className="template-preview__loading">
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@ declare module "./component-renderers.jsx" {
|
||||
workspace: RuntimeWorkspace;
|
||||
page: string;
|
||||
offeringId?: string;
|
||||
}>;
|
||||
}> | null;
|
||||
}
|
||||
@@ -24,5 +24,7 @@ export function resolveTemplateRenderer(workspace) {
|
||||
config && typeof config === "object" && !Array.isArray(config)
|
||||
? config.visualTemplateKey
|
||||
: undefined;
|
||||
return key === "linjing-editorial" ? EditorialPreview : FoodPreview;
|
||||
if (key === "acheng-campus-food") return FoodPreview;
|
||||
if (key === "linjing-editorial") return EditorialPreview;
|
||||
return null;
|
||||
}
|
||||
@@ -33,12 +33,12 @@ function asObject(value: unknown): Record<string, unknown> {
|
||||
function safePath(binding: string): string[] | null {
|
||||
const prefixes = ["brand.config.", "offering.config.", "trust.config."];
|
||||
const prefix = prefixes.find((candidate) => binding.startsWith(candidate));
|
||||
const standardBrandField =
|
||||
/^brand\.(avatarUrl|description|contactPhone|contactWechat|address|hours|deliveryNote)$/.test(
|
||||
const standardField =
|
||||
/^(brand\.(avatarUrl|description|contactPhone|contactWechat|address|hours|deliveryNote)|offering\.(name|summary|description|coverUrl|priceText)|trust\.(title|summary|content|coverUrl))$/.test(
|
||||
binding,
|
||||
);
|
||||
if (!prefix && !standardBrandField) return null;
|
||||
const path = prefix ? binding.slice(prefix.length).split(".") : [binding.slice("brand.".length)];
|
||||
if (!prefix && !standardField) return null;
|
||||
const path = prefix ? binding.slice(prefix.length).split(".") : [binding.split(".")[1] ?? ""];
|
||||
if (path.some((part) => !part || ["__proto__", "prototype", "constructor"].includes(part)))
|
||||
return null;
|
||||
return path;
|
||||
@@ -96,6 +96,7 @@ export function applyPresentationValues(
|
||||
let nextConfig = { ...asObject(config) };
|
||||
for (const section of sections) {
|
||||
for (const field of section.fields) {
|
||||
if (!field.binding.includes(".config.")) continue;
|
||||
const path = safePath(field.binding);
|
||||
if (!path) continue;
|
||||
const raw = values[presentationFieldName(section.key, field.key)];
|
||||
@@ -130,6 +131,24 @@ export function applyStandardBrandValues(
|
||||
return next;
|
||||
}
|
||||
|
||||
export function applyStandardEntityValues(
|
||||
entity: Record<string, unknown>,
|
||||
entityType: "offering" | "trust",
|
||||
sections: PresentationSection[],
|
||||
values: PresentationValues,
|
||||
): Record<string, unknown> {
|
||||
const next = { ...entity };
|
||||
for (const section of sections) {
|
||||
for (const field of section.fields) {
|
||||
if (!field.binding.startsWith(`${entityType}.`) || field.binding.includes(".config."))
|
||||
continue;
|
||||
const value = values[presentationFieldName(section.key, field.key)];
|
||||
if (value !== undefined) next[field.binding.slice(entityType.length + 1)] = value;
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
export function applyBrandPreviewValues(
|
||||
brand: Record<string, unknown>,
|
||||
config: Record<string, unknown> | null | undefined,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
export type PreviewSelection = { targetKey: string; recordId?: string };
|
||||
|
||||
export type PreviewTarget = {
|
||||
key: string;
|
||||
label: string;
|
||||
source: "brand" | "offering" | "trust" | "inquiry";
|
||||
page: string;
|
||||
};
|
||||
|
||||
export function resolvePreviewSelection(
|
||||
targetKey: string,
|
||||
recordId: string | undefined,
|
||||
targets: PreviewTarget[],
|
||||
page: string,
|
||||
): PreviewSelection | undefined {
|
||||
const target = targets.find((item) => item.key === targetKey && item.page === page);
|
||||
if (!target) return undefined;
|
||||
if (recordId && target.source !== "offering" && target.source !== "trust") return undefined;
|
||||
if (!recordId && (target.source === "offering" || target.source === "trust")) return undefined;
|
||||
return recordId ? { targetKey, recordId } : { targetKey };
|
||||
}
|
||||
@@ -2,10 +2,12 @@ import assert from "node:assert/strict";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
applyBrandPreviewValues,
|
||||
applyStandardEntityValues,
|
||||
filterSectionsForPreviewTarget,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
} from "../src/features/brand/presentation-bindings.ts";
|
||||
import { resolvePreviewSelection } from "../src/features/brand/preview-selection.ts";
|
||||
|
||||
const config = {
|
||||
founder: "阿成",
|
||||
@@ -148,3 +150,40 @@ const brandDraft = applyBrandPreviewValues(
|
||||
assert.equal(brandDraft.description, "新简介");
|
||||
assert.equal(brandDraft.address, "新地址");
|
||||
assert.equal(brandDraft.config.visualPresentation.home.title, "新标题");
|
||||
|
||||
const entitySection = [
|
||||
{
|
||||
key: "card",
|
||||
fields: [
|
||||
{ key: "name", binding: "offering.name" },
|
||||
{ key: "summary", binding: "offering.summary" },
|
||||
{ key: "category", binding: "offering.config.categoryLabel" },
|
||||
],
|
||||
},
|
||||
];
|
||||
const updatedEntity = applyStandardEntityValues(
|
||||
{ id: "one", name: "旧名称", summary: "旧简介", config: { categoryLabel: "分类" } },
|
||||
"offering",
|
||||
entitySection,
|
||||
{ "card:name": "新名称", "card:summary": "新简介", "card:category": "新分类" },
|
||||
);
|
||||
assert.equal(updatedEntity.name, "新名称");
|
||||
assert.equal(updatedEntity.summary, "新简介");
|
||||
assert.equal(updatedEntity.id, "one");
|
||||
assert.deepEqual(updatedEntity.config, { categoryLabel: "分类" });
|
||||
assert.equal(readPresentationValue({}, "offering.name", undefined, updatedEntity), "新名称");
|
||||
|
||||
const targets = [
|
||||
{ key: "brand.hero", label: "主视觉", source: "brand", page: "home" },
|
||||
{ key: "offering.card", label: "餐品", source: "offering", page: "offerings" },
|
||||
];
|
||||
assert.deepEqual(resolvePreviewSelection("brand.hero", undefined, targets, "home"), {
|
||||
targetKey: "brand.hero",
|
||||
});
|
||||
assert.deepEqual(resolvePreviewSelection("offering.card", "one", targets, "offerings"), {
|
||||
targetKey: "offering.card",
|
||||
recordId: "one",
|
||||
});
|
||||
assert.equal(resolvePreviewSelection("offering.card", undefined, targets, "offerings"), undefined);
|
||||
assert.equal(resolvePreviewSelection("brand.hero", "one", targets, "home"), undefined);
|
||||
assert.equal(resolvePreviewSelection("brand.hero", undefined, targets, "offerings"), undefined);
|
||||
@@ -23,6 +23,33 @@ const brand = {
|
||||
visualPresentation: { home: { stallTitle: "原服务地点", worksTitle: "原餐品标题" } },
|
||||
},
|
||||
};
|
||||
const adminOffering = {
|
||||
id: "menu-fixture",
|
||||
kind: "service",
|
||||
name: "家庭聚餐定制",
|
||||
summary: "为同学聚餐、家庭聚会提供常见的私房菜定制。",
|
||||
description: "餐品详情",
|
||||
priceText: "88.88",
|
||||
coverUrl: brand.avatarUrl,
|
||||
isEnabled: true,
|
||||
sortOrder: 0,
|
||||
config: { categoryLabel: "业务提供项" },
|
||||
};
|
||||
const adminTrust = {
|
||||
id: "schedule-fixture",
|
||||
type: "schedule",
|
||||
title: "出摊安排",
|
||||
summary: "工作日安排",
|
||||
content: "周末安排",
|
||||
sortOrder: 0,
|
||||
isPublished: true,
|
||||
config: {
|
||||
weekdayLabel: "周一至周五",
|
||||
weekdayDetail: "东门附近",
|
||||
weekendLabel: "周六至周日",
|
||||
weekendDetail: "周末晚间出摊",
|
||||
},
|
||||
};
|
||||
const runtimeWorkspace = {
|
||||
schemaVersion: "1.0.0",
|
||||
publication: { status: "published", version: 1 },
|
||||
@@ -37,16 +64,20 @@ const runtimeWorkspace = {
|
||||
navigation: { tabs: [] },
|
||||
offerings: [
|
||||
{
|
||||
id: "menu-fixture",
|
||||
name: "家庭聚餐定制",
|
||||
summary: "为同学聚餐、家庭聚会提供常见的私房菜定制。",
|
||||
priceText: "88.88",
|
||||
coverUrl: brand.avatarUrl,
|
||||
presentation: { categoryLabel: "业务提供项", keywords: [], details: [] },
|
||||
id: adminOffering.id,
|
||||
name: adminOffering.name,
|
||||
summary: adminOffering.summary,
|
||||
priceText: adminOffering.priceText,
|
||||
coverUrl: adminOffering.coverUrl,
|
||||
presentation: {
|
||||
categoryLabel: "业务提供项",
|
||||
keywords: [],
|
||||
details: { background: "餐品详情", designConcept: "", crafts: [], materialsList: [] },
|
||||
},
|
||||
},
|
||||
],
|
||||
inquiryForms: [],
|
||||
trustItems: [],
|
||||
trustItems: [{ ...adminTrust }],
|
||||
trustPresentation: {},
|
||||
capabilities: [],
|
||||
theme: { colors: {} },
|
||||
@@ -56,11 +87,88 @@ const templateContent = {
|
||||
navigation: [
|
||||
{ key: "home", page: "home", label: "首页" },
|
||||
{ key: "offerings", page: "offerings", label: "套餐餐品" },
|
||||
{ key: "service", page: "service", label: "出摊服务" },
|
||||
{ key: "detail", page: "detail", label: "详情页" },
|
||||
],
|
||||
assetSlots: [],
|
||||
trustContentTypes: [],
|
||||
trustContentTypes: [
|
||||
{
|
||||
type: "schedule",
|
||||
label: "每周出摊安排",
|
||||
adminFields: { title: "安排标题", summary: "安排摘要", content: "安排正文" },
|
||||
hideStandardFields: ["summary", "content"],
|
||||
pages: ["service"],
|
||||
configFields: [
|
||||
{
|
||||
key: "weekdayLabel",
|
||||
binding: "trust.config.weekdayLabel",
|
||||
label: "工作日标题",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekdayDetail",
|
||||
binding: "trust.config.weekdayDetail",
|
||||
label: "工作日地点",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekendLabel",
|
||||
binding: "trust.config.weekendLabel",
|
||||
label: "周末标题",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekendDetail",
|
||||
binding: "trust.config.weekendDetail",
|
||||
label: "周末地点",
|
||||
input: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
admin: {
|
||||
sections: [
|
||||
{
|
||||
key: "detailCopy",
|
||||
title: "餐品说明",
|
||||
description: "编辑详情页说明",
|
||||
page: "detail",
|
||||
target: "brand",
|
||||
previewTargets: [{ key: "acheng-campus-food.detail.detailCopy", label: "餐品说明" }],
|
||||
fields: [
|
||||
{
|
||||
key: "priceLabel",
|
||||
binding: "brand.config.visualPresentation.detail.priceLabel",
|
||||
label: "价格标题",
|
||||
input: "text",
|
||||
previewTarget: "acheng-campus-food.detail.detailCopy",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "offering-card",
|
||||
title: "餐品卡片",
|
||||
description: "编辑单条餐品",
|
||||
page: "offerings",
|
||||
target: "offering",
|
||||
previewTargets: [{ key: "acheng-campus-food.offerings.item", label: "餐品卡片" }],
|
||||
fields: [
|
||||
{
|
||||
key: "name",
|
||||
binding: "offering.name",
|
||||
label: "餐品名称",
|
||||
input: "text",
|
||||
previewTarget: "acheng-campus-food.offerings.item",
|
||||
},
|
||||
{
|
||||
key: "summary",
|
||||
binding: "offering.summary",
|
||||
label: "餐品简介",
|
||||
input: "textarea",
|
||||
previewTarget: "acheng-campus-food.offerings.item",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "home",
|
||||
title: "首页内容",
|
||||
@@ -125,6 +233,32 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
return route.fulfill({ json: brand });
|
||||
}
|
||||
if (url.pathname === "/admin/config/brand") return route.fulfill({ json: brand });
|
||||
if (url.pathname === "/admin/workspace/offerings")
|
||||
return route.fulfill({ json: [adminOffering] });
|
||||
if (
|
||||
url.pathname === `/admin/workspace/offerings/${adminOffering.id}` &&
|
||||
request.method() === "PATCH"
|
||||
) {
|
||||
Object.assign(adminOffering, request.postDataJSON());
|
||||
Object.assign(runtimeWorkspace.offerings[0], {
|
||||
name: adminOffering.name,
|
||||
summary: adminOffering.summary,
|
||||
});
|
||||
return route.fulfill({ json: adminOffering });
|
||||
}
|
||||
if (url.pathname === "/admin/config/trust-content")
|
||||
return route.fulfill({ json: [adminTrust] });
|
||||
if (
|
||||
url.pathname === `/admin/config/trust-content/${adminTrust.id}` &&
|
||||
request.method() === "PATCH"
|
||||
) {
|
||||
Object.assign(adminTrust, request.postDataJSON());
|
||||
Object.assign(runtimeWorkspace.trustItems[0], {
|
||||
title: adminTrust.title,
|
||||
config: adminTrust.config,
|
||||
});
|
||||
return route.fulfill({ json: adminTrust });
|
||||
}
|
||||
if (url.pathname === "/admin/workspace")
|
||||
return route.fulfill({
|
||||
json: { brand, installations: [], fields: [], offerings: [], forms: [], templateContent },
|
||||
@@ -185,11 +319,56 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
await expect(preview.locator(".notice-title")).toContainText("后台草稿地点");
|
||||
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||
await expect(preview.locator('[data-editor-target="food.home.location"]')).toHaveClass(
|
||||
/editor-target-selected/,
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-target",
|
||||
"food.home.location",
|
||||
);
|
||||
await page.getByRole("button", { name: "浏览页面" }).click();
|
||||
await preview.locator(".food-home .actions button").nth(1).click();
|
||||
await expect(page.getByText("招牌餐品标题")).toHaveCount(0);
|
||||
await page.getByRole("button", { name: "点选编辑" }).click();
|
||||
await preview.locator('[data-editor-target="food.home.location"]').click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-target",
|
||||
"food.home.location",
|
||||
);
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await expect(preview.locator(".offering-card")).toHaveCount(1);
|
||||
await preview.locator('[data-editor-target="acheng-campus-food.offerings.item"]').click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-record-id",
|
||||
adminOffering.id,
|
||||
);
|
||||
await page.getByLabel("餐品名称").fill("编辑后的家庭餐");
|
||||
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => adminOffering.name).toBe("编辑后的家庭餐");
|
||||
await page.reload();
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
|
||||
await page.getByText("出摊服务", { exact: true }).click();
|
||||
await preview.locator('[data-editor-target="trust:schedule"]').click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-record-id",
|
||||
adminTrust.id,
|
||||
);
|
||||
await page.getByLabel("工作日标题").fill("周一到周五营业");
|
||||
await expect(preview.locator(".schedule-card")).toContainText("周一到周五营业");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => adminTrust.config.weekdayLabel).toBe("周一到周五营业");
|
||||
await page.reload();
|
||||
await page.getByText("出摊服务", { exact: true }).click();
|
||||
await expect(preview.locator(".schedule-card")).toContainText("周一到周五营业");
|
||||
await page.getByText("详情页", { exact: true }).click();
|
||||
await preview.locator('[data-editor-target="acheng-campus-food.detail.detailCopy"]').click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-target",
|
||||
"acheng-campus-food.detail.detailCopy",
|
||||
);
|
||||
await expect(page.getByLabel("价格标题")).toBeVisible();
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview.locator(".dish-media img").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
@@ -216,3 +395,129 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1600, height: 900 });
|
||||
const editorialBrand = {
|
||||
...structuredClone(brand),
|
||||
templateKey: "personal",
|
||||
config: {
|
||||
visualTemplateKey: "linjing-editorial",
|
||||
founder: "林境主理人",
|
||||
title: "建筑设计师",
|
||||
heroImage: "/assets/tab/home.png",
|
||||
homeHero: { title: "林境作品" },
|
||||
},
|
||||
};
|
||||
const editorialWorkspace = {
|
||||
...structuredClone(runtimeWorkspace),
|
||||
brand: {
|
||||
...structuredClone(runtimeWorkspace.brand),
|
||||
...editorialBrand,
|
||||
founder: "林境主理人",
|
||||
title: "建筑设计师",
|
||||
heroImage: "/assets/tab/home.png",
|
||||
homeHero: { title: "林境作品" },
|
||||
},
|
||||
offerings: [],
|
||||
trustItems: [],
|
||||
};
|
||||
const editorialContent = {
|
||||
displayName: "林境模板",
|
||||
navigation: [
|
||||
{ key: "home", page: "home", label: "首页" },
|
||||
{ key: "profile", page: "profile", label: "主理人与我" },
|
||||
],
|
||||
assetSlots: [],
|
||||
trustContentTypes: [],
|
||||
admin: {
|
||||
sections: [
|
||||
{
|
||||
key: "home",
|
||||
title: "首页主视觉",
|
||||
page: "home",
|
||||
target: "brand",
|
||||
previewTargets: [{ key: "editorial.home.hero", label: "首页主视觉" }],
|
||||
fields: [
|
||||
{
|
||||
key: "heroTitle",
|
||||
binding: "brand.config.homeHero.title",
|
||||
label: "首页标题",
|
||||
input: "text",
|
||||
previewTarget: "editorial.home.hero",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "identity",
|
||||
title: "主理人与联系方式",
|
||||
page: "profile",
|
||||
target: "brand",
|
||||
previewTargets: [
|
||||
{ key: "linjing-editorial.profile.identity", label: "主理人与联系方式" },
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
key: "founder",
|
||||
binding: "brand.config.founder",
|
||||
label: "主理人姓名",
|
||||
input: "text",
|
||||
previewTarget: "linjing-editorial.profile.identity",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
await page.route("**/api/**", (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const path = url.pathname.replace(/^\/api/, "");
|
||||
if (path === "/admin/session/login")
|
||||
return route.fulfill({
|
||||
json: { token: "fixture-token", displayName: "测试管理员", role: "owner" },
|
||||
});
|
||||
if (path === "/admin/brands")
|
||||
return route.fulfill({
|
||||
json: [{ id: editorialBrand.id, role: "owner", brand: editorialBrand }],
|
||||
});
|
||||
if (path === "/admin/config/brand") return route.fulfill({ json: editorialBrand });
|
||||
if (path === "/public/templates/personal")
|
||||
return route.fulfill({
|
||||
json: { name: "个人品牌", description: "林境模板", serviceCategories: [] },
|
||||
});
|
||||
if (path === "/admin/workspace")
|
||||
return route.fulfill({
|
||||
json: {
|
||||
brand: editorialBrand,
|
||||
installations: [],
|
||||
fields: [],
|
||||
offerings: [],
|
||||
forms: [],
|
||||
templateContent: editorialContent,
|
||||
},
|
||||
});
|
||||
if (path === "/admin/workspace/preview" || path === "/public/workspace")
|
||||
return route.fulfill({ json: editorialWorkspace });
|
||||
return route.fulfill({ json: {} });
|
||||
});
|
||||
await page.goto(adminOrigin + "/admin/brand");
|
||||
await page.getByLabel("账号").fill("admin");
|
||||
await page.getByLabel("密码").fill("fixture-password");
|
||||
await page.locator('button[type="submit"]').click();
|
||||
const preview = page.locator(".component-template-preview");
|
||||
await expect(preview.locator(".editorial-home")).toBeVisible();
|
||||
await expect(preview.locator(".hero-title")).toContainText("林境作品");
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview.locator(".hero-image").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
)
|
||||
.toBeGreaterThan(0);
|
||||
await preview.locator('[data-editor-target="editorial.home.hero"]').click();
|
||||
await expect(page.getByLabel("首页标题")).toBeVisible();
|
||||
await page.getByText("主理人与我", { exact: true }).click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||
await preview.locator('[data-editor-target="linjing-editorial.profile.identity"]').click();
|
||||
await expect(page.getByLabel("主理人姓名")).toBeVisible();
|
||||
await page.getByLabel("主理人姓名").fill("修改后的主理人");
|
||||
await expect(preview.locator(".editorial-profile .founder")).toContainText("修改后的主理人");
|
||||
});
|
||||
@@ -11,7 +11,7 @@ import type {
|
||||
RuntimeTrustItem,
|
||||
ThemeManifest,
|
||||
} from "@personal-brand/types";
|
||||
export { projectBrandAliases } from "@personal-brand/types";
|
||||
export { projectBrandAliases, projectTrustPresentation } from "@personal-brand/types";
|
||||
export type { PublicOffering } from "@personal-brand/types";
|
||||
export type { BookingStatus } from "@personal-brand/types";
|
||||
export type { BrandTemplateKey } from "@personal-brand/types";
|
||||
|
||||
@@ -201,6 +201,49 @@ export const generatedTemplatePackageRegistry = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "homeOffering",
|
||||
"title": "首页业务卡片",
|
||||
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||
"page": "home",
|
||||
"target": "offering",
|
||||
"fields": [
|
||||
{
|
||||
"key": "name",
|
||||
"binding": "offering.name",
|
||||
"label": "名称",
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "summary",
|
||||
"binding": "offering.summary",
|
||||
"label": "简介",
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "priceText",
|
||||
"binding": "offering.priceText",
|
||||
"label": "价格说明",
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "coverUrl",
|
||||
"binding": "offering.coverUrl",
|
||||
"label": "封面图片",
|
||||
"input": "image",
|
||||
"previewTarget": "acheng-campus-food.home.offering"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.home.offering",
|
||||
"label": "首页业务卡片"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "home",
|
||||
"title": "首页出摊信息",
|
||||
@@ -297,6 +340,49 @@ export const generatedTemplatePackageRegistry = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "offeringsOffering",
|
||||
"title": "业务卡片",
|
||||
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||
"page": "offerings",
|
||||
"target": "offering",
|
||||
"fields": [
|
||||
{
|
||||
"key": "name",
|
||||
"binding": "offering.name",
|
||||
"label": "名称",
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "summary",
|
||||
"binding": "offering.summary",
|
||||
"label": "简介",
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "priceText",
|
||||
"binding": "offering.priceText",
|
||||
"label": "价格说明",
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "coverUrl",
|
||||
"binding": "offering.coverUrl",
|
||||
"label": "封面图片",
|
||||
"input": "image",
|
||||
"previewTarget": "acheng-campus-food.offerings.item"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.offerings.item",
|
||||
"label": "业务卡片"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "menu",
|
||||
"title": "菜单页说明",
|
||||
@@ -1428,6 +1514,49 @@ export const generatedTemplatePackageRegistry = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "homeOffering",
|
||||
"title": "首页业务卡片",
|
||||
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||
"page": "home",
|
||||
"target": "offering",
|
||||
"fields": [
|
||||
{
|
||||
"key": "name",
|
||||
"binding": "offering.name",
|
||||
"label": "名称",
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "summary",
|
||||
"binding": "offering.summary",
|
||||
"label": "简介",
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "priceText",
|
||||
"binding": "offering.priceText",
|
||||
"label": "价格说明",
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "coverUrl",
|
||||
"binding": "offering.coverUrl",
|
||||
"label": "封面图片",
|
||||
"input": "image",
|
||||
"previewTarget": "linjing-editorial.home.offering"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.home.offering",
|
||||
"label": "首页业务卡片"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "home",
|
||||
"title": "首页品牌表达",
|
||||
@@ -1689,6 +1818,49 @@ export const generatedTemplatePackageRegistry = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "offeringsOffering",
|
||||
"title": "业务卡片",
|
||||
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||
"page": "offerings",
|
||||
"target": "offering",
|
||||
"fields": [
|
||||
{
|
||||
"key": "name",
|
||||
"binding": "offering.name",
|
||||
"label": "名称",
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "summary",
|
||||
"binding": "offering.summary",
|
||||
"label": "简介",
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "priceText",
|
||||
"binding": "offering.priceText",
|
||||
"label": "价格说明",
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "coverUrl",
|
||||
"binding": "offering.coverUrl",
|
||||
"label": "封面图片",
|
||||
"input": "image",
|
||||
"previewTarget": "linjing-editorial.offerings.item"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.offerings.item",
|
||||
"label": "业务卡片"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "cases",
|
||||
"title": "案例与体系",
|
||||
@@ -2451,4 +2623,4 @@ export const generatedTemplatePackageRegistry = [
|
||||
}
|
||||
];
|
||||
export const generatedTemplatePackageRegistryHash =
|
||||
"affa45e548331400f6f552562653f2f21b8ac3643ccb7521df9609776ebae4ae";
|
||||
"495374aaba6d94ef9597a525a8ca3af221d9fb44e7eaf34d75b71b8b6070bd2f";
|
||||
@@ -65,6 +65,8 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<View
|
||||
className="dish"
|
||||
key={item.id}
|
||||
data-editor-target="acheng-campus-food.home.offering"
|
||||
data-editor-record-id={item.id}
|
||||
onClick={() => navigate("detail", { id: item.id })}
|
||||
>
|
||||
<Image src={item.image} mode="aspectFill" />
|
||||
@@ -82,7 +84,12 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
{workspace.trustItems
|
||||
.filter((item) => ["promise", "case"].includes(item.type))
|
||||
.map((item) => (
|
||||
<View className="promise" key={item.id}>
|
||||
<View
|
||||
className="promise"
|
||||
key={item.id}
|
||||
data-editor-target={`trust:${item.type}`}
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<Text className="eyebrow light">{item.title}</Text>
|
||||
{item.summary && <Text className="promise-title">{item.summary}</Text>}
|
||||
<Text className="quote">{item.content}</Text>
|
||||
@@ -119,7 +126,11 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<View className="food-service" data-editor-target="acheng-campus-food.service.service">
|
||||
<View className="page service-page">
|
||||
{schedule && scheduleRows.length > 0 && (
|
||||
<View className="service-card schedule-card">
|
||||
<View
|
||||
className="service-card schedule-card"
|
||||
data-editor-target="trust:schedule"
|
||||
data-editor-record-id={schedule.id}
|
||||
>
|
||||
<View className="card-head">
|
||||
<View className="head-title">
|
||||
<Image className="icon" src={asset("service/clock.png")} />
|
||||
@@ -152,7 +163,11 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</View>
|
||||
)}
|
||||
{c && text(c.config.pickupDetail) && text(c.config.deliveryDetail) && (
|
||||
<View className="service-card coverage-card">
|
||||
<View
|
||||
className="service-card coverage-card"
|
||||
data-editor-target="trust:coverage"
|
||||
data-editor-record-id={c.id}
|
||||
>
|
||||
<View className="simple-title">
|
||||
<Image className="icon" src={asset("service/bike.png")} />
|
||||
<Text>{c.title}</Text>
|
||||
@@ -176,7 +191,11 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</View>
|
||||
)}
|
||||
{process && steps.length > 0 && (
|
||||
<View className="service-card process-card">
|
||||
<View
|
||||
className="service-card process-card"
|
||||
data-editor-target="trust:process"
|
||||
data-editor-record-id={process.id}
|
||||
>
|
||||
<View className="simple-title">
|
||||
<Image className="icon" src={asset("service/list.png")} />
|
||||
<Text>{process.title}</Text>
|
||||
@@ -237,7 +256,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
{text(brand.description) && <Text className="bio">{text(brand.description)}</Text>}
|
||||
{credentials.map((item) =>
|
||||
rows(item.config.standards).length ? (
|
||||
<View className="standards" key={item.id}>
|
||||
<View
|
||||
className="standards"
|
||||
key={item.id}
|
||||
data-editor-target="trust:credential"
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
{rows(item.config.standards).map((standard, index) => (
|
||||
<View className="standard" key={index}>
|
||||
<Image
|
||||
@@ -252,7 +276,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
))}
|
||||
</View>
|
||||
) : (
|
||||
<View className="credential-copy" key={item.id}>
|
||||
<View
|
||||
className="credential-copy"
|
||||
key={item.id}
|
||||
data-editor-target="trust:credential"
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<Text className="credential-title">{item.title}</Text>
|
||||
{item.summary && <Text className="bio">{item.summary}</Text>}
|
||||
<Text className="bio">{item.content}</Text>
|
||||
@@ -264,7 +293,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
{workspace.trustItems
|
||||
.filter((item) => item.type === "case")
|
||||
.map((item) => (
|
||||
<View className="case-card" key={item.id}>
|
||||
<View
|
||||
className="case-card"
|
||||
key={item.id}
|
||||
data-editor-target="trust:case"
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<View className="section-heading">
|
||||
<Image className="heading-icon" src={asset("owner/handshake.png")} />
|
||||
<Text>{item.title}</Text>
|
||||
@@ -291,7 +325,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
{workspace.trustItems
|
||||
.filter((item) => item.type === "promise")
|
||||
.map((item) => (
|
||||
<View className="promise-card" key={item.id}>
|
||||
<View
|
||||
className="promise-card"
|
||||
key={item.id}
|
||||
data-editor-target="trust:promise"
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<View className="section-heading">
|
||||
<Image className="promise-icon" src={asset("owner/clock.png")} />
|
||||
<Text>{item.title}</Text>
|
||||
@@ -409,6 +448,8 @@ function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<View
|
||||
className="offering-card"
|
||||
key={item.id}
|
||||
data-editor-target="acheng-campus-food.offerings.item"
|
||||
data-editor-record-id={item.id}
|
||||
onClick={() => navigate("detail", { id: item.id })}
|
||||
>
|
||||
<View className="dish-media">
|
||||
@@ -447,7 +488,11 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
const item = offering(found);
|
||||
const p = presentation(workspace, "detail");
|
||||
return (
|
||||
<View className="food-detail" data-editor-target="acheng-campus-food.detail.dishDetail">
|
||||
<View
|
||||
className="food-detail"
|
||||
data-editor-target="acheng-campus-food.detail.dishDetail"
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<View className="detail">
|
||||
<View className="hero-wrap">
|
||||
<Image
|
||||
|
||||
@@ -194,6 +194,49 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "homeOffering",
|
||||
"title": "首页业务卡片",
|
||||
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||
"page": "home",
|
||||
"target": "offering",
|
||||
"fields": [
|
||||
{
|
||||
"key": "name",
|
||||
"binding": "offering.name",
|
||||
"label": "名称",
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "summary",
|
||||
"binding": "offering.summary",
|
||||
"label": "简介",
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "priceText",
|
||||
"binding": "offering.priceText",
|
||||
"label": "价格说明",
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "coverUrl",
|
||||
"binding": "offering.coverUrl",
|
||||
"label": "封面图片",
|
||||
"input": "image",
|
||||
"previewTarget": "acheng-campus-food.home.offering"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.home.offering",
|
||||
"label": "首页业务卡片"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "home",
|
||||
"title": "首页出摊信息",
|
||||
@@ -290,6 +333,49 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "offeringsOffering",
|
||||
"title": "业务卡片",
|
||||
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||
"page": "offerings",
|
||||
"target": "offering",
|
||||
"fields": [
|
||||
{
|
||||
"key": "name",
|
||||
"binding": "offering.name",
|
||||
"label": "名称",
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "summary",
|
||||
"binding": "offering.summary",
|
||||
"label": "简介",
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "priceText",
|
||||
"binding": "offering.priceText",
|
||||
"label": "价格说明",
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "coverUrl",
|
||||
"binding": "offering.coverUrl",
|
||||
"label": "封面图片",
|
||||
"input": "image",
|
||||
"previewTarget": "acheng-campus-food.offerings.item"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.offerings.item",
|
||||
"label": "业务卡片"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "menu",
|
||||
"title": "菜单页说明",
|
||||
|
||||
@@ -53,7 +53,13 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<View className="intro" data-editor-target="editorial.home.proof">
|
||||
<Text className="eyebrow dark">{p.proofEyebrow}</Text>
|
||||
<Text className="section-title">{p.proofTitle}</Text>
|
||||
<Text className="body">{credential?.content}</Text>
|
||||
<Text
|
||||
className="body"
|
||||
data-editor-target="trust:credential"
|
||||
data-editor-record-id={credential?.id}
|
||||
>
|
||||
{credential?.content}
|
||||
</Text>
|
||||
<View className="stats">
|
||||
{t.stats?.map((item, index) => (
|
||||
<View key={index}>
|
||||
@@ -88,6 +94,8 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<View
|
||||
className="work-card"
|
||||
key={item.id}
|
||||
data-editor-target="linjing-editorial.home.offering"
|
||||
data-editor-record-id={item.id}
|
||||
onClick={() => navigate("detail", { id: item.id })}
|
||||
>
|
||||
<Image src={item.image} mode="aspectFill" />
|
||||
@@ -205,7 +213,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</View>
|
||||
)}
|
||||
{workspace.trustItems.map((item) => (
|
||||
<View className="info-card trust-card" key={item.id}>
|
||||
<View
|
||||
className="info-card trust-card"
|
||||
key={item.id}
|
||||
data-editor-target={`trust:${item.type}`}
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<View className="card-title">{item.title}</View>
|
||||
{item.summary && <Text className="trust-summary">{item.summary}</Text>}
|
||||
<Text>{item.content}</Text>
|
||||
@@ -227,6 +240,8 @@ function List({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<View
|
||||
className="work-card"
|
||||
key={item.id}
|
||||
data-editor-target="linjing-editorial.offerings.item"
|
||||
data-editor-record-id={item.id}
|
||||
onClick={() => navigate("detail", { id: item.id })}
|
||||
>
|
||||
<Image src={item.image} mode="aspectFill" />
|
||||
@@ -258,7 +273,11 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
const item = offering(found);
|
||||
const p = presentation(workspace, "detail");
|
||||
return (
|
||||
<View className="editorial-detail" data-editor-target="linjing-editorial.detail.projectDetail">
|
||||
<View
|
||||
className="editorial-detail"
|
||||
data-editor-target="linjing-editorial.detail.projectDetail"
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<View className="detail">
|
||||
<View className="hero-wrap">
|
||||
<Image
|
||||
|
||||
@@ -161,6 +161,49 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "homeOffering",
|
||||
"title": "首页业务卡片",
|
||||
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||
"page": "home",
|
||||
"target": "offering",
|
||||
"fields": [
|
||||
{
|
||||
"key": "name",
|
||||
"binding": "offering.name",
|
||||
"label": "名称",
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "summary",
|
||||
"binding": "offering.summary",
|
||||
"label": "简介",
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "priceText",
|
||||
"binding": "offering.priceText",
|
||||
"label": "价格说明",
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.offering"
|
||||
},
|
||||
{
|
||||
"key": "coverUrl",
|
||||
"binding": "offering.coverUrl",
|
||||
"label": "封面图片",
|
||||
"input": "image",
|
||||
"previewTarget": "linjing-editorial.home.offering"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.home.offering",
|
||||
"label": "首页业务卡片"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "home",
|
||||
"title": "首页品牌表达",
|
||||
@@ -422,6 +465,49 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "offeringsOffering",
|
||||
"title": "业务卡片",
|
||||
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||
"page": "offerings",
|
||||
"target": "offering",
|
||||
"fields": [
|
||||
{
|
||||
"key": "name",
|
||||
"binding": "offering.name",
|
||||
"label": "名称",
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "summary",
|
||||
"binding": "offering.summary",
|
||||
"label": "简介",
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "priceText",
|
||||
"binding": "offering.priceText",
|
||||
"label": "价格说明",
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.offerings.item"
|
||||
},
|
||||
{
|
||||
"key": "coverUrl",
|
||||
"binding": "offering.coverUrl",
|
||||
"label": "封面图片",
|
||||
"input": "image",
|
||||
"previewTarget": "linjing-editorial.offerings.item"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.offerings.item",
|
||||
"label": "业务卡片"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "cases",
|
||||
"title": "案例与体系",
|
||||
|
||||
@@ -62,6 +62,16 @@ export function runtimeContractForBinding(binding: string): RuntimeBindingContra
|
||||
kind: "offering",
|
||||
};
|
||||
}
|
||||
if (
|
||||
binding.startsWith("offering.") &&
|
||||
["name", "summary", "priceText", "coverUrl"].includes(binding.slice("offering.".length))
|
||||
) {
|
||||
return {
|
||||
binding,
|
||||
runtimePath: `workspace.offerings[].${binding.slice("offering.".length)}`,
|
||||
kind: "offering",
|
||||
};
|
||||
}
|
||||
if (binding === "trust.title" || binding === "trust.summary" || binding === "trust.content") {
|
||||
return {
|
||||
binding,
|
||||
|
||||
@@ -11,6 +11,10 @@ import {
|
||||
} from "../src/runtime-content-contract.ts";
|
||||
|
||||
test("runtime contract resolves canonical paths", () => {
|
||||
assert.equal(
|
||||
runtimeContractForBinding("offering.name").runtimePath,
|
||||
"workspace.offerings[].name",
|
||||
);
|
||||
assert.equal(
|
||||
runtimeContractForBinding("offering.config.details.background").runtimePath,
|
||||
"workspace.offerings[].presentation.details.background",
|
||||
|
||||
Reference in new issue
Block a user