feat: 建立组件化模板预览基线并规划可视化编辑
This commit is contained in:
1 parent
c5af790554
commit
0b14b5a814
46 files changed
+1880
-427
No files matched your search
@@ -14,6 +14,7 @@ apps/miniapp/project.private.config.json
|
||||
|
||||
.worktrees/
|
||||
apps/taro/src/assets/
|
||||
apps/admin/public/template-preview/
|
||||
|
||||
apps/taro/test-results/
|
||||
apps/taro/playwright-report/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
node_modules
|
||||
.turbo
|
||||
dist
|
||||
apps/admin/public/template-preview
|
||||
.next
|
||||
prototype
|
||||
pnpm-lock.yaml
|
||||
|
||||
@@ -2,4 +2,4 @@ VITE_APP_BASE_PATH=/admin/
|
||||
VITE_API_BASE_URL=/api
|
||||
VITE_DEV_API_TARGET=http://localhost:3001
|
||||
ADMIN_PORT=3000
|
||||
VITE_TEMPLATE_PREVIEW_URLS={"acheng-campus-food":"http://localhost:3002","linjing-editorial":"http://localhost:3003"}
|
||||
VITE_TEMPLATE_PREVIEW_URL=http://localhost:3002
|
||||
@@ -16,6 +16,10 @@ export function BrandPage() {
|
||||
queryKey: ["admin-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const previewWorkspace = useQuery({
|
||||
queryKey: ["admin-preview-workspace"],
|
||||
queryFn: () => client.getAdminPreviewWorkspace(),
|
||||
});
|
||||
const template = useQuery({
|
||||
queryKey: ["template", brand.data?.templateKey],
|
||||
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
|
||||
@@ -145,6 +149,7 @@ export function BrandPage() {
|
||||
</Form>
|
||||
<PresentationEditor
|
||||
templateContent={workspace.data?.templateContent}
|
||||
previewWorkspace={previewWorkspace.data}
|
||||
config={brand.data.config}
|
||||
brand={brand.data}
|
||||
loading={workspace.isLoading}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
.component-template-preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: min(76vh, 820px);
|
||||
min-height: 620px;
|
||||
padding: 24px 16px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #e8e8e8;
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.component-template-preview__canvas {
|
||||
container-type: inline-size;
|
||||
width: min(100%, 390px);
|
||||
min-height: calc(100% - 48px);
|
||||
margin: 0 auto;
|
||||
overflow: visible;
|
||||
border-radius: 14px;
|
||||
background: #fff;
|
||||
box-shadow:
|
||||
0 0 0 1px rgba(0, 0, 0, 0.04),
|
||||
0 10px 30px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.component-template-preview__canvas,
|
||||
.component-template-preview__canvas * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.component-template-preview__canvas > * {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
:where(.component-template-preview__canvas) button {
|
||||
display: block;
|
||||
width: -webkit-fill-available;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
font-size: 4.8cqw;
|
||||
line-height: 2.55555556;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
:where(.component-template-preview__canvas) input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.component-template-preview__canvas img {
|
||||
flex-shrink: 0;
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.component-template-preview [data-editor-target] {
|
||||
position: relative;
|
||||
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 {
|
||||
position: absolute;
|
||||
top: -10px;
|
||||
left: -2px;
|
||||
z-index: 3;
|
||||
padding: 2px 7px;
|
||||
border-radius: 4px;
|
||||
background: #1677ff;
|
||||
color: #fff;
|
||||
content: attr(data-editor-target);
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
pointer-events: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
||||
import "../../../../../packages/template-acheng-campus-food/taro/style.css";
|
||||
import "../../../../../packages/template-linjing-editorial/taro/style.css";
|
||||
import "./ComponentTemplatePreview.css";
|
||||
|
||||
type PreviewProps = {
|
||||
workspace: RuntimeWorkspace;
|
||||
page: string;
|
||||
offeringId?: string;
|
||||
targetKey?: string;
|
||||
onTargetSelected: (targetKey: string) => void;
|
||||
};
|
||||
|
||||
export function ComponentTemplatePreview({
|
||||
workspace,
|
||||
page,
|
||||
offeringId,
|
||||
targetKey,
|
||||
onTargetSelected,
|
||||
}: PreviewProps) {
|
||||
const Renderer = resolveTemplateRenderer(workspace);
|
||||
const root = useRef<HTMLDivElement>(null);
|
||||
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]);
|
||||
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>
|
||||
{targetKey ? (
|
||||
<div className="component-template-preview__selection" data-selected-target={targetKey} />
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
// @ts-nocheck
|
||||
@@ -19,14 +19,21 @@ import {
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type { AdminTemplateContent, TemplateAdminField } from "@personal-brand/api-client";
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminField,
|
||||
} from "@personal-brand/api-client";
|
||||
import type { BrandProfile } from "@personal-brand/api-client";
|
||||
import { projectBrandAliases } 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 {
|
||||
applyBrandPreviewValues,
|
||||
applyStandardBrandValues,
|
||||
applyPresentationValues,
|
||||
filterSectionsForPreviewTarget,
|
||||
presentationFieldName,
|
||||
@@ -36,6 +43,7 @@ import {
|
||||
|
||||
interface PresentationEditorProps {
|
||||
templateContent: AdminTemplateContent | null | undefined;
|
||||
previewWorkspace?: RuntimeWorkspace | undefined;
|
||||
config: Record<string, unknown> | null | undefined;
|
||||
brand: BrandProfile;
|
||||
loading?: boolean;
|
||||
@@ -83,6 +91,7 @@ function renderField(field: TemplateAdminField) {
|
||||
|
||||
export function PresentationEditor({
|
||||
templateContent,
|
||||
previewWorkspace,
|
||||
config,
|
||||
brand,
|
||||
loading,
|
||||
@@ -94,6 +103,8 @@ export function PresentationEditor({
|
||||
const breakpoints = Grid.useBreakpoint();
|
||||
const [activePage, setActivePage] = useState<string>();
|
||||
const [activeTarget, setActiveTarget] = useState<string>();
|
||||
const [previewConfig, setPreviewConfig] = useState(config ?? {});
|
||||
const [previewBrandValues, setPreviewBrandValues] = useState<Record<string, unknown>>({});
|
||||
const sections = useMemo(() => {
|
||||
const declaredTemplateFields = (templateContent?.templateFields ?? []).map((field) => ({
|
||||
...field,
|
||||
@@ -113,22 +124,20 @@ export function PresentationEditor({
|
||||
]
|
||||
: []),
|
||||
...(templateContent?.admin.sections ?? []),
|
||||
]
|
||||
.map((section) => ({
|
||||
...section,
|
||||
fields: section.fields.filter(
|
||||
(field) =>
|
||||
field.binding.startsWith("brand.config.") ||
|
||||
[
|
||||
"brand.avatarUrl",
|
||||
"brand.description",
|
||||
"brand.contactPhone",
|
||||
"brand.contactWechat",
|
||||
"brand.address",
|
||||
].includes(field.binding),
|
||||
),
|
||||
}))
|
||||
.filter((section) => section.fields.length > 0);
|
||||
].map((section) => ({
|
||||
...section,
|
||||
fields: section.fields.filter(
|
||||
(field) =>
|
||||
field.binding.startsWith("brand.config.") ||
|
||||
[
|
||||
"brand.avatarUrl",
|
||||
"brand.description",
|
||||
"brand.contactPhone",
|
||||
"brand.contactWechat",
|
||||
"brand.address",
|
||||
].includes(field.binding),
|
||||
),
|
||||
}));
|
||||
}, [templateContent]);
|
||||
const pageOptions = useMemo(() => {
|
||||
const pages = new Map<string, string>();
|
||||
@@ -144,11 +153,23 @@ export function PresentationEditor({
|
||||
? activePage
|
||||
: pageOptions[0]?.value;
|
||||
const visibleSections = sections.filter((section) => section.page === selectedPage);
|
||||
const visibleTargets = visibleSections.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({ ...target, page: section.page })),
|
||||
);
|
||||
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 editableSections = filterSectionsForPreviewTarget(visibleSections, selectedTarget?.key);
|
||||
const selectedSection = (templateContent?.admin.sections ?? []).find((section) =>
|
||||
section.previewTargets?.some((target) => target.key === selectedTarget?.key),
|
||||
);
|
||||
const editableSections = filterSectionsForPreviewTarget(
|
||||
visibleSections.filter((section) => section.target === "brand"),
|
||||
selectedTarget?.key,
|
||||
);
|
||||
const handleTargetSelected = useCallback((key: string) => setActiveTarget(key), []);
|
||||
const relatedTargets = [
|
||||
...(templateContent?.admin.sections ?? [])
|
||||
@@ -180,6 +201,12 @@ export function PresentationEditor({
|
||||
},
|
||||
],
|
||||
);
|
||||
const relevantPageLinks = selectedSection
|
||||
? pageLinks.filter((item) => {
|
||||
if (item.target.startsWith("trust:")) return selectedSection.target === "trust";
|
||||
return item.target === selectedSection.target;
|
||||
})
|
||||
: pageLinks;
|
||||
const initialValues = useMemo(() => {
|
||||
const values: PresentationValues = {};
|
||||
for (const section of sections) {
|
||||
@@ -188,6 +215,7 @@ export function PresentationEditor({
|
||||
config,
|
||||
field.binding,
|
||||
field,
|
||||
brand as unknown as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -197,7 +225,10 @@ export function PresentationEditor({
|
||||
const save = useMutation({
|
||||
mutationFn: (values: PresentationValues) => {
|
||||
const nextConfig = applyPresentationValues(config, sections, values);
|
||||
return createApiClient().updateAdminBrand({ config: nextConfig });
|
||||
return createApiClient().updateAdminBrand({
|
||||
config: nextConfig,
|
||||
...applyStandardBrandValues(brand as unknown as Record<string, unknown>, sections, values),
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("页面内容已保存为草稿,发布后小程序才会更新");
|
||||
@@ -218,6 +249,27 @@ export function PresentationEditor({
|
||||
setActivePage(pageOptions[0]?.value);
|
||||
}, [activePage, pageOptions]);
|
||||
useEffect(() => setActiveTarget(undefined), [selectedPage]);
|
||||
useEffect(() => {
|
||||
setPreviewConfig(config ?? {});
|
||||
setPreviewBrandValues({});
|
||||
}, [config]);
|
||||
const previewBrand = useMemo(
|
||||
() => ({ ...brand, ...previewBrandValues, config: previewConfig }),
|
||||
[brand, previewBrandValues, previewConfig],
|
||||
);
|
||||
const handleValuesChange = useCallback(
|
||||
(_changed: PresentationValues, allValues: PresentationValues) => {
|
||||
const next = applyBrandPreviewValues(
|
||||
brand as unknown as Record<string, unknown>,
|
||||
config,
|
||||
sections,
|
||||
allValues,
|
||||
);
|
||||
setPreviewConfig((next.config as Record<string, unknown>) ?? {});
|
||||
setPreviewBrandValues(next);
|
||||
},
|
||||
[brand, config, sections],
|
||||
);
|
||||
|
||||
return (
|
||||
<Card
|
||||
@@ -259,9 +311,25 @@ export function PresentationEditor({
|
||||
<Col xs={24} xl={12}>
|
||||
<Typography.Title level={5}>页面预览</Typography.Title>
|
||||
<TemplatePreview
|
||||
brand={brand}
|
||||
brand={previewBrand}
|
||||
{...(previewWorkspace
|
||||
? {
|
||||
workspace: {
|
||||
...previewWorkspace,
|
||||
brand: {
|
||||
...projectBrandAliases(
|
||||
{
|
||||
...previewWorkspace.brand,
|
||||
...(previewBrand as unknown as Record<string, unknown>),
|
||||
config: previewConfig,
|
||||
},
|
||||
previewConfig,
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
: {})}
|
||||
page={selectedPage ?? "home"}
|
||||
route={`/pages/${encodeURIComponent(selectedPage ?? "home")}/index`}
|
||||
{...(activeTarget ? { targetKey: activeTarget } : {})}
|
||||
onTargetSelected={handleTargetSelected}
|
||||
/>
|
||||
@@ -287,6 +355,7 @@ export function PresentationEditor({
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={initialValues}
|
||||
onValuesChange={handleValuesChange}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
@@ -333,7 +402,7 @@ export function PresentationEditor({
|
||||
</Row>
|
||||
</section>
|
||||
))}
|
||||
{pageLinks.length ? (
|
||||
{relevantPageLinks.length ? (
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
@@ -341,7 +410,7 @@ export function PresentationEditor({
|
||||
message="这个页面还有关联内容"
|
||||
description={
|
||||
<Space wrap>
|
||||
{pageLinks.map((item) => (
|
||||
{relevantPageLinks.map((item) => (
|
||||
<Button
|
||||
key={item.target}
|
||||
type="link"
|
||||
@@ -367,11 +436,19 @@ export function PresentationEditor({
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{!editableSections.length && !pageLinks.length ? (
|
||||
{!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} />
|
||||
|
||||
@@ -4,42 +4,42 @@ import type {
|
||||
BrandProfile,
|
||||
EditorPreviewFrameMessage,
|
||||
EditorPreviewHostMessage,
|
||||
RuntimeWorkspace,
|
||||
} from "@personal-brand/api-client";
|
||||
import { templatePreviewUrl } from "../../lib/template-preview.js";
|
||||
import { ComponentTemplatePreview } from "./ComponentTemplatePreview.js";
|
||||
import "./TemplatePreview.css";
|
||||
|
||||
export function TemplatePreview({
|
||||
brand,
|
||||
workspace,
|
||||
page,
|
||||
targetKey,
|
||||
route,
|
||||
onTargetSelected,
|
||||
}: {
|
||||
brand: BrandProfile;
|
||||
workspace?: RuntimeWorkspace;
|
||||
page: string;
|
||||
targetKey?: string;
|
||||
route: string;
|
||||
onTargetSelected: (key: string) => void;
|
||||
}) {
|
||||
const frame = useRef<HTMLIFrameElement>(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [reloadKey, setReloadKey] = useState(0);
|
||||
const config = brand.config ?? {};
|
||||
const templateKey =
|
||||
typeof config.visualTemplateKey === "string" ? config.visualTemplateKey : brand.templateKey;
|
||||
const url = useMemo(
|
||||
() =>
|
||||
templatePreviewUrl(
|
||||
templateKey,
|
||||
brand.slug,
|
||||
page,
|
||||
import.meta.env.VITE_TEMPLATE_PREVIEW_URLS,
|
||||
window.location.origin,
|
||||
route,
|
||||
),
|
||||
[brand.slug, page, reloadKey, route, templateKey],
|
||||
);
|
||||
const url = useMemo(() => {
|
||||
const value = templatePreviewUrl(
|
||||
brand.slug,
|
||||
page,
|
||||
import.meta.env.VITE_TEMPLATE_PREVIEW_URL || "/template-preview/index.html",
|
||||
window.location.origin,
|
||||
`/pages/${encodeURIComponent(page)}/index`,
|
||||
);
|
||||
if (!value) return undefined;
|
||||
const preview = new URL(value);
|
||||
preview.searchParams.set("refresh", String(reloadKey));
|
||||
return preview.toString();
|
||||
}, [brand.slug, page, reloadKey]);
|
||||
const origin = useMemo(() => (url ? new URL(url).origin : ""), [url]);
|
||||
const brandDraft = useMemo(
|
||||
() => ({
|
||||
@@ -80,12 +80,21 @@ export function TemplatePreview({
|
||||
if (!ready || !frame.current?.contentWindow || !origin) return;
|
||||
const send = (message: EditorPreviewHostMessage) =>
|
||||
frame.current?.contentWindow?.postMessage(message, origin);
|
||||
send({
|
||||
protocol: "personal-brand-editor-preview",
|
||||
version: 1,
|
||||
type: "brandDraft",
|
||||
brand: brandDraft,
|
||||
});
|
||||
if (workspace) {
|
||||
send({
|
||||
protocol: "personal-brand-editor-preview",
|
||||
version: 1,
|
||||
type: "workspaceDraft",
|
||||
workspace,
|
||||
});
|
||||
} else {
|
||||
send({
|
||||
protocol: "personal-brand-editor-preview",
|
||||
version: 1,
|
||||
type: "brandDraft",
|
||||
brand: brandDraft,
|
||||
});
|
||||
}
|
||||
if (targetKey)
|
||||
send({
|
||||
protocol: "personal-brand-editor-preview",
|
||||
@@ -93,7 +102,7 @@ export function TemplatePreview({
|
||||
type: "focusTarget",
|
||||
targetKey,
|
||||
});
|
||||
}, [brandDraft, origin, ready, targetKey]);
|
||||
}, [brandDraft, origin, ready, targetKey, workspace]);
|
||||
|
||||
useEffect(() => {
|
||||
const refresh = () => setReloadKey((value) => value + 1);
|
||||
@@ -106,30 +115,42 @@ export function TemplatePreview({
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message="尚未配置模板预览服务"
|
||||
description="请在 Admin 环境变量 VITE_TEMPLATE_PREVIEW_URLS 中为模板配置 H5 预览地址。"
|
||||
message="页面预览暂不可用"
|
||||
description="请确认模板预览资源已构建并发布,或本地预览服务正在运行。"
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="template-preview">
|
||||
{!ready && !error ? (
|
||||
<div className="template-preview__loading">
|
||||
<Spin tip="正在加载页面预览" />
|
||||
</div>
|
||||
{workspace ? (
|
||||
<ComponentTemplatePreview
|
||||
workspace={workspace}
|
||||
page={page}
|
||||
{...(targetKey ? { targetKey } : {})}
|
||||
onTargetSelected={onTargetSelected}
|
||||
/>
|
||||
) : null}
|
||||
{error ? (
|
||||
<Alert type="error" showIcon message="页面预览加载失败" description={error} />
|
||||
{!workspace ? (
|
||||
<>
|
||||
{!ready && !error ? (
|
||||
<div className="template-preview__loading">
|
||||
<Spin tip="正在加载页面预览" />
|
||||
</div>
|
||||
) : null}
|
||||
{error ? (
|
||||
<Alert type="error" showIcon message="页面预览加载失败" description={error} />
|
||||
) : null}
|
||||
<iframe
|
||||
key={url}
|
||||
ref={frame}
|
||||
title="小程序页面预览"
|
||||
src={url}
|
||||
referrerPolicy="origin"
|
||||
onError={() => setError("请检查预览服务地址和网络连接。")}
|
||||
style={{ opacity: ready ? 1 : 0 }}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
<iframe
|
||||
key={url}
|
||||
ref={frame}
|
||||
title="小程序页面预览"
|
||||
src={url}
|
||||
referrerPolicy="origin"
|
||||
onError={() => setError("请检查预览服务地址和网络连接。")}
|
||||
style={{ opacity: ready ? 1 : 0 }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { ComponentType } from "react";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||
|
||||
declare module "./component-renderers.jsx" {
|
||||
export function resolveTemplateRenderer(workspace: RuntimeWorkspace): ComponentType<{
|
||||
workspace: RuntimeWorkspace;
|
||||
page: string;
|
||||
offeringId?: string;
|
||||
}>;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { TemplatePage as FoodTemplatePage } from "../../../../../packages/template-acheng-campus-food/taro/index.tsx";
|
||||
import { TemplatePage as EditorialTemplatePage } from "../../../../../packages/template-linjing-editorial/taro/index.tsx";
|
||||
import React from "react";
|
||||
import { TemplateAssetContext } from "./taro-web-components.jsx";
|
||||
|
||||
function FoodPreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value="acheng-campus-food">
|
||||
<FoodTemplatePage {...props} />
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
}
|
||||
function EditorialPreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value="linjing-editorial">
|
||||
<EditorialTemplatePage {...props} />
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveTemplateRenderer(workspace) {
|
||||
const config = workspace?.brand?.config;
|
||||
const key =
|
||||
config && typeof config === "object" && !Array.isArray(config)
|
||||
? config.visualTemplateKey
|
||||
: undefined;
|
||||
return key === "linjing-editorial" ? EditorialPreview : FoodPreview;
|
||||
}
|
||||
@@ -31,11 +31,14 @@ function asObject(value: unknown): Record<string, unknown> {
|
||||
}
|
||||
|
||||
function safePath(binding: string): string[] | null {
|
||||
const prefix = ["brand.config.", "offering.config.", "trust.config."].find((candidate) =>
|
||||
binding.startsWith(candidate),
|
||||
);
|
||||
if (!prefix) return null;
|
||||
const path = binding.slice(prefix.length).split(".");
|
||||
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(
|
||||
binding,
|
||||
);
|
||||
if (!prefix && !standardBrandField) return null;
|
||||
const path = prefix ? binding.slice(prefix.length).split(".") : [binding.slice("brand.".length)];
|
||||
if (path.some((part) => !part || ["__proto__", "prototype", "constructor"].includes(part)))
|
||||
return null;
|
||||
return path;
|
||||
@@ -49,10 +52,15 @@ export function readPresentationValue(
|
||||
config: Record<string, unknown> | null | undefined,
|
||||
binding: string,
|
||||
field?: PresentationField,
|
||||
brand?: Record<string, unknown>,
|
||||
): unknown {
|
||||
const path = safePath(binding);
|
||||
if (!path) return undefined;
|
||||
let value: unknown = asObject(config);
|
||||
const isConfigBinding =
|
||||
binding.startsWith("brand.config.") ||
|
||||
binding.startsWith("offering.config.") ||
|
||||
binding.startsWith("trust.config.");
|
||||
let value: unknown = isConfigBinding ? asObject(config) : asObject(brand);
|
||||
for (const part of path) value = asObject(value)[part];
|
||||
if (field?.input === "list") {
|
||||
if (!Array.isArray(value)) return [];
|
||||
@@ -104,3 +112,33 @@ export function applyPresentationValues(
|
||||
}
|
||||
return nextConfig;
|
||||
}
|
||||
|
||||
export function applyStandardBrandValues(
|
||||
brand: Record<string, unknown>,
|
||||
sections: PresentationSection[],
|
||||
values: PresentationValues,
|
||||
): Record<string, unknown> {
|
||||
const next = { ...brand };
|
||||
for (const section of sections) {
|
||||
for (const field of section.fields) {
|
||||
if (!field.binding.startsWith("brand.") || field.binding.startsWith("brand.config."))
|
||||
continue;
|
||||
const value = values[presentationFieldName(section.key, field.key)];
|
||||
if (value !== undefined) next[field.binding.slice("brand.".length)] = value;
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
export function applyBrandPreviewValues(
|
||||
brand: Record<string, unknown>,
|
||||
config: Record<string, unknown> | null | undefined,
|
||||
sections: PresentationSection[],
|
||||
values: PresentationValues,
|
||||
): Record<string, unknown> {
|
||||
const nextBrand = applyStandardBrandValues(brand, sections, values);
|
||||
return {
|
||||
...nextBrand,
|
||||
config: applyPresentationValues(config, sections, values),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import React from "react";
|
||||
|
||||
export const TemplateAssetContext = React.createContext("");
|
||||
const templateAssets = import.meta.glob("../../../../../packages/template-*/miniapp/assets/**/*", {
|
||||
eager: true,
|
||||
query: "?url",
|
||||
import: "default",
|
||||
});
|
||||
|
||||
function resolveImageSource(src, templateKey) {
|
||||
if (typeof src !== "string" || !src.startsWith("/assets/")) return src;
|
||||
const relative = src.slice("/assets/".length);
|
||||
for (const [file, url] of Object.entries(templateAssets)) {
|
||||
const parts = file.split("/packages/template-")[1]?.split("/miniapp/assets/");
|
||||
if (!parts) continue;
|
||||
const [key, asset] = parts;
|
||||
if (relative === key + "/" + asset || (key === templateKey && relative === asset)) return url;
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
const element = (tag) =>
|
||||
React.forwardRef(({ children, className, style, onClick, ...props }, ref) =>
|
||||
React.createElement(tag, { ...props, ref, className, style, onClick }, children),
|
||||
);
|
||||
|
||||
export const View = element("div");
|
||||
export const Text = element("span");
|
||||
export const Button = element("button");
|
||||
export const Input = React.forwardRef((props, ref) =>
|
||||
React.createElement("input", { ...props, ref }),
|
||||
);
|
||||
export const Image = React.forwardRef(({ mode, src, style, ...props }, ref) => {
|
||||
const key = React.useContext(TemplateAssetContext);
|
||||
return React.createElement("img", {
|
||||
...props,
|
||||
ref,
|
||||
src: resolveImageSource(src, key),
|
||||
style: { objectFit: mode === "aspectFit" ? "contain" : "cover", ...style },
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
const noop = () => Promise.resolve();
|
||||
const Taro = {
|
||||
setStorageSync() {},
|
||||
getStorageSync() {
|
||||
return undefined;
|
||||
},
|
||||
removeStorageSync() {},
|
||||
switchTab: noop,
|
||||
navigateTo: noop,
|
||||
};
|
||||
export default Taro;
|
||||
@@ -1,25 +1,13 @@
|
||||
export function templatePreviewUrl(
|
||||
templateKey: string,
|
||||
brandSlug: string | undefined,
|
||||
page: string,
|
||||
configured: string | undefined,
|
||||
parentOrigin?: string,
|
||||
route?: string,
|
||||
): string | undefined {
|
||||
let urls: Record<string, unknown>;
|
||||
const raw = configured || "http://localhost:3002";
|
||||
try {
|
||||
const parsed: unknown = configured ? JSON.parse(configured) : {};
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
||||
return undefined;
|
||||
}
|
||||
urls = parsed as Record<string, unknown>;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
const raw = urls[templateKey];
|
||||
if (typeof raw !== "string" || !raw) return undefined;
|
||||
try {
|
||||
const url = new URL(raw);
|
||||
const url = new URL(raw, parentOrigin);
|
||||
url.searchParams.set("editor", "1");
|
||||
if (parentOrigin) url.searchParams.set("parentOrigin", parentOrigin);
|
||||
if (brandSlug) url.searchParams.set("brand", brandSlug);
|
||||
|
||||
Vendored
+3
-1
@@ -1,7 +1,9 @@
|
||||
interface ImportMetaEnv {
|
||||
readonly DEV: boolean;
|
||||
readonly PROD: boolean;
|
||||
readonly VITE_API_BASE_URL?: string;
|
||||
readonly VITE_APP_BASE_PATH?: string;
|
||||
readonly VITE_TEMPLATE_PREVIEW_URLS?: string;
|
||||
readonly VITE_TEMPLATE_PREVIEW_URL?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// 模板 CSS 使用 Taro 的 750 设计宽度,转换到预览容器单位。
|
||||
export function templatePreviewCss() {
|
||||
return {
|
||||
postcssPlugin: "template-preview-css",
|
||||
Once(root) {
|
||||
const file = root.source?.input.file || "";
|
||||
if (!file.includes("/packages/template-") || !file.endsWith("/taro/style.css")) return;
|
||||
root.walkRules((rule) => {
|
||||
rule.selector = rule.selector
|
||||
.split(",")
|
||||
.map(
|
||||
(selector) =>
|
||||
".component-template-preview__canvas " +
|
||||
selector
|
||||
.trim()
|
||||
.replace(
|
||||
/(^|[ >+~])(image|text|view)(?=[ .#:[>+~)]|$)/g,
|
||||
(_, prefix, tag) => prefix + { image: "img", text: "span", view: "div" }[tag],
|
||||
),
|
||||
)
|
||||
.join(", ");
|
||||
});
|
||||
root.walkDecls((declaration) => {
|
||||
declaration.value = declaration.value.replace(
|
||||
/(-?(?:[0-9]*[.])?[0-9]+)px/g,
|
||||
(_, value) => Number((Number(value) / 7.5).toFixed(8)) + "cqw",
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
applyBrandPreviewValues,
|
||||
filterSectionsForPreviewTarget,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
@@ -124,3 +125,26 @@ const offering = applyPresentationValues(
|
||||
{ [presentationFieldName("offering", "background")]: "新背景" },
|
||||
);
|
||||
assert.deepEqual(offering.details, { background: "新背景", preserve: "保留" });
|
||||
|
||||
const brandDraft = applyBrandPreviewValues(
|
||||
{ description: "旧简介", address: "旧地址", config: { visualPresentation: {} } },
|
||||
{ visualPresentation: {} },
|
||||
[
|
||||
{
|
||||
key: "identity",
|
||||
fields: [
|
||||
{ key: "description", binding: "brand.description" },
|
||||
{ key: "address", binding: "brand.address" },
|
||||
{ key: "headline", binding: "brand.config.visualPresentation.home.title" },
|
||||
],
|
||||
},
|
||||
],
|
||||
{
|
||||
[presentationFieldName("identity", "description")]: "新简介",
|
||||
[presentationFieldName("identity", "address")]: "新地址",
|
||||
[presentationFieldName("identity", "headline")]: "新标题",
|
||||
},
|
||||
);
|
||||
assert.equal(brandDraft.description, "新简介");
|
||||
assert.equal(brandDraft.address, "新地址");
|
||||
assert.equal(brandDraft.config.visualPresentation.home.title, "新标题");
|
||||
@@ -2,12 +2,11 @@ import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { templatePreviewUrl } from "../src/lib/template-preview.ts";
|
||||
|
||||
test("template preview URL is resolved from generic deployment configuration", () => {
|
||||
test("template preview URL is resolved from one shared deployment address", () => {
|
||||
const url = templatePreviewUrl(
|
||||
"new-template",
|
||||
"brand-a",
|
||||
"profile",
|
||||
JSON.stringify({ "new-template": "https://preview.example.test/app/" }),
|
||||
"https://preview.example.test/app/",
|
||||
"https://admin.example.test",
|
||||
"/pages/profile/index",
|
||||
);
|
||||
@@ -17,11 +16,18 @@ test("template preview URL is resolved from generic deployment configuration", (
|
||||
);
|
||||
});
|
||||
|
||||
test("missing, malformed or invalid template preview configuration fails closed", () => {
|
||||
assert.equal(templatePreviewUrl("missing", "brand-a", "home", undefined), undefined);
|
||||
assert.equal(templatePreviewUrl("missing", "brand-a", "home", "{"), undefined);
|
||||
test("the shared same-origin preview address is the default", () => {
|
||||
assert.equal(
|
||||
templatePreviewUrl("broken", "brand-a", "home", JSON.stringify({ broken: "not a URL" })),
|
||||
undefined,
|
||||
templatePreviewUrl("brand-a", "home", undefined),
|
||||
"http://localhost:3002/?editor=1&brand=brand-a#/pages/home/index",
|
||||
);
|
||||
assert.equal(templatePreviewUrl("brand-a", "home", "{"), undefined);
|
||||
assert.equal(templatePreviewUrl("brand-a", "home", "not a URL"), undefined);
|
||||
});
|
||||
|
||||
test("same-origin static preview uses its explicit entry document", () => {
|
||||
assert.equal(
|
||||
templatePreviewUrl("brand-a", "home", "/template-preview/index.html", "http://localhost:3005"),
|
||||
"http://localhost:3005/template-preview/index.html?editor=1&parentOrigin=http%3A%2F%2Flocalhost%3A3005&brand=brand-a#/pages/home/index",
|
||||
);
|
||||
});
|
||||
@@ -1,9 +1,22 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { templatePreviewCss } from "./template-preview-css.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
css: { postcss: { plugins: [templatePreviewCss()] } },
|
||||
base: process.env.VITE_APP_BASE_PATH ?? "/",
|
||||
resolve: {
|
||||
alias: {
|
||||
"@tarojs/components": `${process.cwd()}/src/features/brand/taro-web-components.jsx`,
|
||||
"@tarojs/taro": `${process.cwd()}/src/features/brand/taro-web-runtime.jsx`,
|
||||
},
|
||||
},
|
||||
define: {
|
||||
"process.env.TARO_PLATFORM": JSON.stringify("web"),
|
||||
PREVIEW_ALL_TEMPLATES: JSON.stringify(true),
|
||||
TEMPLATE_MANIFEST: JSON.stringify({ navigation: [] }),
|
||||
},
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
port: Number(process.env.ADMIN_PORT ?? 3000),
|
||||
|
||||
@@ -36,12 +36,14 @@ import {
|
||||
} from "@personal-brand/config";
|
||||
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
||||
import { validateFieldSnapshot, validateOfferingConfig } from "@personal-brand/validation";
|
||||
import { PublicWorkspaceService } from "./modules/public/public-workspace.controller.js";
|
||||
|
||||
@Controller("admin/workspace")
|
||||
class AdminWorkspaceController {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly templateWorkspace: TemplateWorkspaceService,
|
||||
private readonly publicWorkspace: PublicWorkspaceService,
|
||||
) {}
|
||||
private brandId(): string {
|
||||
return process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
||||
@@ -194,6 +196,11 @@ class AdminWorkspaceController {
|
||||
: null,
|
||||
};
|
||||
}
|
||||
@Get("preview")
|
||||
async getPreviewWorkspace(@Req() request: FastifyRequest): Promise<unknown> {
|
||||
const { brandId } = this.requireAdmin(request);
|
||||
return this.publicWorkspace.getForBrandId(brandId);
|
||||
}
|
||||
private jsonObject(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" && !Array.isArray(value)
|
||||
? (value as Record<string, unknown>)
|
||||
|
||||
@@ -7,7 +7,10 @@ import { BookingService } from "./booking.service.js";
|
||||
import { AdminAuthService } from "./admin-auth.service.js";
|
||||
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
||||
import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
||||
import { PublicWorkspaceController } from "./modules/public/public-workspace.controller.js";
|
||||
import {
|
||||
PublicWorkspaceController,
|
||||
PublicWorkspaceService,
|
||||
} from "./modules/public/public-workspace.controller.js";
|
||||
import { PublicBrandContextService } from "./modules/public/public-brand-context.service.js";
|
||||
import { AdminConfigController } from "./modules/admin/admin-config.controller.js";
|
||||
import { PublicOfferingController } from "./modules/public/public-offering.controller.js";
|
||||
@@ -70,6 +73,7 @@ export class HealthController {
|
||||
BrandReleaseService,
|
||||
BrandReleaseApiService,
|
||||
PublicBrandContextService,
|
||||
PublicWorkspaceService,
|
||||
],
|
||||
exports: [PrismaService, WechatAuthService],
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, Query } from "@nestjs/common";
|
||||
import { Controller, Get, Injectable, Query } from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { PrismaService } from "../../prisma.service.js";
|
||||
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||
@@ -26,15 +26,11 @@ import {
|
||||
projectTrustPresentation,
|
||||
} from "@personal-brand/types";
|
||||
|
||||
@Controller("public/workspace")
|
||||
export class PublicWorkspaceController {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly brandContext: PublicBrandContextService,
|
||||
) {}
|
||||
@Get()
|
||||
async get(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||
const brandId = await this.brandContext.resolveId(brandSlug);
|
||||
@Injectable()
|
||||
export class PublicWorkspaceService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async getForBrandId(brandId: string): Promise<unknown> {
|
||||
const release = await this.prisma.brandRelease.findFirst({
|
||||
where: { brandId, status: "published" },
|
||||
orderBy: { version: "desc" },
|
||||
@@ -370,3 +366,17 @@ export class PublicWorkspaceController {
|
||||
return value === "create-booking" || value === "create-quote" ? value : "create-inquiry";
|
||||
}
|
||||
}
|
||||
|
||||
@Controller("public/workspace")
|
||||
export class PublicWorkspaceController {
|
||||
constructor(
|
||||
private readonly brandContext: PublicBrandContextService,
|
||||
private readonly workspaceService: PublicWorkspaceService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
async get(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||
const brandId = await this.brandContext.resolveId(brandSlug);
|
||||
return this.workspaceService.getForBrandId(brandId);
|
||||
}
|
||||
}
|
||||
@@ -1325,6 +1325,28 @@ test("admin can install a template and public workspace exposes enabled configur
|
||||
}
|
||||
});
|
||||
|
||||
test("admin preview workspace is brand-scoped and exposes only the published runtime", async () => {
|
||||
const user = await prisma.adminUser.findUniqueOrThrow({ where: { username: "admin" } });
|
||||
const token = signIdentity({ subject: user.id, brandId, role: "admin" });
|
||||
const unauthorized = await request("/admin/workspace/preview");
|
||||
assert.equal(unauthorized.statusCode, 401);
|
||||
const wrongRole = await request("/admin/workspace/preview", {
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
});
|
||||
assert.equal(wrongRole.statusCode, 403);
|
||||
const authorized = await request("/admin/workspace/preview", {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
});
|
||||
assert.equal(authorized.statusCode, 200);
|
||||
const workspace = JSON.parse(authorized.body);
|
||||
assert.equal(workspace.publication?.status, "published");
|
||||
assert.equal(
|
||||
workspace.brand.slug,
|
||||
(await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } })).slug,
|
||||
);
|
||||
assert.equal(workspace.brand.visualTemplateKey, "acheng-campus-food");
|
||||
});
|
||||
|
||||
test("admin can customize workspace fields with brand isolation", async () => {
|
||||
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
|
||||
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
|
||||
|
||||
@@ -4,6 +4,7 @@ import fs from "node:fs";
|
||||
|
||||
const root = path.resolve(__dirname, "../../..");
|
||||
const key = process.env.TEMPLATE_KEY || "acheng-campus-food";
|
||||
const previewAllTemplates = process.env.PREVIEW_ALL_TEMPLATES === "true";
|
||||
const templates = fs
|
||||
.readdirSync(path.join(root, "packages"))
|
||||
.filter(
|
||||
@@ -30,20 +31,33 @@ export default defineConfig({
|
||||
designWidth: 750,
|
||||
deviceRatio: { 750: 1 },
|
||||
sourceRoot: "src",
|
||||
outputRoot: `dist/${key}/${process.env.TARO_ENV || "weapp"}`,
|
||||
outputRoot: previewAllTemplates
|
||||
? "dist/template-preview/h5"
|
||||
: `dist/${key}/${process.env.TARO_ENV || "weapp"}`,
|
||||
framework: "react",
|
||||
compiler: { type: "vite" },
|
||||
plugins: [],
|
||||
alias: { "@template": path.join(template, "taro") },
|
||||
alias: {
|
||||
"@template": previewAllTemplates
|
||||
? path.resolve(__dirname, "../src/runtime/template-preview-entry.tsx")
|
||||
: path.join(template, "taro"),
|
||||
},
|
||||
defineConstants: {
|
||||
TEMPLATE_KEY: JSON.stringify(key),
|
||||
BRAND_SLUG: JSON.stringify(brand),
|
||||
API_BASE_URL: JSON.stringify(process.env.API_BASE_URL || "http://localhost:3001"),
|
||||
TEMPLATE_MANIFEST: JSON.stringify(manifest),
|
||||
PREVIEW_ALL_TEMPLATES: JSON.stringify(previewAllTemplates),
|
||||
},
|
||||
copy: {
|
||||
options: {},
|
||||
patterns: [
|
||||
...(previewAllTemplates
|
||||
? templates.map((templateKey) => ({
|
||||
from: path.join(root, "packages", `template-${templateKey}`, "miniapp/assets"),
|
||||
to: `dist/template-preview/h5/assets/${templateKey}`,
|
||||
}))
|
||||
: []),
|
||||
...(process.env.TARO_ENV === "weapp"
|
||||
? [
|
||||
{
|
||||
@@ -52,15 +66,19 @@ export default defineConfig({
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
from: path.join(template, "miniapp/assets"),
|
||||
to: `dist/${key}/${process.env.TARO_ENV || "weapp"}/assets`,
|
||||
},
|
||||
...(!previewAllTemplates
|
||||
? [
|
||||
{
|
||||
from: path.join(template, "miniapp/assets"),
|
||||
to: `dist/${key}/${process.env.TARO_ENV || "weapp"}/assets`,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
mini: {},
|
||||
h5: {
|
||||
publicPath: "/",
|
||||
publicPath: process.env.PREVIEW_PUBLIC_PATH || "/",
|
||||
router: { mode: "hash" },
|
||||
devServer: { host: "0.0.0.0", port: Number(process.env.PREVIEW_PORT || 3002) },
|
||||
},
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev:h5": "taro build --type h5 --watch",
|
||||
"dev:preview": "PREVIEW_ALL_TEMPLATES=true taro build --type h5 --watch",
|
||||
"build:h5": "taro build --type h5",
|
||||
"build:preview": "PREVIEW_ALL_TEMPLATES=true taro build --type h5",
|
||||
"build:weapp": "taro build --type weapp",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"lint": "pnpm --workspace-root exec eslint apps/taro/src apps/taro/config packages/template-acheng-campus-food/taro packages/template-linjing-editorial/taro",
|
||||
|
||||
+15
-11
@@ -21,15 +21,19 @@ export default defineAppConfig({
|
||||
navigationBarBackgroundColor: "#ffffff",
|
||||
navigationBarTextStyle: "black",
|
||||
},
|
||||
tabBar: {
|
||||
color: "#8b8178",
|
||||
selectedColor: "#3b2118",
|
||||
backgroundColor: "#ffffff",
|
||||
list: TEMPLATE_MANIFEST.navigation.map((tab) => ({
|
||||
pagePath: routes[tab.page],
|
||||
text: tab.label,
|
||||
iconPath: tab.iconPath,
|
||||
selectedIconPath: tab.selectedIconPath,
|
||||
})),
|
||||
},
|
||||
...(!PREVIEW_ALL_TEMPLATES
|
||||
? {
|
||||
tabBar: {
|
||||
color: "#8b8178",
|
||||
selectedColor: "#3b2118",
|
||||
backgroundColor: "#ffffff",
|
||||
list: TEMPLATE_MANIFEST.navigation.map((tab) => ({
|
||||
pagePath: routes[tab.page],
|
||||
text: tab.label,
|
||||
iconPath: tab.iconPath,
|
||||
selectedIconPath: tab.selectedIconPath,
|
||||
})),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
@@ -9,7 +9,7 @@ import { Inquiry } from "./Inquiry";
|
||||
import { Records } from "./Records";
|
||||
import { Success } from "./Success";
|
||||
export function Page({ page }: { page: PageKey }) {
|
||||
const { workspace, error, loading, reload, setBrandDraft } = useWorkspace();
|
||||
const { workspace, error, loading, reload, setBrandDraft, setWorkspaceDraft } = useWorkspace();
|
||||
const router = useRouter();
|
||||
useEffect(() => {
|
||||
if (process.env.TARO_ENV !== "h5" || window.parent === window) return;
|
||||
@@ -27,6 +27,7 @@ export function Page({ page }: { page: PageKey }) {
|
||||
if (event.source !== window.parent || event.origin !== parentOrigin) return;
|
||||
const message = event.data;
|
||||
if (message?.protocol !== "personal-brand-editor-preview" || message.version !== 1) return;
|
||||
if (message.type === "workspaceDraft") setWorkspaceDraft(message.workspace);
|
||||
if (message.type === "brandDraft") setBrandDraft(message.brand);
|
||||
if (message.type === "focusTarget") {
|
||||
document.querySelectorAll<HTMLElement>("[data-editor-target]").forEach((element) => {
|
||||
@@ -63,7 +64,7 @@ export function Page({ page }: { page: PageKey }) {
|
||||
window.removeEventListener("message", onMessage);
|
||||
document.removeEventListener("click", onClick, true);
|
||||
};
|
||||
}, [setBrandDraft]);
|
||||
}, [setBrandDraft, setWorkspaceDraft]);
|
||||
if (loading) return <View className="runtime-state">正在加载…</View>;
|
||||
if (error || !workspace)
|
||||
return (
|
||||
|
||||
Vendored
+4
@@ -12,7 +12,11 @@ declare const TEMPLATE_MANIFEST: {
|
||||
selectedIconPath: string;
|
||||
}[];
|
||||
};
|
||||
declare const PREVIEW_ALL_TEMPLATES: boolean;
|
||||
declare module "*.css";
|
||||
interface ImportMeta {
|
||||
glob<T = unknown>(pattern: string, options?: { eager?: boolean }): Record<string, T>;
|
||||
}
|
||||
declare module "@template" {
|
||||
export { TemplatePage } from "../../../packages/template-acheng-campus-food/taro";
|
||||
}
|
||||
@@ -7,6 +7,12 @@ export function brandSlug() {
|
||||
}
|
||||
return BRAND_SLUG;
|
||||
}
|
||||
function isEditorPreview() {
|
||||
return (
|
||||
process.env.TARO_ENV === "h5" &&
|
||||
new URLSearchParams(window.location.search).get("editor") === "1"
|
||||
);
|
||||
}
|
||||
export const tokenKey = () => `customerToken:${brandSlug()}`;
|
||||
export function hasSession() {
|
||||
return Boolean(Taro.getStorageSync<string>(tokenKey()));
|
||||
@@ -16,9 +22,10 @@ export async function request<T>(
|
||||
options: { method?: "GET" | "POST"; data?: unknown; customer?: boolean } = {},
|
||||
): Promise<T> {
|
||||
const context = path.startsWith("/public/") || path.startsWith("/customer/session/wechat");
|
||||
const query = context
|
||||
? `${path.includes("?") ? "&" : "?"}brandSlug=${encodeURIComponent(brandSlug())}`
|
||||
: "";
|
||||
const query =
|
||||
context && !(isEditorPreview() && path === "/public/workspace")
|
||||
? `${path.includes("?") ? "&" : "?"}brandSlug=${encodeURIComponent(brandSlug())}`
|
||||
: "";
|
||||
const response = await Taro.request<T & { error?: { message?: string; requestId?: string } }>({
|
||||
url: API_BASE_URL.replace(/\/$/, "") + path + query,
|
||||
method: options.method || "GET",
|
||||
@@ -38,9 +45,7 @@ export async function request<T>(
|
||||
}
|
||||
export async function loadWorkspace() {
|
||||
const data = await request<RuntimeWorkspace>("/public/workspace");
|
||||
const editorPreview =
|
||||
process.env.TARO_ENV === "h5" &&
|
||||
new URLSearchParams(window.location.search).get("editor") === "1";
|
||||
const editorPreview = isEditorPreview();
|
||||
if (!editorPreview && data.publication?.status !== "published") throw new Error("品牌尚未发布");
|
||||
if (!editorPreview && data.brand.visualTemplateKey !== TEMPLATE_KEY)
|
||||
throw new Error("该品牌使用其他模板,请选择匹配的模板预览地址");
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { ComponentType } from "react";
|
||||
import type { TemplateProps } from "./template";
|
||||
|
||||
type TemplateRenderer = ComponentType<TemplateProps>;
|
||||
|
||||
const renderers = import.meta.glob<{
|
||||
TemplatePage: TemplateRenderer;
|
||||
}>("../../../../packages/template-*/taro/index.tsx", { eager: true });
|
||||
|
||||
export function TemplatePage(props: TemplateProps) {
|
||||
const config = props.workspace.brand.config;
|
||||
const visualTemplateKey =
|
||||
config && typeof config === "object" && !Array.isArray(config)
|
||||
? (config as Record<string, unknown>).visualTemplateKey
|
||||
: undefined;
|
||||
const templateKey = typeof visualTemplateKey === "string" ? visualTemplateKey : TEMPLATE_KEY;
|
||||
const suffix = `/template-${templateKey}/taro/index.tsx`;
|
||||
const rendererModule = Object.entries(renderers).find(([path]) => path.endsWith(suffix))?.[1];
|
||||
if (!rendererModule)
|
||||
return <div className="runtime-state">当前模板没有可用的 H5 预览 renderer</div>;
|
||||
const Renderer = rendererModule.TemplatePage;
|
||||
return <Renderer {...props} />;
|
||||
}
|
||||
@@ -8,19 +8,22 @@ const Context = createContext<{
|
||||
error: string;
|
||||
loading: boolean;
|
||||
setBrandDraft: (brand: Partial<RuntimeWorkspace["brand"]>) => void;
|
||||
setWorkspaceDraft: (workspace: RuntimeWorkspace) => void;
|
||||
reload: () => void;
|
||||
}>({ error: "", loading: true, setBrandDraft() {}, reload() {} });
|
||||
}>({ error: "", loading: true, setBrandDraft() {}, setWorkspaceDraft() {}, reload() {} });
|
||||
export function WorkspaceProvider({ children }: PropsWithChildren) {
|
||||
const [baseWorkspace, setBaseWorkspace] = useState<RuntimeWorkspace>();
|
||||
const [brandDraft, setBrandDraft] = useState<Partial<RuntimeWorkspace["brand"]>>({});
|
||||
const workspace = baseWorkspace
|
||||
const [workspaceDraft, setWorkspaceDraft] = useState<RuntimeWorkspace>();
|
||||
const workspace = workspaceDraft ?? baseWorkspace;
|
||||
const resolvedWorkspace = workspace
|
||||
? {
|
||||
...baseWorkspace,
|
||||
...workspace,
|
||||
brand: projectBrandAliases(
|
||||
{ ...baseWorkspace.brand, ...brandDraft },
|
||||
{ ...workspace.brand, ...brandDraft },
|
||||
brandDraft.config && typeof brandDraft.config === "object"
|
||||
? (brandDraft.config as Record<string, unknown>)
|
||||
: ((baseWorkspace.brand.config as Record<string, unknown> | undefined) ?? {}),
|
||||
: ((workspace.brand.config as Record<string, unknown> | undefined) ?? {}),
|
||||
),
|
||||
}
|
||||
: undefined;
|
||||
@@ -29,16 +32,35 @@ export function WorkspaceProvider({ children }: PropsWithChildren) {
|
||||
const reload = useCallback(() => {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
void loadWorkspace()
|
||||
.then(setBaseWorkspace)
|
||||
const editorPreview =
|
||||
process.env.TARO_ENV === "h5" &&
|
||||
new URLSearchParams(window.location.search).get("editor") === "1";
|
||||
const workspacePromise = editorPreview ? Promise.resolve(undefined) : loadWorkspace();
|
||||
void workspacePromise
|
||||
.then((value) => {
|
||||
if (value) setBaseWorkspace(value);
|
||||
})
|
||||
.catch((error: unknown) =>
|
||||
setError(error instanceof Error ? error.message : "加载失败,请重试"),
|
||||
)
|
||||
.finally(() => setLoading(false));
|
||||
.finally(() => setLoading(!editorPreview));
|
||||
}, []);
|
||||
useEffect(reload, [reload]);
|
||||
return (
|
||||
<Context.Provider value={{ workspace, error, loading, setBrandDraft, reload }}>
|
||||
<Context.Provider
|
||||
value={{
|
||||
workspace: resolvedWorkspace,
|
||||
error,
|
||||
loading:
|
||||
process.env.TARO_ENV === "h5" &&
|
||||
new URLSearchParams(window.location.search).get("editor") === "1"
|
||||
? !workspace
|
||||
: loading,
|
||||
setBrandDraft,
|
||||
setWorkspaceDraft,
|
||||
reload,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Context.Provider>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
const adminOrigin = "http://localhost:3011";
|
||||
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
||||
const brand = {
|
||||
id: "brand-fixture",
|
||||
slug: "preview-fixture",
|
||||
@@ -8,7 +8,7 @@ const brand = {
|
||||
templateKey: "food",
|
||||
tagline: "校园家常餐",
|
||||
description: "认真做好每一餐",
|
||||
avatarUrl: "",
|
||||
avatarUrl: "/assets/owner/portrait.jpg",
|
||||
coverUrl: "",
|
||||
hours: "每日 17:00",
|
||||
address: "东门附近",
|
||||
@@ -35,7 +35,16 @@ const runtimeWorkspace = {
|
||||
},
|
||||
templateData: {},
|
||||
navigation: { tabs: [] },
|
||||
offerings: [],
|
||||
offerings: [
|
||||
{
|
||||
id: "menu-fixture",
|
||||
name: "家庭聚餐定制",
|
||||
summary: "为同学聚餐、家庭聚会提供常见的私房菜定制。",
|
||||
priceText: "88.88",
|
||||
coverUrl: brand.avatarUrl,
|
||||
presentation: { categoryLabel: "业务提供项", keywords: [], details: [] },
|
||||
},
|
||||
],
|
||||
inquiryForms: [],
|
||||
trustItems: [],
|
||||
trustPresentation: {},
|
||||
@@ -44,7 +53,10 @@ const runtimeWorkspace = {
|
||||
};
|
||||
const templateContent = {
|
||||
displayName: "餐饮模板",
|
||||
navigation: [{ key: "home", page: "home", label: "首页" }],
|
||||
navigation: [
|
||||
{ key: "home", page: "home", label: "首页" },
|
||||
{ key: "offerings", page: "offerings", label: "套餐餐品" },
|
||||
],
|
||||
assetSlots: [],
|
||||
trustContentTypes: [],
|
||||
admin: {
|
||||
@@ -88,6 +100,7 @@ const templateContent = {
|
||||
};
|
||||
|
||||
test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 1000 });
|
||||
await page.route("http://localhost:3001/public/workspace**", (route) =>
|
||||
route.fulfill({ json: runtimeWorkspace }),
|
||||
);
|
||||
@@ -116,6 +129,8 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
return route.fulfill({
|
||||
json: { brand, installations: [], fields: [], offerings: [], forms: [], templateContent },
|
||||
});
|
||||
if (url.pathname === "/admin/workspace/preview")
|
||||
return route.fulfill({ json: runtimeWorkspace });
|
||||
if (url.pathname === "/public/templates/food")
|
||||
return route.fulfill({
|
||||
json: { name: "餐饮模板", description: "fixture", serviceCategories: [] },
|
||||
@@ -129,16 +144,75 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
await page.getByLabel("密码").fill("fixture-password");
|
||||
await page.locator('button[type="submit"]').click();
|
||||
await expect(page.getByText("小程序页面配置")).toBeVisible();
|
||||
const frame = page.frameLocator('iframe[title="小程序页面预览"]');
|
||||
await expect(frame.locator(".food-home .name")).toContainText("测试主理人");
|
||||
await frame.locator('[data-editor-target="food.home.location"]').click();
|
||||
const preview = page.locator(".component-template-preview");
|
||||
await expect(preview.locator(".food-home .name")).toContainText("测试主理人");
|
||||
const dimensions = await preview.evaluate((element) => {
|
||||
const canvas = element.querySelector(".component-template-preview__canvas")!;
|
||||
const name = element.querySelector(".name")!;
|
||||
const avatar = element.querySelector(".identity img")!;
|
||||
return {
|
||||
width: canvas.getBoundingClientRect().width,
|
||||
font: parseFloat(getComputedStyle(name).fontSize),
|
||||
avatar: avatar.getBoundingClientRect().width,
|
||||
transform: getComputedStyle(canvas.firstElementChild!).transform,
|
||||
};
|
||||
});
|
||||
expect(dimensions.font / dimensions.width).toBeCloseTo(32 / 750, 3);
|
||||
expect(dimensions.avatar / dimensions.width).toBeCloseTo(128 / 750, 3);
|
||||
expect(dimensions.transform).toBe("none");
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview.locator(".identity img").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
)
|
||||
.toBeGreaterThan(0);
|
||||
await preview.screenshot({ path: "../../.codex-tasks/preview-proportion/home.png" });
|
||||
const actionButtons = preview.locator(".food-home .actions button");
|
||||
await expect(actionButtons).toHaveCount(2);
|
||||
const previewBox = await preview.locator(".component-template-preview__canvas").boundingBox();
|
||||
const firstActionBox = await actionButtons.nth(0).boundingBox();
|
||||
const secondActionBox = await actionButtons.nth(1).boundingBox();
|
||||
expect(previewBox && firstActionBox && secondActionBox).toBeTruthy();
|
||||
expect(firstActionBox!.x).toBeGreaterThanOrEqual(previewBox!.x);
|
||||
expect(secondActionBox!.x + secondActionBox!.width).toBeLessThanOrEqual(
|
||||
previewBox!.x + previewBox!.width,
|
||||
);
|
||||
await expect(actionButtons.nth(0)).toContainText("咨询 / 预订");
|
||||
await expect(actionButtons.nth(1)).toContainText("查看餐品");
|
||||
await preview.locator('[data-editor-target="food.home.location"]').click();
|
||||
await expect(page.getByText("出摊信息标题")).toBeVisible();
|
||||
await expect(page.getByText("招牌餐品标题")).toHaveCount(0);
|
||||
await page.getByLabel("出摊信息标题").fill("后台草稿地点");
|
||||
await expect(preview.locator(".notice-title")).toContainText("后台草稿地点");
|
||||
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||
await expect(frame.locator(".notice-title")).toContainText("后台草稿地点");
|
||||
await expect(frame.locator('[data-editor-target="food.home.location"]')).toHaveClass(
|
||||
await expect(preview.locator('[data-editor-target="food.home.location"]')).toHaveClass(
|
||||
/editor-target-selected/,
|
||||
);
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await expect(preview.locator(".offering-card")).toHaveCount(1);
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview.locator(".dish-media img").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
)
|
||||
.toBeGreaterThan(0);
|
||||
for (const width of [390, 320]) {
|
||||
await preview.locator(".component-template-preview__canvas").evaluate((element, size) => {
|
||||
(element as HTMLElement).style.width = size + "px";
|
||||
}, width);
|
||||
const layout = await preview.evaluate((element) => {
|
||||
const canvas = element.querySelector(".component-template-preview__canvas")!;
|
||||
const card = element.querySelector(".offering-card")!;
|
||||
const media = element.querySelector(".dish-media")!;
|
||||
return {
|
||||
canvas: canvas.getBoundingClientRect().width,
|
||||
overflow: card.scrollWidth - card.clientWidth,
|
||||
media: media.getBoundingClientRect().width,
|
||||
};
|
||||
});
|
||||
expect(layout.overflow).toBeLessThanOrEqual(1);
|
||||
expect(layout.media / layout.canvas).toBeCloseTo(224 / 750, 3);
|
||||
await preview.screenshot({
|
||||
path: "../../.codex-tasks/preview-proportion/menu-" + width + ".png",
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
# 0020:后台可视化页面编辑预览
|
||||
|
||||
## Context
|
||||
|
||||
后台已能根据模板 manifest 展示字段,但管理员难以判断字段对应小程序的哪个区块。Taro H5 renderer 可复用小程序页面结构;按模板分别构建和运行 H5 服务、编译时固定单个 renderer,则无法支撑多个品牌和模板的生产部署。
|
||||
|
||||
## Decision
|
||||
|
||||
采用基于模板 renderer 的可视化编辑器,并将 H5 预览作为同一套 Admin 产品的静态运行时:
|
||||
|
||||
1. `admin.sections` 是编辑字段分组,不等同 DOM 区块。section 声明稳定的 `previewTargets`,字段声明 `previewTarget`。
|
||||
2. renderer 在可编辑区域输出 `data-editor-target`。新增模板必须为所有页面字段声明 binding 和 target,并通过自动发现的契约测试。
|
||||
3. 一个 H5 预览应用在构建时收集所有带 Taro renderer 的模板包,运行时根据品牌当前模板选择 renderer。
|
||||
4. 本地开发只启动一个 Vite H5 预览服务。生产构建将 H5 静态文件复制到 Admin `/template-preview/`,与 Admin 一起部署;线上不运行 Vite,也不按模板运行服务。
|
||||
5. Admin iframe 与 renderer 使用带版本的 `postMessage` 协议,校验 origin、source 和协议版本。Admin 发送品牌草稿和 target focus;renderer 回传 target 选择。
|
||||
6. 表单输入立即投影到预览草稿,保存仍是显式动作。失败时保留用户输入和草稿。
|
||||
7. Admin 按模板契约运行,不按模板 key、行业名或字段名增加业务分支。
|
||||
8. 信任内容、业务提供项、咨询表单等记录数据继续由通用 Admin feature 编辑;它们的页面区域需提供明确的对应编辑入口,不能冒充品牌 config 字段。
|
||||
9. 不支持拖拽布局或持久化 HTML。
|
||||
|
||||
## Alternatives
|
||||
|
||||
- 在 Admin 复制一套 React 预览:会造成后台和小程序视觉分叉,弃用。
|
||||
- 每模板单独构建并运行 H5 服务:开发和部署负担随模板数量增长,弃用。
|
||||
- 生产环境运行 Vite:不是静态部署方案且扩大运行时依赖,弃用。
|
||||
- 将 HTML 存进数据库:无法保持模板升级和字段 binding 一致,弃用。
|
||||
- 一开始建设完整低代码画布:范围过大,暂缓。
|
||||
|
||||
## Consequences
|
||||
|
||||
- Preview build、静态资源打包和部署路径是 Admin 发布门槛。
|
||||
- renderer 需要显式标记可编辑区域;漏掉的字段由模板契约测试拒绝。
|
||||
- H5 iframe 使用当前已发布 workspace 作为底稿,管理员草稿只在客户端预览,不伪造已发布状态。
|
||||
- 新模板新增 renderer 后自动进入 preview build;未实现 Taro renderer 的模板必须明确显示不支持,不能显示空白预览。
|
||||
|
||||
## Migration Plan
|
||||
|
||||
### 组件预览阶段补充
|
||||
|
||||
Admin 有 workspace 时直接复用 Taro renderer,iframe 保留为 H5 回退。组件预览必须补齐原运行环境的尺寸、元素选择器及资源映射:750 设计宽度通过容器单位转换,image/text/view 选择器映射到对应 DOM,模板静态资源经 Vite 打包。不得通过猜测 transform 系数修复单位不一致。此方案避免额外预览服务,但仍需验证所有模板的适配能力;当前 renderer 注册尚为显式列表,自动发现纳入后续任务。详见 `docs/visual-editor-next-steps.md`。
|
||||
|
||||
先实现单一多模板 H5 静态构建和 Admin 同源部署;补齐现有模板所有页面字段 target;验证即时草稿、保存失败和业务记录编辑入口;再将 preview build 纳入正式部署流水线。
|
||||
+13
-2
@@ -21,10 +21,21 @@ location /api/ {
|
||||
}
|
||||
```
|
||||
|
||||
构建管理后台时使用:
|
||||
生产构建会先把所有已接入模板的 H5 renderer 编译进一个静态预览应用,再将其放到 Admin 的 `/template-preview/` 下。线上无需启动 Vite,也无需为每个模板运行单独服务。构建管理后台与预览应用时使用:
|
||||
|
||||
```bash
|
||||
VITE_APP_BASE_PATH=/admin/ VITE_API_BASE_URL=/api pnpm --filter @personal-brand/admin build
|
||||
pnpm build:admin:preview
|
||||
```
|
||||
|
||||
部署时将 `apps/admin/dist` 作为同一个静态站点发布。预览 iframe 与 Admin 同源,运行时根据品牌公开工作区中的 `visualTemplateKey` 选择已打包的模板 renderer,并通过 `/api` 读取已发布数据;管理员正在编辑的草稿由 Admin 经 `postMessage` 投影到 iframe,不会写回公开 API。
|
||||
|
||||
本地开发只需启动一个多模板 H5 服务和 Admin:
|
||||
|
||||
```bash
|
||||
pnpm preview:templates
|
||||
VITE_APP_BASE_PATH=/ ADMIN_PORT=3000 pnpm --filter @personal-brand/admin dev
|
||||
```
|
||||
|
||||
本地 Admin 默认连接 `http://localhost:3002` 上的统一预览服务。`VITE_TEMPLATE_PREVIEW_URL` 只用于部署时覆盖预览应用地址,不再按模板配置 URL map。
|
||||
|
||||
如果希望 API 服务自身也带前缀,可设置 `API_PREFIX=api`。使用 Nginx 去前缀转发时保持默认空值即可,避免重复 `/api/api`。
|
||||
@@ -0,0 +1,39 @@
|
||||
# 可视化编辑后续任务
|
||||
|
||||
## 当前基线
|
||||
|
||||
Admin 直接复用 Taro renderer,模板原始 CSS 按 750 设计宽度转换为预览容器单位,模板图片经 Vite 打包。已有区域点击、选中样式、品牌字段筛选、即时草稿和显式保存;保留 H5 iframe 作为回退。当前不代表所有页面、记录与字段均已完成编辑闭环。
|
||||
|
||||
## 1. 统一选区契约
|
||||
|
||||
- 统一 selection 为模板、页面、targetKey、实体类型、recordId;重复餐品和信任卡片必须带记录标识。
|
||||
- 从 manifest 解析中文名称、binding、编辑能力,不在 Admin 中新增行业条件分支。
|
||||
- 校验 target 存在、binding 可解析、页面归属正确;切页、删记录和换模板清理无效选区。
|
||||
- 验收:嵌套区块选最近目标,重复卡片准确选中对应记录,未知目标不打开错误表单。
|
||||
|
||||
## 2. 完成点选与高亮交互
|
||||
|
||||
- 区分浏览模式与编辑模式;编辑模式阻止咨询提交、导航等真实操作。
|
||||
- 使用独立覆盖层显示悬停边框、选中边框及中文区域名,避免改变模板背景、尺寸和布局。
|
||||
- 覆盖层随滚动、容器尺寸、图片加载和字段换行更新;支持空白取消、Escape 取消及键盘选择。
|
||||
- 验收:320/390 画布、长页面、滚动及图片加载后边框仍准确,不遮挡按钮和表单。
|
||||
|
||||
## 3. 打通绑定值编辑
|
||||
|
||||
- 右侧固定显示区域名称、数据来源、对应字段、未保存状态;点字段时定位关联区域。
|
||||
- 品牌配置、业务记录、信任内容、咨询表单使用各自现有 API 和验证规则;记录 ID 由选区携带。
|
||||
- 把当前仅跳转管理页的记录区域接入对应编辑器,复用原有表单与 mutation。
|
||||
- 图片、列表、条件字段按模板声明渲染;空值、默认值、继承值明确区分。
|
||||
- 验收:改值即时预览;保存后重新读取仍一致;失败保留输入并可重试;未保存切页给出明确选择。
|
||||
|
||||
## 4. 自动化验收和部署
|
||||
|
||||
- 按模板包自动发现 renderer、页面与资源,去掉现有 renderer 注册的手工二选一;未知模板明确显示不支持。
|
||||
- 对每个模板覆盖首页、列表、详情、信任区及表单:选择→字段→草稿→保存→重载。
|
||||
- 覆盖非空真实结构数据、嵌套/重复目标、授权失败、图片实际解码、样式尺寸和溢出;仅 DOM 存在不能作为视觉通过。
|
||||
- 校验发布前后隔离:草稿不影响公开页面,发布后访客读取新值;受保护接口覆盖无凭证、错误角色及成功路径。
|
||||
- 验收生产静态构建及子路径部署,不按模板新增 Vite 服务。
|
||||
|
||||
## 推进顺序
|
||||
|
||||
先完成选区契约与覆盖层,作为一个可验收提交;再分批接入记录编辑与保存语义;最后补齐跨模板测试和发布验收。每次提交展示具体可操作闭环,保留回退到当前分支基线的能力。
|
||||
@@ -12,6 +12,7 @@ export default tseslint.config(
|
||||
"apps/api/test/**/*.test.js",
|
||||
"apps/api/test/**/*.cjs",
|
||||
"apps/admin/test/**/*.test.mjs",
|
||||
"apps/admin/public/**",
|
||||
"packages/types/test/**/*.test.mjs",
|
||||
"apps/taro/test/**/*.test.mjs",
|
||||
"apps/taro/src/assets/**",
|
||||
@@ -53,4 +54,8 @@ export default tseslint.config(
|
||||
"@typescript-eslint/require-await": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
...tseslint.configs.disableTypeChecked,
|
||||
files: ["apps/admin/template-preview-css.mjs"],
|
||||
},
|
||||
);
|
||||
@@ -26,6 +26,8 @@
|
||||
"clean": "turbo run clean && rimraf node_modules .turbo",
|
||||
"preview:food": "pnpm --filter @personal-brand/taro dev:h5",
|
||||
"preview:linjing": "TEMPLATE_KEY=linjing-editorial PREVIEW_PORT=3003 pnpm --filter @personal-brand/taro dev:h5",
|
||||
"preview:templates": "pnpm --filter @personal-brand/taro dev:preview",
|
||||
"build:admin:preview": "PREVIEW_ALL_TEMPLATES=true API_BASE_URL=/api PREVIEW_PUBLIC_PATH=/template-preview/ pnpm --filter @personal-brand/taro build:preview && node scripts/package-template-preview.cjs && VITE_APP_BASE_PATH=/admin/ VITE_API_BASE_URL=/api pnpm --filter @personal-brand/admin build",
|
||||
"build:taro:food": "pnpm --filter @personal-brand/taro build:h5 && pnpm --filter @personal-brand/taro build:weapp",
|
||||
"build:taro:linjing": "TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:h5 && TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:weapp"
|
||||
},
|
||||
|
||||
@@ -11,10 +11,15 @@ import type {
|
||||
RuntimeTrustItem,
|
||||
ThemeManifest,
|
||||
} from "@personal-brand/types";
|
||||
export { projectBrandAliases } 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";
|
||||
export type { EditorPreviewFrameMessage, EditorPreviewHostMessage } from "@personal-brand/types";
|
||||
export type {
|
||||
EditorPreviewFrameMessage,
|
||||
EditorPreviewHostMessage,
|
||||
RuntimeWorkspace,
|
||||
} from "@personal-brand/types";
|
||||
|
||||
export interface BrandProfile {
|
||||
id: string;
|
||||
@@ -688,6 +693,9 @@ export class ApiClient {
|
||||
}> {
|
||||
return this.request("/admin/workspace");
|
||||
}
|
||||
getAdminPreviewWorkspace(): Promise<import("@personal-brand/types").RuntimeWorkspace> {
|
||||
return this.request("/admin/workspace/preview");
|
||||
}
|
||||
listAdminReleases(): Promise<BrandReleaseSummary[]> {
|
||||
return this.request("/admin/releases");
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,7 +6,8 @@ import { navigate } from "../../../apps/taro/src/runtime/navigation";
|
||||
import { presentation, offering, slot, text, rows } from "../../../apps/taro/src/runtime/content";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/types";
|
||||
import "./style.css";
|
||||
const asset = (name: string) => `/assets/${name}`;
|
||||
const asset = (name: string) =>
|
||||
`/assets/${PREVIEW_ALL_TEMPLATES ? "acheng-campus-food/" : ""}${name}`;
|
||||
function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
const brand = workspace.brand;
|
||||
const p = presentation(workspace, "home");
|
||||
@@ -115,7 +116,7 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
].filter((row) => row.title && row.detail);
|
||||
const steps = rows(process?.config.steps).filter((step) => step.title && step.detail);
|
||||
return (
|
||||
<View className="food-service">
|
||||
<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">
|
||||
@@ -220,7 +221,7 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
const p = presentation(workspace, "profile");
|
||||
const credentials = workspace.trustItems.filter((item) => item.type === "credential");
|
||||
return (
|
||||
<View className="food-profile">
|
||||
<View className="food-profile" data-editor-target="acheng-campus-food.profile.identity">
|
||||
<View className="page">
|
||||
<View className="profile-card">
|
||||
<View className="portrait">
|
||||
@@ -340,13 +341,22 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</View>
|
||||
);
|
||||
}
|
||||
const formTargets: Record<string, string> = {
|
||||
inquiry: "acheng-campus-food.inquiry.booking",
|
||||
success: "acheng-campus-food.success.successCopy",
|
||||
records: "acheng-campus-food.records.recordsCopy",
|
||||
};
|
||||
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
|
||||
if (page === "home") return <Home workspace={workspace} />;
|
||||
if (page === "service") return <Service workspace={workspace} />;
|
||||
if (page === "profile") return <Profile workspace={workspace} />;
|
||||
if (page === "offerings") return <OfferingList workspace={workspace} />;
|
||||
if (page === "detail") return <Detail workspace={workspace} id={offeringId} />;
|
||||
return <View className="food-forms">{children}</View>;
|
||||
return (
|
||||
<View className="food-forms" data-editor-target={formTargets[page]}>
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
const p = presentation(workspace, "offerings");
|
||||
@@ -363,7 +373,7 @@ function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
.includes(query.trim().toLowerCase()),
|
||||
);
|
||||
return (
|
||||
<View className="food-list">
|
||||
<View className="food-list" data-editor-target="acheng-campus-food.offerings.menu">
|
||||
<View className="page">
|
||||
<View className="filters">
|
||||
<Button
|
||||
@@ -437,7 +447,7 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
const item = offering(found);
|
||||
const p = presentation(workspace, "detail");
|
||||
return (
|
||||
<View className="food-detail">
|
||||
<View className="food-detail" data-editor-target="acheng-campus-food.detail.dishDetail">
|
||||
<View className="detail">
|
||||
<View className="hero-wrap">
|
||||
<Image
|
||||
@@ -454,7 +464,7 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
<Text>{item.series}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View className="content">
|
||||
<View className="content" data-editor-target="acheng-campus-food.detail.detailCopy">
|
||||
<View className="price-card">
|
||||
<View>
|
||||
<Text>{p.priceLabel || "参考价格"}</Text>
|
||||
|
||||
@@ -144,7 +144,8 @@
|
||||
"label": "主理人姓名",
|
||||
"input": "text",
|
||||
"required": true,
|
||||
"placeholder": "例如:阿成"
|
||||
"placeholder": "例如:阿成",
|
||||
"previewTarget": "acheng-campus-food.profile.identity"
|
||||
},
|
||||
{
|
||||
"key": "title",
|
||||
@@ -152,33 +153,44 @@
|
||||
"label": "你的身份",
|
||||
"help": "例如:校园餐饮主理人。",
|
||||
"input": "text",
|
||||
"required": true
|
||||
"required": true,
|
||||
"previewTarget": "acheng-campus-food.profile.identity"
|
||||
},
|
||||
{
|
||||
"key": "badge",
|
||||
"binding": "brand.config.visualPresentation.profile.badge",
|
||||
"label": "写真角标",
|
||||
"input": "text",
|
||||
"help": "显示在主理人写真上,可填写经验或服务定位。"
|
||||
"help": "显示在主理人写真上,可填写经验或服务定位。",
|
||||
"previewTarget": "acheng-campus-food.profile.identity"
|
||||
},
|
||||
{
|
||||
"key": "storyLead",
|
||||
"binding": "brand.config.visualPresentation.profile.storyLead",
|
||||
"label": "故事引言",
|
||||
"input": "textarea",
|
||||
"help": "故事开头的强调段落,下面的正文使用品牌简介。"
|
||||
"help": "故事开头的强调段落,下面的正文使用品牌简介。",
|
||||
"previewTarget": "acheng-campus-food.profile.identity"
|
||||
},
|
||||
{
|
||||
"key": "recordsTitle",
|
||||
"binding": "brand.config.visualPresentation.profile.recordsTitle",
|
||||
"label": "记录入口文案",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.profile.identity"
|
||||
},
|
||||
{
|
||||
"key": "recordsCountUnit",
|
||||
"binding": "brand.config.visualPresentation.profile.recordsCountUnit",
|
||||
"label": "记录数量单位",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.profile.identity"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.profile.identity",
|
||||
"label": "摊位与主理人"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -189,10 +201,22 @@
|
||||
"page": "home",
|
||||
"target": "brand",
|
||||
"previewTargets": [
|
||||
{ "key": "food.home.location", "label": "服务地点" },
|
||||
{ "key": "food.home.hero", "label": "出摊现场图片" },
|
||||
{ "key": "food.home.offerings-heading", "label": "餐品区域标题" },
|
||||
{ "key": "food.home.promise-heading", "label": "出餐承诺标题" }
|
||||
{
|
||||
"key": "food.home.location",
|
||||
"label": "服务地点"
|
||||
},
|
||||
{
|
||||
"key": "food.home.hero",
|
||||
"label": "出摊现场图片"
|
||||
},
|
||||
{
|
||||
"key": "food.home.offerings-heading",
|
||||
"label": "餐品区域标题"
|
||||
},
|
||||
{
|
||||
"key": "food.home.promise-heading",
|
||||
"label": "出餐承诺标题"
|
||||
}
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -255,7 +279,14 @@
|
||||
"binding": "brand.config.visualPresentation.service.processAction",
|
||||
"label": "流程咨询按钮",
|
||||
"input": "text",
|
||||
"placeholder": "例如:立即预订"
|
||||
"placeholder": "例如:立即预订",
|
||||
"previewTarget": "acheng-campus-food.service.service"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.service.service",
|
||||
"label": "出摊服务页说明"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -270,21 +301,30 @@
|
||||
"key": "title",
|
||||
"binding": "brand.config.visualPresentation.offerings.title",
|
||||
"label": "菜单页标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.offerings.menu"
|
||||
},
|
||||
{
|
||||
"key": "subtitle",
|
||||
"binding": "brand.config.visualPresentation.offerings.subtitle",
|
||||
"label": "菜单页说明",
|
||||
"input": "textarea",
|
||||
"maxLength": 120
|
||||
"maxLength": 120,
|
||||
"previewTarget": "acheng-campus-food.offerings.menu"
|
||||
},
|
||||
{
|
||||
"key": "menuTip",
|
||||
"binding": "brand.config.visualPresentation.offerings.menuTip",
|
||||
"label": "菜单提示",
|
||||
"help": "只填写当前实际提供的取餐、加菜或定制服务。",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.offerings.menu"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.offerings.menu",
|
||||
"label": "菜单页说明"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -299,28 +339,38 @@
|
||||
"key": "title",
|
||||
"binding": "brand.config.visualPresentation.inquiry.title",
|
||||
"label": "预订页面标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.inquiry.booking"
|
||||
},
|
||||
{
|
||||
"key": "subtitle",
|
||||
"binding": "brand.config.visualPresentation.inquiry.subtitle",
|
||||
"label": "预订说明",
|
||||
"input": "textarea",
|
||||
"maxLength": 120
|
||||
"maxLength": 120,
|
||||
"previewTarget": "acheng-campus-food.inquiry.booking"
|
||||
},
|
||||
{
|
||||
"key": "submitLabel",
|
||||
"binding": "brand.config.visualPresentation.inquiry.submitLabel",
|
||||
"label": "提交按钮文字",
|
||||
"input": "text",
|
||||
"placeholder": "例如:提交预订需求"
|
||||
"placeholder": "例如:提交预订需求",
|
||||
"previewTarget": "acheng-campus-food.inquiry.booking"
|
||||
},
|
||||
{
|
||||
"key": "promise",
|
||||
"binding": "brand.config.visualPresentation.inquiry.promise",
|
||||
"label": "真实服务承诺",
|
||||
"help": "仅填写能兑现的回复时间、订金和联系规则;留空则不显示。",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.inquiry.booking"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.inquiry.booking",
|
||||
"label": "预订与定制"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -335,43 +385,50 @@
|
||||
"key": "categoryLabel",
|
||||
"binding": "offering.config.categoryLabel",
|
||||
"label": "餐品类别",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "detailHero",
|
||||
"binding": "offering.config.detailHero",
|
||||
"label": "详情主图",
|
||||
"input": "image"
|
||||
"input": "image",
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "area",
|
||||
"binding": "offering.config.area",
|
||||
"label": "供应地点",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "series",
|
||||
"binding": "offering.config.series",
|
||||
"label": "套餐或系列说明",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "spaceType",
|
||||
"binding": "offering.config.spaceType",
|
||||
"label": "适合场景",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "background",
|
||||
"binding": "offering.config.details.background",
|
||||
"label": "餐品介绍",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "designConcept",
|
||||
"binding": "offering.config.details.designConcept",
|
||||
"label": "口味与分量",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "keywords",
|
||||
@@ -384,7 +441,8 @@
|
||||
"key": "value",
|
||||
"label": "特色"
|
||||
}
|
||||
]
|
||||
],
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "crafts",
|
||||
@@ -397,7 +455,8 @@
|
||||
"key": "value",
|
||||
"label": "制作说明"
|
||||
}
|
||||
]
|
||||
],
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
},
|
||||
{
|
||||
"key": "materialsList",
|
||||
@@ -413,7 +472,14 @@
|
||||
"key": "spec",
|
||||
"label": "说明"
|
||||
}
|
||||
]
|
||||
],
|
||||
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.detail.dishDetail",
|
||||
"label": "餐品与服务详情"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -428,50 +494,64 @@
|
||||
"key": "priceLabel",
|
||||
"binding": "brand.config.visualPresentation.detail.priceLabel",
|
||||
"label": "价格说明标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "spaceLabel",
|
||||
"binding": "brand.config.visualPresentation.detail.spaceLabel",
|
||||
"label": "适合场景标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "backgroundTitle",
|
||||
"binding": "brand.config.visualPresentation.detail.backgroundTitle",
|
||||
"label": "餐品介绍标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "conceptTitle",
|
||||
"binding": "brand.config.visualPresentation.detail.conceptTitle",
|
||||
"label": "口味与分量标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "craftsTitle",
|
||||
"binding": "brand.config.visualPresentation.detail.craftsTitle",
|
||||
"label": "制作方式标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "materialsTitle",
|
||||
"binding": "brand.config.visualPresentation.detail.materialsTitle",
|
||||
"label": "食材与搭配标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "inquiryAction",
|
||||
"binding": "brand.config.visualPresentation.detail.inquiryAction",
|
||||
"label": "咨询按钮文字",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "inquiryHint",
|
||||
"binding": "brand.config.visualPresentation.detail.inquiryHint",
|
||||
"label": "咨询后的处理说明",
|
||||
"help": "只写能够兑现的联系和确认方式。",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.detail.detailCopy",
|
||||
"label": "详情页说明"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -486,32 +566,43 @@
|
||||
"key": "eyebrow",
|
||||
"binding": "brand.config.visualPresentation.success.eyebrow",
|
||||
"label": "页面小标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||
},
|
||||
{
|
||||
"key": "title",
|
||||
"binding": "brand.config.visualPresentation.success.title",
|
||||
"label": "确认标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||
},
|
||||
{
|
||||
"key": "intro",
|
||||
"binding": "brand.config.visualPresentation.success.intro",
|
||||
"label": "后续联系说明",
|
||||
"help": "若写回复时间,请确认日常能兑现。",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||
},
|
||||
{
|
||||
"key": "recordsAction",
|
||||
"binding": "brand.config.visualPresentation.success.recordsAction",
|
||||
"label": "查看记录按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||
},
|
||||
{
|
||||
"key": "homeAction",
|
||||
"binding": "brand.config.visualPresentation.success.homeAction",
|
||||
"label": "返回首页按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.success.successCopy",
|
||||
"label": "提交成功页"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -526,31 +617,42 @@
|
||||
"key": "title",
|
||||
"binding": "brand.config.visualPresentation.records.title",
|
||||
"label": "记录页标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||
},
|
||||
{
|
||||
"key": "createAction",
|
||||
"binding": "brand.config.visualPresentation.records.createAction",
|
||||
"label": "新增咨询按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||
},
|
||||
{
|
||||
"key": "emptyTitle",
|
||||
"binding": "brand.config.visualPresentation.records.emptyTitle",
|
||||
"label": "暂无记录标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||
},
|
||||
{
|
||||
"key": "emptyDescription",
|
||||
"binding": "brand.config.visualPresentation.records.emptyDescription",
|
||||
"label": "暂无记录说明",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||
},
|
||||
{
|
||||
"key": "emptyAction",
|
||||
"binding": "brand.config.visualPresentation.records.emptyAction",
|
||||
"label": "空状态按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "acheng-campus-food.records.recordsCopy",
|
||||
"label": "咨询记录页"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -27,15 +27,25 @@ for (const directory of templateDirectories) {
|
||||
const keys = targets.map((target) => target.key);
|
||||
assert.equal(new Set(keys).size, keys.length, "preview target keys must be unique");
|
||||
|
||||
for (const { section } of targets) {
|
||||
for (const section of sections) {
|
||||
for (const field of section.fields) {
|
||||
if (field.previewTarget)
|
||||
assert.ok(
|
||||
section.previewTargets.some((target) => target.key === field.previewTarget),
|
||||
`${section.key}.${field.key} references an undeclared previewTarget`,
|
||||
);
|
||||
assert.ok(field.binding, `${section.key}.${field.key} must have an editable binding`);
|
||||
assert.ok(field.previewTarget, `${section.key}.${field.key} must map to a visual region`);
|
||||
assert.ok(
|
||||
section.previewTargets?.some((target) => target.key === field.previewTarget),
|
||||
`${section.key}.${field.key} references an undeclared previewTarget`,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const field of manifest.templateFields ?? []) {
|
||||
assert.ok(field.binding, `templateFields.${field.key} must have an editable binding`);
|
||||
assert.ok(field.previewTarget, `templateFields.${field.key} must map to a visual region`);
|
||||
assert.ok(
|
||||
targets.some((target) => target.key === field.previewTarget),
|
||||
`templateFields.${field.key} references an undeclared previewTarget`,
|
||||
);
|
||||
assert.ok(rendererPath && fs.existsSync(rendererPath));
|
||||
}
|
||||
|
||||
for (const target of targets)
|
||||
assert.ok(
|
||||
@@ -48,8 +58,9 @@ for (const directory of templateDirectories) {
|
||||
const renderer = fs.readFileSync(rendererPath, "utf8");
|
||||
for (const target of targets)
|
||||
assert.ok(
|
||||
renderer.includes(`data-editor-target="${target.key}"`),
|
||||
renderer.includes(target.key),
|
||||
`renderer is missing data-editor-target ${target.key}`,
|
||||
);
|
||||
assert.ok(renderer.includes("data-editor-target"), "renderer must expose editor targets");
|
||||
});
|
||||
}
|
||||
@@ -19,7 +19,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
const credential = slot(workspace, "credential");
|
||||
const t = workspace.trustPresentation;
|
||||
return (
|
||||
<View className="editorial-home">
|
||||
<View className="editorial-home" data-editor-target="linjing-editorial.home.home">
|
||||
<View className="page">
|
||||
<View className="founder-card" data-editor-target="editorial.home.identity">
|
||||
{text(b.avatarUrl) && (
|
||||
@@ -125,9 +125,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
const p = presentation(workspace, "profile");
|
||||
const config = object(b.profilePresentation);
|
||||
return (
|
||||
<View className="editorial-profile">
|
||||
<View
|
||||
className="editorial-profile"
|
||||
data-editor-target="linjing-editorial.profile.profileDetails"
|
||||
>
|
||||
<View className="profile">
|
||||
<View className="founder-card">
|
||||
<View className="founder-card" data-editor-target="linjing-editorial.profile.identity">
|
||||
<View className="identity">
|
||||
{text(b.avatarUrl) && (
|
||||
<Image className="avatar" src={text(b.avatarUrl)} mode="aspectFill" />
|
||||
@@ -215,7 +218,7 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
function List({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
const p = presentation(workspace, "offerings");
|
||||
return (
|
||||
<View className="editorial-list">
|
||||
<View className="editorial-list" data-editor-target="linjing-editorial.offerings.cases">
|
||||
<View className="page">
|
||||
<Text className="eyebrow">{p.eyebrow}</Text>
|
||||
<Text className="section-title">{p.title || "作品与服务"}</Text>
|
||||
@@ -255,7 +258,7 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
const item = offering(found);
|
||||
const p = presentation(workspace, "detail");
|
||||
return (
|
||||
<View className="editorial-detail">
|
||||
<View className="editorial-detail" data-editor-target="linjing-editorial.detail.projectDetail">
|
||||
<View className="detail">
|
||||
<View className="hero-wrap">
|
||||
<Image
|
||||
@@ -272,7 +275,7 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
<Text>{item.series}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View className="content">
|
||||
<View className="content" data-editor-target="linjing-editorial.detail.detailCopy">
|
||||
<View className="price-card">
|
||||
<View>
|
||||
<Text>{p.priceLabel}</Text>
|
||||
@@ -333,10 +336,19 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
</View>
|
||||
);
|
||||
}
|
||||
const formTargets: Record<string, string> = {
|
||||
inquiry: "linjing-editorial.inquiry.consultation",
|
||||
success: "linjing-editorial.success.successCopy",
|
||||
records: "linjing-editorial.records.recordsCopy",
|
||||
};
|
||||
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
|
||||
if (page === "home") return <Home workspace={workspace} />;
|
||||
if (page === "offerings") return <List workspace={workspace} />;
|
||||
if (page === "profile" || page === "service") return <Profile workspace={workspace} />;
|
||||
if (page === "detail") return <Detail workspace={workspace} id={offeringId} />;
|
||||
return <View className="editorial-forms">{children}</View>;
|
||||
return (
|
||||
<View className="editorial-forms" data-editor-target={formTargets[page]}>
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -86,6 +86,8 @@
|
||||
{
|
||||
"key": "designPhilosophy",
|
||||
"page": "home",
|
||||
"binding": "brand.config.templateData.designPhilosophy",
|
||||
"previewTarget": "linjing-editorial.home.home",
|
||||
"label": "设计理念",
|
||||
"help": "用一两句话说明你的设计方法。",
|
||||
"input": "textarea",
|
||||
@@ -139,7 +141,8 @@
|
||||
"binding": "brand.config.founder",
|
||||
"label": "主理人姓名",
|
||||
"input": "text",
|
||||
"required": true
|
||||
"required": true,
|
||||
"previewTarget": "linjing-editorial.profile.identity"
|
||||
},
|
||||
{
|
||||
"key": "title",
|
||||
@@ -147,7 +150,14 @@
|
||||
"label": "身份或职位",
|
||||
"input": "text",
|
||||
"required": true,
|
||||
"placeholder": "例如:别墅门系统主理人"
|
||||
"placeholder": "例如:别墅门系统主理人",
|
||||
"previewTarget": "linjing-editorial.profile.identity"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.profile.identity",
|
||||
"label": "主理人与联系方式"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -158,11 +168,30 @@
|
||||
"page": "home",
|
||||
"target": "brand",
|
||||
"previewTargets": [
|
||||
{ "key": "editorial.home.identity", "label": "主理人标签" },
|
||||
{ "key": "editorial.home.hero", "label": "首页主视觉" },
|
||||
{ "key": "editorial.home.proof", "label": "信任介绍" },
|
||||
{ "key": "editorial.home.manifesto", "label": "品牌主张" },
|
||||
{ "key": "editorial.home.works", "label": "代表案例标题" }
|
||||
{
|
||||
"key": "editorial.home.identity",
|
||||
"label": "主理人标签"
|
||||
},
|
||||
{
|
||||
"key": "editorial.home.hero",
|
||||
"label": "首页主视觉"
|
||||
},
|
||||
{
|
||||
"key": "editorial.home.proof",
|
||||
"label": "信任介绍"
|
||||
},
|
||||
{
|
||||
"key": "editorial.home.manifesto",
|
||||
"label": "品牌主张"
|
||||
},
|
||||
{
|
||||
"key": "editorial.home.works",
|
||||
"label": "代表案例标题"
|
||||
},
|
||||
{
|
||||
"key": "linjing-editorial.home.home",
|
||||
"label": "首页品牌表达"
|
||||
}
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -228,43 +257,50 @@
|
||||
"key": "worksAction",
|
||||
"binding": "brand.config.visualPresentation.home.worksAction",
|
||||
"label": "查看案例入口",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.home"
|
||||
},
|
||||
{
|
||||
"key": "flowEyebrow",
|
||||
"binding": "brand.config.visualPresentation.home.flowEyebrow",
|
||||
"label": "合作流程小标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.home"
|
||||
},
|
||||
{
|
||||
"key": "flowTitle",
|
||||
"binding": "brand.config.visualPresentation.home.flowTitle",
|
||||
"label": "项目流程标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.home"
|
||||
},
|
||||
{
|
||||
"key": "heroTitle",
|
||||
"binding": "brand.config.homeHero.title",
|
||||
"label": "首页主标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.home"
|
||||
},
|
||||
{
|
||||
"key": "heroEyebrow",
|
||||
"binding": "brand.config.homeHero.eyebrow",
|
||||
"label": "主图项目标注",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.home"
|
||||
},
|
||||
{
|
||||
"key": "heroDescription",
|
||||
"binding": "brand.config.homeHero.slogan",
|
||||
"label": "首页主图说明",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.home.home"
|
||||
},
|
||||
{
|
||||
"key": "heroAction",
|
||||
"binding": "brand.config.homeHero.cta",
|
||||
"label": "主图行动文字",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.home.home"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -281,9 +317,17 @@
|
||||
"label": "服务区域",
|
||||
"input": "list",
|
||||
"itemFields": [
|
||||
{ "key": "title", "label": "区域名称" },
|
||||
{ "key": "content", "label": "服务说明", "input": "textarea" }
|
||||
]
|
||||
{
|
||||
"key": "title",
|
||||
"label": "区域名称"
|
||||
},
|
||||
{
|
||||
"key": "content",
|
||||
"label": "服务说明",
|
||||
"input": "textarea"
|
||||
}
|
||||
],
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "warranty",
|
||||
@@ -291,67 +335,90 @@
|
||||
"label": "履约与维护说明",
|
||||
"input": "list",
|
||||
"itemValueKey": "value",
|
||||
"itemFields": [{ "key": "value", "label": "承诺内容", "input": "textarea" }]
|
||||
"itemFields": [
|
||||
{
|
||||
"key": "value",
|
||||
"label": "承诺内容",
|
||||
"input": "textarea"
|
||||
}
|
||||
],
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "recordsTitle",
|
||||
"binding": "brand.config.visualPresentation.profile.recordsTitle",
|
||||
"label": "咨询记录入口标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "recordsSubtitle",
|
||||
"binding": "brand.config.visualPresentation.profile.recordsSubtitle",
|
||||
"label": "咨询记录入口说明",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "coverageTitle",
|
||||
"binding": "brand.config.visualPresentation.profile.coverageTitle",
|
||||
"label": "服务区域标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "warrantyTitle",
|
||||
"binding": "brand.config.visualPresentation.profile.warrantyTitle",
|
||||
"label": "履约说明标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "phoneLabel",
|
||||
"binding": "brand.config.visualPresentation.profile.phoneLabel",
|
||||
"label": "电话标签",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "wechatLabel",
|
||||
"binding": "brand.config.visualPresentation.profile.wechatLabel",
|
||||
"label": "微信标签",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "addressLabel",
|
||||
"binding": "brand.config.visualPresentation.profile.addressLabel",
|
||||
"label": "地址标签",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "callAction",
|
||||
"binding": "brand.config.visualPresentation.profile.callAction",
|
||||
"label": "拨打电话按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "copyAction",
|
||||
"binding": "brand.config.visualPresentation.profile.copyAction",
|
||||
"label": "复制微信按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
},
|
||||
{
|
||||
"key": "recordsCountUnit",
|
||||
"binding": "brand.config.visualPresentation.profile.recordsCountUnit",
|
||||
"label": "记录数量单位",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.profile.profileDetails"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.profile.profileDetails",
|
||||
"label": "服务区域与履约说明"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -366,32 +433,43 @@
|
||||
"key": "worksEyebrow",
|
||||
"binding": "brand.config.visualPresentation.offerings.worksEyebrow",
|
||||
"label": "案例页辅助标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.offerings.cases"
|
||||
},
|
||||
{
|
||||
"key": "worksTitle",
|
||||
"binding": "brand.config.visualPresentation.offerings.worksTitle",
|
||||
"label": "案例页主标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.offerings.cases"
|
||||
},
|
||||
{
|
||||
"key": "subtitle",
|
||||
"binding": "brand.config.visualPresentation.offerings.subtitle",
|
||||
"label": "案例页说明",
|
||||
"input": "textarea",
|
||||
"maxLength": 140
|
||||
"maxLength": 140,
|
||||
"previewTarget": "linjing-editorial.offerings.cases"
|
||||
},
|
||||
{
|
||||
"key": "closingText",
|
||||
"binding": "brand.config.visualPresentation.offerings.closingText",
|
||||
"label": "案例页结语",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.offerings.cases"
|
||||
},
|
||||
{
|
||||
"key": "closingAction",
|
||||
"binding": "brand.config.visualPresentation.offerings.closingAction",
|
||||
"label": "案例页咨询入口",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.offerings.cases"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.offerings.cases",
|
||||
"label": "案例与体系"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -406,32 +484,43 @@
|
||||
"key": "title",
|
||||
"binding": "brand.config.visualPresentation.inquiry.title",
|
||||
"label": "咨询页面标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.inquiry.consultation"
|
||||
},
|
||||
{
|
||||
"key": "subtitle",
|
||||
"binding": "brand.config.visualPresentation.inquiry.subtitle",
|
||||
"label": "咨询说明",
|
||||
"input": "textarea",
|
||||
"maxLength": 140
|
||||
"maxLength": 140,
|
||||
"previewTarget": "linjing-editorial.inquiry.consultation"
|
||||
},
|
||||
{
|
||||
"key": "submitLabel",
|
||||
"binding": "brand.config.visualPresentation.inquiry.submitLabel",
|
||||
"label": "提交按钮文字",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.inquiry.consultation"
|
||||
},
|
||||
{
|
||||
"key": "eyebrow",
|
||||
"binding": "brand.config.visualPresentation.inquiry.eyebrow",
|
||||
"label": "咨询页小标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.inquiry.consultation"
|
||||
},
|
||||
{
|
||||
"key": "note",
|
||||
"binding": "brand.config.visualPresentation.inquiry.note",
|
||||
"label": "咨询前提示",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.inquiry.consultation"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.inquiry.consultation",
|
||||
"label": "咨询说明"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -446,43 +535,50 @@
|
||||
"key": "categoryLabel",
|
||||
"binding": "offering.config.categoryLabel",
|
||||
"label": "案例类别",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "detailHero",
|
||||
"binding": "offering.config.detailHero",
|
||||
"label": "详情主图",
|
||||
"input": "image"
|
||||
"input": "image",
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "area",
|
||||
"binding": "offering.config.area",
|
||||
"label": "项目地点",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "series",
|
||||
"binding": "offering.config.series",
|
||||
"label": "产品系列",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "spaceType",
|
||||
"binding": "offering.config.spaceType",
|
||||
"label": "适用空间",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "background",
|
||||
"binding": "offering.config.details.background",
|
||||
"label": "项目背景",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "designConcept",
|
||||
"binding": "offering.config.details.designConcept",
|
||||
"label": "设计理念",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "keywords",
|
||||
@@ -490,7 +586,13 @@
|
||||
"label": "项目关键词",
|
||||
"input": "list",
|
||||
"itemValueKey": "value",
|
||||
"itemFields": [{ "key": "value", "label": "关键词" }]
|
||||
"itemFields": [
|
||||
{
|
||||
"key": "value",
|
||||
"label": "关键词"
|
||||
}
|
||||
],
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "crafts",
|
||||
@@ -498,7 +600,13 @@
|
||||
"label": "工艺要点",
|
||||
"input": "list",
|
||||
"itemValueKey": "value",
|
||||
"itemFields": [{ "key": "value", "label": "工艺说明" }]
|
||||
"itemFields": [
|
||||
{
|
||||
"key": "value",
|
||||
"label": "工艺说明"
|
||||
}
|
||||
],
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
},
|
||||
{
|
||||
"key": "materialsList",
|
||||
@@ -506,9 +614,22 @@
|
||||
"label": "材料说明",
|
||||
"input": "list",
|
||||
"itemFields": [
|
||||
{ "key": "name", "label": "材料名称" },
|
||||
{ "key": "spec", "label": "规格说明" }
|
||||
]
|
||||
{
|
||||
"key": "name",
|
||||
"label": "材料名称"
|
||||
},
|
||||
{
|
||||
"key": "spec",
|
||||
"label": "规格说明"
|
||||
}
|
||||
],
|
||||
"previewTarget": "linjing-editorial.detail.projectDetail"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.detail.projectDetail",
|
||||
"label": "案例详情"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -523,50 +644,64 @@
|
||||
"key": "priceLabel",
|
||||
"binding": "brand.config.visualPresentation.detail.priceLabel",
|
||||
"label": "价格说明标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "spaceLabel",
|
||||
"binding": "brand.config.visualPresentation.detail.spaceLabel",
|
||||
"label": "适用空间标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "backgroundTitle",
|
||||
"binding": "brand.config.visualPresentation.detail.backgroundTitle",
|
||||
"label": "项目背景标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "conceptTitle",
|
||||
"binding": "brand.config.visualPresentation.detail.conceptTitle",
|
||||
"label": "设计理念标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "craftsTitle",
|
||||
"binding": "brand.config.visualPresentation.detail.craftsTitle",
|
||||
"label": "工艺要点标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "materialsTitle",
|
||||
"binding": "brand.config.visualPresentation.detail.materialsTitle",
|
||||
"label": "材料说明标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "inquiryAction",
|
||||
"binding": "brand.config.visualPresentation.detail.inquiryAction",
|
||||
"label": "咨询按钮文字",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.detail.detailCopy"
|
||||
},
|
||||
{
|
||||
"key": "inquiryHint",
|
||||
"binding": "brand.config.visualPresentation.detail.inquiryHint",
|
||||
"label": "咨询后的处理说明",
|
||||
"help": "只填写能兑现的服务安排。",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.detail.detailCopy"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.detail.detailCopy",
|
||||
"label": "详情页说明"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -581,32 +716,43 @@
|
||||
"key": "eyebrow",
|
||||
"binding": "brand.config.visualPresentation.success.eyebrow",
|
||||
"label": "页面小标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.success.successCopy"
|
||||
},
|
||||
{
|
||||
"key": "title",
|
||||
"binding": "brand.config.visualPresentation.success.title",
|
||||
"label": "确认标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.success.successCopy"
|
||||
},
|
||||
{
|
||||
"key": "intro",
|
||||
"binding": "brand.config.visualPresentation.success.intro",
|
||||
"label": "后续联系说明",
|
||||
"help": "回复时间必须与实际承诺一致。",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.success.successCopy"
|
||||
},
|
||||
{
|
||||
"key": "recordsAction",
|
||||
"binding": "brand.config.visualPresentation.success.recordsAction",
|
||||
"label": "查看记录按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.success.successCopy"
|
||||
},
|
||||
{
|
||||
"key": "homeAction",
|
||||
"binding": "brand.config.visualPresentation.success.homeAction",
|
||||
"label": "返回首页按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.success.successCopy"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.success.successCopy",
|
||||
"label": "提交成功页"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -621,31 +767,42 @@
|
||||
"key": "title",
|
||||
"binding": "brand.config.visualPresentation.records.title",
|
||||
"label": "记录页标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.records.recordsCopy"
|
||||
},
|
||||
{
|
||||
"key": "createAction",
|
||||
"binding": "brand.config.visualPresentation.records.createAction",
|
||||
"label": "新增咨询按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.records.recordsCopy"
|
||||
},
|
||||
{
|
||||
"key": "emptyTitle",
|
||||
"binding": "brand.config.visualPresentation.records.emptyTitle",
|
||||
"label": "暂无记录标题",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.records.recordsCopy"
|
||||
},
|
||||
{
|
||||
"key": "emptyDescription",
|
||||
"binding": "brand.config.visualPresentation.records.emptyDescription",
|
||||
"label": "暂无记录说明",
|
||||
"input": "textarea"
|
||||
"input": "textarea",
|
||||
"previewTarget": "linjing-editorial.records.recordsCopy"
|
||||
},
|
||||
{
|
||||
"key": "emptyAction",
|
||||
"binding": "brand.config.visualPresentation.records.emptyAction",
|
||||
"label": "空状态按钮",
|
||||
"input": "text"
|
||||
"input": "text",
|
||||
"previewTarget": "linjing-editorial.records.recordsCopy"
|
||||
}
|
||||
],
|
||||
"previewTargets": [
|
||||
{
|
||||
"key": "linjing-editorial.records.recordsCopy",
|
||||
"label": "咨询记录页"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -655,21 +812,33 @@
|
||||
{
|
||||
"type": "schedule",
|
||||
"label": "服务与合作安排",
|
||||
"adminFields": { "title": "安排标题", "summary": "安排摘要", "content": "时间与排期详情" },
|
||||
"adminFields": {
|
||||
"title": "安排标题",
|
||||
"summary": "安排摘要",
|
||||
"content": "时间与排期详情"
|
||||
},
|
||||
"pages": ["profile"],
|
||||
"help": "说明可预约时间、服务周期或项目排期。"
|
||||
},
|
||||
{
|
||||
"type": "coverage",
|
||||
"label": "服务范围与适用对象",
|
||||
"adminFields": { "title": "范围标题", "summary": "范围摘要", "content": "服务范围说明" },
|
||||
"adminFields": {
|
||||
"title": "范围标题",
|
||||
"summary": "范围摘要",
|
||||
"content": "服务范围说明"
|
||||
},
|
||||
"pages": ["profile"],
|
||||
"help": "说明服务地区、项目类型或合作边界。"
|
||||
},
|
||||
{
|
||||
"type": "process",
|
||||
"label": "合作流程",
|
||||
"adminFields": { "title": "流程标题", "summary": "流程摘要", "content": "流程步骤" },
|
||||
"adminFields": {
|
||||
"title": "流程标题",
|
||||
"summary": "流程摘要",
|
||||
"content": "流程步骤"
|
||||
},
|
||||
"pages": ["profile"],
|
||||
"help": "每行写一步,从初次沟通到交付完成。",
|
||||
"placeholder": "例如:需求沟通\n方案确认\n落地交付",
|
||||
@@ -678,7 +847,11 @@
|
||||
{
|
||||
"type": "credential",
|
||||
"label": "专业资历与方法",
|
||||
"adminFields": { "title": "证明标题", "summary": "专业摘要", "content": "资历与方法说明" },
|
||||
"adminFields": {
|
||||
"title": "证明标题",
|
||||
"summary": "专业摘要",
|
||||
"content": "资历与方法说明"
|
||||
},
|
||||
"pages": ["home", "profile"],
|
||||
"help": "填写经验、资质、专业标准或工作方法。",
|
||||
"configFields": [
|
||||
@@ -688,9 +861,19 @@
|
||||
"label": "信任数据",
|
||||
"input": "list",
|
||||
"itemFields": [
|
||||
{ "key": "value", "label": "数字或成果" },
|
||||
{ "key": "label", "label": "说明" },
|
||||
{ "key": "sub", "label": "补充说明", "required": false }
|
||||
{
|
||||
"key": "value",
|
||||
"label": "数字或成果"
|
||||
},
|
||||
{
|
||||
"key": "label",
|
||||
"label": "说明"
|
||||
},
|
||||
{
|
||||
"key": "sub",
|
||||
"label": "补充说明",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -699,8 +882,14 @@
|
||||
"label": "专业方法",
|
||||
"input": "list",
|
||||
"itemFields": [
|
||||
{ "key": "title", "label": "方法名称" },
|
||||
{ "key": "desc", "label": "方法说明" }
|
||||
{
|
||||
"key": "title",
|
||||
"label": "方法名称"
|
||||
},
|
||||
{
|
||||
"key": "desc",
|
||||
"label": "方法说明"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -709,9 +898,18 @@
|
||||
"label": "合作流程",
|
||||
"input": "list",
|
||||
"itemFields": [
|
||||
{ "key": "step", "label": "步骤编号" },
|
||||
{ "key": "name", "label": "步骤名称" },
|
||||
{ "key": "desc", "label": "步骤说明" }
|
||||
{
|
||||
"key": "step",
|
||||
"label": "步骤编号"
|
||||
},
|
||||
{
|
||||
"key": "name",
|
||||
"label": "步骤名称"
|
||||
},
|
||||
{
|
||||
"key": "desc",
|
||||
"label": "步骤说明"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -731,7 +929,11 @@
|
||||
{
|
||||
"type": "promise",
|
||||
"label": "合作预期与响应承诺",
|
||||
"adminFields": { "title": "承诺标题", "summary": "承诺摘要", "content": "合作与响应说明" },
|
||||
"adminFields": {
|
||||
"title": "承诺标题",
|
||||
"summary": "承诺摘要",
|
||||
"content": "合作与响应说明"
|
||||
},
|
||||
"pages": ["profile"],
|
||||
"help": "说明回复时间、合作边界和后续跟进方式。"
|
||||
}
|
||||
@@ -777,7 +979,11 @@
|
||||
"title": "别墅门系统案例",
|
||||
"content": "示例内容,待品牌主理人完善。"
|
||||
},
|
||||
{ "type": "process", "title": "从测量到交付", "content": "示例内容,待品牌主理人完善。" },
|
||||
{
|
||||
"type": "process",
|
||||
"title": "从测量到交付",
|
||||
"content": "示例内容,待品牌主理人完善。"
|
||||
},
|
||||
{
|
||||
"type": "credential",
|
||||
"title": "材料与工艺标准",
|
||||
@@ -791,11 +997,26 @@
|
||||
"type": "select",
|
||||
"required": true,
|
||||
"options": [
|
||||
{ "label": "入户大门(防暴铸铜 / 实木)", "value": "入户大门(防暴铸铜 / 实木)" },
|
||||
{ "label": "庭院围墙门(耐候格栅 / 对开)", "value": "庭院围墙门(耐候格栅 / 对开)" },
|
||||
{ "label": "全屋室内门系统(通顶隐形)", "value": "全屋室内门系统(通顶隐形)" },
|
||||
{ "label": "背景墙一体门 / 密室门", "value": "背景墙一体门 / 密室门" },
|
||||
{ "label": "整栋别墅门系统全案一体化", "value": "整栋别墅门系统全案一体化" }
|
||||
{
|
||||
"label": "入户大门(防暴铸铜 / 实木)",
|
||||
"value": "入户大门(防暴铸铜 / 实木)"
|
||||
},
|
||||
{
|
||||
"label": "庭院围墙门(耐候格栅 / 对开)",
|
||||
"value": "庭院围墙门(耐候格栅 / 对开)"
|
||||
},
|
||||
{
|
||||
"label": "全屋室内门系统(通顶隐形)",
|
||||
"value": "全屋室内门系统(通顶隐形)"
|
||||
},
|
||||
{
|
||||
"label": "背景墙一体门 / 密室门",
|
||||
"value": "背景墙一体门 / 密室门"
|
||||
},
|
||||
{
|
||||
"label": "整栋别墅门系统全案一体化",
|
||||
"value": "整栋别墅门系统全案一体化"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -810,10 +1031,22 @@
|
||||
"type": "select",
|
||||
"required": true,
|
||||
"options": [
|
||||
{ "label": "土建结构阶段(适合预埋加固)", "value": "土建结构阶段(适合预埋加固)" },
|
||||
{ "label": "水电木工阶段(适合精确测距)", "value": "水电木工阶段(适合精确测距)" },
|
||||
{ "label": "硬装收尾阶段", "value": "硬装收尾阶段" },
|
||||
{ "label": "旧宅门体翻新改造", "value": "旧宅门体翻新改造" }
|
||||
{
|
||||
"label": "土建结构阶段(适合预埋加固)",
|
||||
"value": "土建结构阶段(适合预埋加固)"
|
||||
},
|
||||
{
|
||||
"label": "水电木工阶段(适合精确测距)",
|
||||
"value": "水电木工阶段(适合精确测距)"
|
||||
},
|
||||
{
|
||||
"label": "硬装收尾阶段",
|
||||
"value": "硬装收尾阶段"
|
||||
},
|
||||
{
|
||||
"label": "旧宅门体翻新改造",
|
||||
"value": "旧宅门体翻新改造"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -822,10 +1055,22 @@
|
||||
"type": "select",
|
||||
"required": false,
|
||||
"options": [
|
||||
{ "label": "5 万 - 10 万", "value": "5 万 - 10 万" },
|
||||
{ "label": "10 万 - 20 万", "value": "10 万 - 20 万" },
|
||||
{ "label": "20 万 - 50 万(全宅全案)", "value": "20 万 - 50 万(全宅全案)" },
|
||||
{ "label": "50 万以上(顶级孤品定制)", "value": "50 万以上(顶级孤品定制)" }
|
||||
{
|
||||
"label": "5 万 - 10 万",
|
||||
"value": "5 万 - 10 万"
|
||||
},
|
||||
{
|
||||
"label": "10 万 - 20 万",
|
||||
"value": "10 万 - 20 万"
|
||||
},
|
||||
{
|
||||
"label": "20 万 - 50 万(全宅全案)",
|
||||
"value": "20 万 - 50 万(全宅全案)"
|
||||
},
|
||||
{
|
||||
"label": "50 万以上(顶级孤品定制)",
|
||||
"value": "50 万以上(顶级孤品定制)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -834,14 +1079,22 @@
|
||||
"type": "radio",
|
||||
"required": true,
|
||||
"options": [
|
||||
{ "label": "需要(预约排期现场勘测)", "value": "需要(预约排期现场勘测)" },
|
||||
{
|
||||
"label": "需要(预约排期现场勘测)",
|
||||
"value": "需要(预约排期现场勘测)"
|
||||
},
|
||||
{
|
||||
"label": "暂不需要(先发图纸在线深化评估)",
|
||||
"value": "暂不需要(先发图纸在线深化评估)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{ "key": "contactName", "label": "贵姓称谓", "type": "text", "required": true },
|
||||
{
|
||||
"key": "contactName",
|
||||
"label": "贵姓称谓",
|
||||
"type": "text",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"key": "contactPhone",
|
||||
"label": "联系手机号(微信同号)",
|
||||
@@ -875,13 +1128,36 @@
|
||||
}
|
||||
],
|
||||
"trustContent": [
|
||||
{ "type": "credential", "title": "关于主理人", "content": "示例内容,待品牌主理人完善。" },
|
||||
{ "type": "process", "title": "合作方法", "content": "示例内容,待品牌主理人完善。" }
|
||||
{
|
||||
"type": "credential",
|
||||
"title": "关于主理人",
|
||||
"content": "示例内容,待品牌主理人完善。"
|
||||
},
|
||||
{
|
||||
"type": "process",
|
||||
"title": "合作方法",
|
||||
"content": "示例内容,待品牌主理人完善。"
|
||||
}
|
||||
],
|
||||
"fields": [
|
||||
{ "key": "name", "label": "您的称呼", "type": "text", "required": true },
|
||||
{ "key": "phone", "label": "联系方式", "type": "phone", "required": true },
|
||||
{ "key": "remark", "label": "合作需求", "type": "textarea", "required": true }
|
||||
{
|
||||
"key": "name",
|
||||
"label": "您的称呼",
|
||||
"type": "text",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"key": "phone",
|
||||
"label": "联系方式",
|
||||
"type": "phone",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"key": "remark",
|
||||
"label": "合作需求",
|
||||
"type": "textarea",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"capabilityKey": "inquiry"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import type { RuntimeWorkspace } from "./runtime-workspace.js";
|
||||
|
||||
export type EditorPreviewHostMessage =
|
||||
| {
|
||||
protocol: "personal-brand-editor-preview";
|
||||
version: 1;
|
||||
type: "workspaceDraft";
|
||||
workspace: RuntimeWorkspace;
|
||||
}
|
||||
| {
|
||||
protocol: "personal-brand-editor-preview";
|
||||
version: 1;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const root = path.resolve(__dirname, "..");
|
||||
const source = path.join(root, "apps/taro/dist/template-preview/h5");
|
||||
const destination = path.join(root, "apps/admin/public/template-preview");
|
||||
|
||||
if (!fs.existsSync(path.join(source, "index.html"))) {
|
||||
throw new Error("Unified template preview build is missing; run build:preview first.");
|
||||
}
|
||||
|
||||
fs.rmSync(destination, { recursive: true, force: true });
|
||||
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
||||
fs.cpSync(source, destination, { recursive: true });
|
||||
Reference in new issue
Block a user