diff --git a/apps/admin/src/features/brand/ComponentTemplatePreview.css b/apps/admin/src/features/brand/ComponentTemplatePreview.css index 9d377cf..87feaef 100644 --- a/apps/admin/src/features/brand/ComponentTemplatePreview.css +++ b/apps/admin/src/features/brand/ComponentTemplatePreview.css @@ -168,6 +168,6 @@ display: block; } -.component-template-preview__overlay-host > * { +.component-template-preview__overlay-host > .component-template-preview__composite-select { pointer-events: auto; } diff --git a/apps/admin/src/features/brand/PresentationEditor.tsx b/apps/admin/src/features/brand/PresentationEditor.tsx index df8198e..9a3ae3e 100644 --- a/apps/admin/src/features/brand/PresentationEditor.tsx +++ b/apps/admin/src/features/brand/PresentationEditor.tsx @@ -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 = diff --git a/apps/admin/src/features/brand/component-renderers.jsx b/apps/admin/src/features/brand/component-renderers.jsx index 2498e8c..d746106 100644 --- a/apps/admin/src/features/brand/component-renderers.jsx +++ b/apps/admin/src/features/brand/component-renderers.jsx @@ -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 ; @@ -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 ( {pageContent(props)} ); - }; + } + resolvedRenderers.set(key, TemplatePreview); + return TemplatePreview; } diff --git a/apps/admin/src/features/brand/presentation-editor-state.ts b/apps/admin/src/features/brand/presentation-editor-state.ts index 9515d7e..ad01146 100644 --- a/apps/admin/src/features/brand/presentation-editor-state.ts +++ b/apps/admin/src/features/brand/presentation-editor-state.ts @@ -98,6 +98,7 @@ interface BrandSaveMutationOptions extends BrandPresentationFormState { config: Record | 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"] }); diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index 7c8e90c..74f3a08 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -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, diff --git a/apps/taro/test/browser/admin-editor.spec.ts b/apps/taro/test/browser/admin-editor.spec.ts index 9ff5f82..e5e8853 100644 --- a/apps/taro/test/browser/admin-editor.spec.ts +++ b/apps/taro/test/browser/admin-editor.spec.ts @@ -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("修改后的主理人"); diff --git a/apps/taro/test/browser/services-editor.spec.ts b/apps/taro/test/browser/services-editor.spec.ts index 8dba7ed..57bde4f 100644 --- a/apps/taro/test/browser/services-editor.spec.ts +++ b/apps/taro/test/browser/services-editor.spec.ts @@ -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("跨入口保存后的业务简介"); diff --git a/config/template-build.json b/config/template-build.json index 1510c17..1ca8b6c 100644 --- a/config/template-build.json +++ b/config/template-build.json @@ -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", diff --git a/docs/template-completion-rules.md b/docs/template-completion-rules.md index d428be2..6b42cad 100644 --- a/docs/template-completion-rules.md +++ b/docs/template-completion-rules.md @@ -72,6 +72,8 @@ Runtime 合并标准品牌列和模板 config 时,标准列是共享品牌事 画布点选测试必须点击实际区域内部的叶子内容,并验证目标和记录 ID;侧栏定位通过不能代替画布可点击。应避开圆角透明角落,不能用强制点击或 dispatchEvent 掩盖真实命中问题。 +预览 renderer 的 React 组件引用必须稳定;鼠标悬浮、选区与草稿更新不得重新创建组件类型并卸载画布。回归需覆盖移动鼠标后点选以及连续输入,确认 DOM、焦点和组件本地状态保留。高亮覆盖层必须穿透指针事件,仅显式选区按钮允许接收点击。 + ## Taro 小程序视觉一致性 Taro 小程序构建默认会把 CSS 中的 HTML 标签选择器重写为 `.h5-`,但 React `