fix: 修复模板画布点选与保存切页回归

This commit is contained in:
que01 committed 2026-10-18 13:40:01 +08:00
1 parent e6d843b4a7
commit cd2992c00a
15 files changed
+98 -40

No files matched your search

@@ -168,6 +168,6 @@
display: block;
}
.component-template-preview__overlay-host > * {
.component-template-preview__overlay-host > .component-template-preview__composite-select {
pointer-events: auto;
}
@@ -2,11 +2,7 @@ import { Alert, Button, Grid, Select, Segmented, Space, Typography } from "antd"
import { useQueryClient } from "@tanstack/react-query";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useNavigate } from "react-router-dom";
import type {
AdminTemplateContent,
RuntimeWorkspace,
TemplateAdminSection,
} from "@personal-brand/api-client";
import type { AdminTemplateContent, RuntimeWorkspace } from "@personal-brand/api-client";
import type { BrandProfile } from "@personal-brand/api-client";
import { StatusTag } from "../../components/StatusTag.js";
import { RecordContentEditor } from "../../components/RecordContentEditor.js";
@@ -18,10 +14,7 @@ import {
type PreviewSelection,
type PreviewTarget,
} from "./preview-selection.js";
import {
filterSectionsForPreviewTarget,
type PresentationValues,
} from "../../lib/presentation/presentation-bindings.js";
import { filterSectionsForPreviewTarget } from "../../lib/presentation/presentation-bindings.js";
import "./PresentationEditor.css";
import { useEditorDraft } from "./use-editor-draft.js";
import {
@@ -213,7 +206,14 @@ export function PresentationEditor({
: pageLinks;
const formState = useBrandPresentationForm({ brand, config, sections });
const { form, initialValues } = formState;
const save = useBrandSaveMutation({ ...formState, brand, config, sections, queryClient });
const save = useBrandSaveMutation({
...formState,
brand,
config,
sections,
queryClient,
onSaved: () => setBrandDirty(false),
});
useEffect(() => {
const initialPage =
@@ -7,6 +7,7 @@ import { TemplateAssetContext } from "./taro-web-components.jsx";
const templateRenderers = import.meta.glob("../../../../../packages/template-*/taro/index.tsx", {
eager: true,
});
const resolvedRenderers = new Map();
function pageContent({ workspace, page }) {
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
@@ -22,15 +23,18 @@ export function resolveTemplateRenderer(workspace) {
? config.visualTemplateKey
: undefined;
if (typeof key !== "string") return null;
if (resolvedRenderers.has(key)) return resolvedRenderers.get(key);
const suffix = `/template-${key}/taro/index.tsx`;
const entry = Object.entries(templateRenderers).find(([path]) => path.endsWith(suffix));
const TemplatePage = entry?.[1]?.TemplatePage;
if (!TemplatePage) return null;
return function TemplatePreview(props) {
function TemplatePreview(props) {
return (
<TemplateAssetContext.Provider value={key}>
<TemplatePage {...props}>{pageContent(props)}</TemplatePage>
</TemplateAssetContext.Provider>
);
};
}
resolvedRenderers.set(key, TemplatePreview);
return TemplatePreview;
}
@@ -98,6 +98,7 @@ interface BrandSaveMutationOptions extends BrandPresentationFormState {
config: Record<string, unknown> | null | undefined;
sections: TemplateAdminSection[];
queryClient: QueryClient;
onSaved: () => void;
}
export function useBrandSaveMutation({
@@ -105,6 +106,7 @@ export function useBrandSaveMutation({
config,
sections,
queryClient,
onSaved,
}: BrandSaveMutationOptions) {
return useMutation({
mutationFn: (values: PresentationValues) => {
@@ -125,6 +127,7 @@ export function useBrandSaveMutation({
return createApiClient().updateAdminBrand({ ...changed, config: contentConfig });
},
onSuccess: () => {
onSaved();
message.success("页面内容已保存为草稿,发布后小程序才会更新");
window.dispatchEvent(new Event("template-preview-refresh"));
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
+12
View File
@@ -860,6 +860,9 @@ test("real template declarations persist brand offering and trust bindings throu
};
let checked = 0;
for (const slug of ["default-brand", "linjing-doors"]) {
const originalPublicWorkspace = JSON.parse(
(await request("/public/workspace?brandSlug=" + slug)).body,
);
const original = await prisma.brandProfile.findUniqueOrThrow({ where: { slug } });
const originalOffering = await prisma.offering.findFirstOrThrow({
where: { brandId: original.id, isEnabled: true },
@@ -1030,6 +1033,15 @@ test("real template declarations persist brand offering and trust bindings throu
);
checked += 1;
}
const unpublishedWorkspace = JSON.parse(
(await request("/public/workspace?brandSlug=" + slug)).body,
);
for (const key of ["brand", "templateData", "offerings", "trustItems", "trustPresentation"])
assert.deepEqual(
unpublishedWorkspace[key],
originalPublicWorkspace[key],
slug + " unpublished edits must preserve public " + key,
);
const publish = await request("/admin/releases/publish", {
method: "POST",
headers,
+38 -18
View File
@@ -33,6 +33,7 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
for (let index = 0; index < (await elements.count()); index++) {
const element = elements.nth(index);
if (!(await element.isVisible())) continue;
await element.scrollIntoViewIfNeeded();
const leafIndex = await element.evaluate((node, key) => {
return Array.from(node.querySelectorAll("*")).findIndex((child) => {
const rect = child.getBoundingClientRect();
@@ -40,7 +41,11 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
child.childElementCount === 0 &&
rect.width > 0 &&
rect.height > 0 &&
child.closest("[data-editor-target]")?.getAttribute("data-editor-target") === key
child.closest("[data-editor-target]")?.getAttribute("data-editor-target") === key &&
document
.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2)
?.closest("[data-editor-target]")
?.getAttribute("data-editor-target") === key
);
});
}, target);
@@ -61,6 +66,19 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
};
});
expect(point.target, "实际命中区域:" + target).toBe(target);
const originalNode = await content.elementHandle();
expect(originalNode).not.toBeNull();
await page.mouse.move(point.x, point.y);
await expect
.poll(() =>
preview
.locator(".component-template-preview__outline")
.evaluateAll((outlines) =>
outlines.every((outline) => getComputedStyle(outline).pointerEvents === "none"),
),
)
.toBe(true);
expect(await originalNode!.evaluate((node) => node.isConnected)).toBe(true);
await page.mouse.click(point.x, point.y);
await expect(
preview.locator(".component-template-preview__outline.is-selected"),
@@ -161,6 +179,7 @@ const runtimeWorkspace = {
trustItems: [{ ...adminTrust }],
trustPresentation: {},
capabilities: [],
plugins: [{ key: "inquiry", status: "enabled", config: {} }],
theme: { colors: {} },
};
const templateContent = JSON.parse(
@@ -390,9 +409,10 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
);
await page.keyboard.press("Escape");
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
await page.getByText("套餐餐品", { exact: true }).click();
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
await expect(page.getByRole("dialog", { name: "有尚未保存的修改" })).toHaveCount(0);
await expect(preview.locator(".offering-card")).toHaveCount(1);
await preview.locator('[data-editor-target="acheng-campus-food.offerings.item"]').click();
await preview.locator(".offering-card .dish-name").click();
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
"data-selected-record-id",
adminOffering.id,
@@ -411,7 +431,7 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
await page.getByRole("button", { name: "保存此项内容" }).click();
await expect.poll(() => adminOffering.name).toBe("编辑后的家庭餐");
await page.reload();
await page.getByText("套餐餐品", { exact: true }).click();
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
await page.getByText("出摊服务", { exact: true }).click();
await preview.locator('[data-editor-target="trust:schedule"]').click();
@@ -487,7 +507,7 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
await page.getByText("记录页", { exact: true }).click();
await expect(preview.locator(".records-page")).toBeVisible();
await expect(preview.locator(".records-page")).toContainText("请在微信小程序内登录查看");
await page.getByText("套餐餐品", { exact: true }).click();
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
await page.getByRole("button", { name: "点选编辑" }).click();
await expect
.poll(() =>
@@ -769,9 +789,9 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
await stats.click();
const inspector = page.locator(".presentation-editor__inspector");
await expect(inspector.getByRole("heading", { name: "信任数据" })).toBeVisible();
await expect(page.getByLabel("1. 数字或成果")).toHaveValue("10 年");
await expect(page.getByLabel("2. 说明")).toHaveValue("项目落地");
await page.getByLabel("1. 数字或成果").fill("25 年");
await expect(page.getByLabel("数字或成果", { exact: true }).nth(0)).toHaveValue("10 年");
await expect(page.getByLabel("说明", { exact: true }).nth(1)).toHaveValue("项目落地");
await page.getByLabel("数字或成果", { exact: true }).nth(0).fill("25 年");
await expect(stats.locator(".stat-value").first()).toContainText("25 年");
await inspector.getByRole("button", { name: "保存此项内容" }).click();
await expect.poll(() => editorialWorkspace.trustItems[0].config.stats[0].value).toBe("25 年");
@@ -787,7 +807,7 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
await expect(preview.locator(".founder-copy .quote")).toContainText("跨页面共享的简介回归");
await expect(stats.locator(".stat-value").first()).toContainText("25 年");
await page.getByRole("button", { name: "信任数据", exact: true }).click();
await expect(page.getByLabel("1. 数字或成果")).toHaveValue("25 年");
await expect(page.getByLabel("数字或成果", { exact: true }).nth(0)).toHaveValue("25 年");
await preview.locator('[data-editor-target="editorial.home.hero"]').click();
await expect(page.getByLabel("首页主标题")).toBeVisible();
await page.getByLabel("设计理念", { exact: true }).fill("模板专属理念回归");
@@ -804,20 +824,20 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
await page.reload();
await expect(stats.locator(".stat-value").first()).toContainText("200+");
await preview.locator(".pillar-title").first().click();
await expect(page.getByLabel("1. 方法说明")).toBeVisible();
await page.getByLabel("1. 方法名称").fill("方法名称回归");
await expect(page.getByLabel("方法说明", { exact: true }).nth(0)).toBeVisible();
await page.getByLabel("方法名称", { exact: true }).nth(0).fill("方法名称回归");
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
await page.getByRole("button", { name: "保存此项内容" }).click();
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
await expect(page.getByText("已保存内容草稿,发布后访客才会看到更新")).toBeVisible();
await page.reload();
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
await preview.locator(".flow-name").first().click();
await expect(page.getByLabel("1. 步骤编号")).toBeVisible();
await expect(page.getByLabel("1. 步骤名称")).toBeVisible();
await page.getByLabel("1. 步骤说明").fill("步骤说明回归");
await expect(page.getByLabel("步骤编号", { exact: true }).nth(0)).toBeVisible();
await expect(page.getByLabel("步骤名称", { exact: true }).nth(0)).toBeVisible();
await page.getByLabel("步骤说明", { exact: true }).nth(0).fill("步骤说明回归");
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
await page.getByRole("button", { name: "保存此项内容" }).click();
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
await expect(page.getByText("已保存内容草稿,发布后访客才会看到更新")).toBeVisible();
await page.reload();
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
await preview.locator(".work-card").click();
@@ -826,12 +846,12 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
await page.getByLabel("项目地点", { exact: true }).fill("项目地点回归");
await expect(preview.locator(".work-category")).toContainText("项目地点回归");
await page.getByRole("button", { name: "保存此项内容" }).click();
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
await expect(page.getByText("已保存内容草稿,发布后访客才会看到更新")).toBeVisible();
await page.reload();
await expect(preview.locator(".work-category")).toContainText("项目地点回归");
await page.getByText("主理人与我", { exact: true }).click();
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
await preview.locator('[data-editor-target="linjing-editorial.profile.identity"]').click();
await preview.locator(".editorial-profile .founder").click();
await expect(page.getByRole("button", { name: "信任数据", exact: true })).toHaveCount(0);
await expect(page.getByLabel("主理人姓名")).toBeVisible();
await page.getByLabel("主理人姓名").fill("修改后的主理人");
@@ -179,7 +179,10 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
await expect(preview.locator(".food-detail")).toContainText("列表实时预览餐品");
await expect(page.getByLabel("餐品介绍")).toHaveValue("弹窗编辑后的餐品介绍");
await page.locator(".ant-modal-footer").getByRole("button", { name: "OK" }).click();
await page
.locator(".ant-modal-footer")
.getByRole("button", { name: "确 定", exact: true })
.click();
await expect(page.getByText("业务提供项已保存")).toBeVisible();
await page.locator(".ant-modal-wrap").waitFor({ state: "hidden" });
@@ -199,11 +202,14 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
expect(savedBody.name).toBe("小程序页保存后的餐品");
expect(savedBody.summary).toBe("跨入口保存后的业务简介");
await page.goBack();
await expect(page.getByText("小程序内容:业务展示与详情")).toBeVisible();
await expect(page.getByRole("heading", { name: "业务提供项", exact: true })).toBeVisible();
await page.getByRole("button", { name: "编辑详情" }).click();
await expect(page.getByLabel("名称", { exact: true })).toHaveValue("小程序页保存后的餐品");
await expect(page.getByLabel("餐品介绍")).toHaveValue("弹窗编辑后的餐品介绍");
await page.locator(".ant-modal-footer").getByRole("button", { name: "OK" }).click();
await page
.locator(".ant-modal-footer")
.getByRole("button", { name: "确 定", exact: true })
.click();
await expect(page.getByText("业务提供项已保存")).toBeVisible();
expect(savedBody.name).toBe("小程序页保存后的餐品");
expect(savedBody.summary).toBe("跨入口保存后的业务简介");
+1 -1
View File
@@ -4,7 +4,7 @@
{
"packageKey": "acheng-campus-food",
"packageName": "@personal-brand/template-acheng-campus-food",
"version": "1.0.1"
"version": "1.0.2"
},
{
"packageKey": "linjing-editorial",
+2
View File
@@ -72,6 +72,8 @@ Runtime 合并标准品牌列和模板 config 时,标准列是共享品牌事
画布点选测试必须点击实际区域内部的叶子内容,并验证目标和记录 ID;侧栏定位通过不能代替画布可点击。应避开圆角透明角落,不能用强制点击或 dispatchEvent 掩盖真实命中问题。
预览 renderer 的 React 组件引用必须稳定;鼠标悬浮、选区与草稿更新不得重新创建组件类型并卸载画布。回归需覆盖移动鼠标后点选以及连续输入,确认 DOM、焦点和组件本地状态保留。高亮覆盖层必须穿透指针事件,仅显式选区按钮允许接收点击。
## Taro 小程序视觉一致性
Taro 小程序构建默认会把 CSS 中的 HTML 标签选择器重写为 `.h5-<tag>`,但 React `<Button />` 渲染的是微信原生 `<button>`,不会自动获得 `.h5-button`。本项目关闭小程序 `htmltransform`,保证 `button` 选择器直接命中微信原生 `<button>`;新增共享组件样式时不得再依赖 `.h5-<tag>`。
+10
View File
@@ -563,6 +563,16 @@ Phase 8 自动化持久化与兼容审查(2026-10-17):
退出门禁:真实品牌保存重载发布、视觉证据、双端外部验证和运营审阅记录全部归档;旧兼容层只有在历史品牌迁移验证后才允许删除。
Phase 8 编辑闭环回归(2026-10-18):
- 用户反馈模板预览初步认可,尚不视为逐区域、双端视觉验收完成。
- 修复 Admin renderer 解析每次返回新 React 组件导致悬浮更新卸载画布、点击和输入焦点丢失的问题;同一模板复用稳定组件引用。高亮覆盖层穿透指针,仅组合选区按钮接收点击。
- 修复页面内容保存成功后仍保留未保存标记、切页被错误拦截的问题;失败时继续保留草稿与原有离页保护。
- 修复餐饮菜单底部按钮全宽叠加左右外边距造成的窄屏溢出;包递增为 `acheng-campus-food@1.0.2`,同步 package metadata、生成目录与发布构建清单。
- 编辑器浏览器测试使用真实 manifest,修正 Runtime plugin fixture、列表字段与页面控件定位;新增悬浮后 DOM 保留、覆盖层穿透及保存后切页无确认弹窗断言。数据库 integration 补充全部品牌/业务/信任字段修改后、发布前公开快照不变的断言。
- 浏览器编辑器 `2/2`、模板管理预览 `1/1`、业务弹窗跨入口编辑 `1/1` 通过;隔离数据库 HTTP integration `54/54`、upload `2/2` 通过;Admin unit `6/6`、typecheck、production build、变更 TypeScript ESLint、模板总门禁、format 与 diff 检查通过;餐饮 H5/weapp 本地 smoke 构建及三模板产物契约 `3/3` 通过。餐饮品牌未配置真实 AppID,本次构建不作为真实部署参数或微信发布证据。
- 浏览器 fixture 与数据库 integration 是分别验证的证据,尚未执行连接隔离数据库的完整浏览器发布流程;`template:doctor` 仍为 `completionStatus=unverified`,三个模板静态通过且未解决项为 `0`。
## 13. 历史问题到自动化验收的映射
| 已发生问题 | 必须新增的验收 |
+1 -1
View File
@@ -14,7 +14,7 @@
### 仓库内视觉模板包
- acheng-campus-food@1.0.1:餐饮场景,使用 food 行业能力。
- acheng-campus-food@1.0.2:餐饮场景,使用 food 行业能力。
- linjing-editorial@1.0.4:林境建筑画册,可用于 doors 和 personal 组合。
- atelier-solopreneur@1.3.1:独立工坊方向,适配 personal 行业。
@@ -4,7 +4,7 @@ import type { TemplatePackageManifest } from "./index.js";
export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[] = [
{
packageKey: "acheng-campus-food",
version: "1.0.1",
version: "1.0.2",
displayName: "阿成校园餐",
defaultBrandSlug: "default-brand",
runtimeContract: "1.0",
@@ -5823,4 +5823,4 @@ export const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[
},
];
export const generatedTemplatePackageRegistryHash =
"bdd28cba9e01fe3e121790670475d350d4af5e8f8c9c1cebe89d7fa01bf3c049";
"9331ccd265c062ede2ac010e45e2fb20a38bfa176ca81869e0a54250f2619aa0";
@@ -1,6 +1,6 @@
{
"name": "@personal-brand/template-acheng-campus-food",
"version": "1.0.1",
"version": "1.0.2",
"private": true,
"type": "module",
"files": [
@@ -1246,6 +1246,7 @@
font-size: 20px;
}
.food-list .menu-cta {
width: calc(100% - 64px);
margin: 32px;
background: #f97316;
color: #fff;
@@ -1,6 +1,6 @@
{
"packageKey": "acheng-campus-food",
"version": "1.0.1",
"version": "1.0.2",
"displayName": "阿成校园餐",
"defaultBrandSlug": "default-brand",
"runtimeContract": "1.0",