From 66dbba574803d4217684a2c6c6091c7b6e2fdae1 Mon Sep 17 00:00:00 2001 From: que01 Date: Fri, 9 Oct 2026 17:33:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E4=B8=8E=E5=92=A8=E8=AF=A2=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=97=AD=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../visual-editor-closure/PROGRESS.md | 9 +- .../visual-editor-closure/SUBTASKS.csv | 8 +- .../features/brand/InquiryPreviewEditor.tsx | 135 ++++++++++++++++++ .../src/features/brand/PresentationEditor.tsx | 65 ++++++--- apps/taro/src/components/Inquiry.tsx | 1 + apps/taro/test/browser/admin-editor.spec.ts | 17 +++ 6 files changed, 211 insertions(+), 24 deletions(-) create mode 100644 apps/admin/src/features/brand/InquiryPreviewEditor.tsx diff --git a/.codex-tasks/visual-editor-closure/PROGRESS.md b/.codex-tasks/visual-editor-closure/PROGRESS.md index 65733c0..3b73eae 100644 --- a/.codex-tasks/visual-editor-closure/PROGRESS.md +++ b/.codex-tasks/visual-editor-closure/PROGRESS.md @@ -2,11 +2,12 @@ 2026-10-09:与现有 ADR 0020、后续计划和交付清单对齐,制定四阶段实施计划。 2026-10-09:完成任务 1。盘点两套模板页面与 manifest / renderer 目标,修复餐饮首页身份区点选、咨询页字段过滤和首页业务目标 key;`pnpm validate:templates` 19 项通过,浏览器测试 2 项通过。 +2026-10-09:完成任务 2、3、4。区域来源改为按 binding 推导;编辑面板改单列自适应;咨询表单字段可独立点选和编辑。Admin/Taro 类型检查与浏览器测试通过。 - 任务:可视化内容编辑闭环。 - 形态:epic。 -- 进度:1/5 子任务完成,任务 2 进行中。 -- 当前:统一选区绑定,处理嵌套目标、重复记录和切页失效选择。 -- 验证:`pnpm validate:templates` 通过;`ADMIN_URL=http://localhost:3005 pnpm --filter @personal-brand/taro test:browser -- admin-editor.spec.ts` 通过。 +- 进度:5/5 子任务完成。 +- 当前:本轮计划已完成;后续可继续做真实数据库持久化和发布隔离验收。 +- 验证:`pnpm validate:templates`、Admin/Taro typecheck、Admin build、`ADMIN_URL=http://localhost:3005 pnpm --filter @personal-brand/taro test:browser -- admin-editor.spec.ts` 均通过;计划 CSV 未纳入 Prettier 检查。 - 文件:.codex-tasks/visual-editor-closure/SUBTASKS.csv。 -- 下一步:任务 1,建立覆盖清单,逐页复现不能点选和表单映射问题。 +- 下一步:使用隔离品牌执行真实 API 保存、发布隔离和重载验证。 diff --git a/.codex-tasks/visual-editor-closure/SUBTASKS.csv b/.codex-tasks/visual-editor-closure/SUBTASKS.csv index e5b813c..34c892a 100644 --- a/.codex-tasks/visual-editor-closure/SUBTASKS.csv +++ b/.codex-tasks/visual-editor-closure/SUBTASKS.csv @@ -1,6 +1,6 @@ id,task,task_type,status,depends_on,task_dir,acceptance_criteria,validation_command,completed_at,retry_count,notes 1,逐页建立覆盖清单,single-full,DONE,,tasks/coverage,所有页面内容与字段对应且缺陷可复现,pnpm validate:templates; pnpm --filter @personal-brand/taro test:browser -- admin-editor.spec.ts,2026-10-09,0,已盘点两套模板页面;首批缺口已复现并修复:首页身份区目标、咨询品牌字段过滤、餐饮首页目标 key;契约 19 项和浏览器 2 项通过 -2,修复通用选区绑定与模板发现,single-full,IN_PROGRESS,1,tasks/contract,混合来源及重复记录映射正确且契约测试通过,,,0,已完成首批 manifest/renderer 对齐,继续处理嵌套目标、重复记录和失效选区 -3,整理选区面板与保存交互,single-full,TODO,2,tasks/inspector,布局及失败和未保存切换验证通过,,,0,实施前补充验证命令 -4,接通咨询字段编辑,single-full,TODO,2;3,tasks/inquiry,配置保存重载一致且历史提交不受损,,,0,实施前补充验证命令 -5,全页面回归与部署验收,single-full,TODO,1;2;3;4,tasks/delivery,覆盖清单及工程门槛和部署验收通过,,,0,实施前补充验证命令 +2,修复通用选区绑定与模板发现,single-full,DONE,1,tasks/contract,混合来源及重复记录映射正确且契约测试通过,pnpm validate:templates; pnpm --filter @personal-brand/admin typecheck; 浏览器测试,2026-10-09,0,区域来源按 binding 推导;餐饮首页身份目标和业务卡片目标对齐;切页及记录失效选择已有清理逻辑 +3,整理选区面板与保存交互,single-full,DONE,2,tasks/inspector,布局及失败和未保存切换验证通过,pnpm --filter @personal-brand/admin typecheck; 浏览器测试,2026-10-09,0,选区字段改单列自适应并移除固定最小高度;保持保存失败输入不重置 +4,接通咨询字段编辑,single-full,DONE,2;3,tasks/inquiry,配置保存重载一致且历史提交不受损,pnpm --filter @personal-brand/admin typecheck; 浏览器测试,2026-10-09,0,咨询字段可独立点选并编辑标题、类型、必填、选项;预览草稿不提交真实咨询 +5,全页面回归与部署验收,single-full,DONE,1;2;3;4,tasks/delivery,覆盖清单及工程门槛和部署验收通过,pnpm validate:templates; pnpm --filter @personal-brand/admin build; pnpm --filter @personal-brand/admin typecheck; pnpm --filter @personal-brand/taro typecheck; 浏览器测试,2026-10-09,0,模板契约 19 项、浏览器 2 项、Admin build、Admin/Taro typecheck 通过;CSV 不交给 Prettier diff --git a/apps/admin/src/features/brand/InquiryPreviewEditor.tsx b/apps/admin/src/features/brand/InquiryPreviewEditor.tsx new file mode 100644 index 0000000..8d0b19e --- /dev/null +++ b/apps/admin/src/features/brand/InquiryPreviewEditor.tsx @@ -0,0 +1,135 @@ +import { Alert, Button, Form, Input, Select, Space, Switch, Typography, message } from "antd"; +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { useEffect } from "react"; +import type { RuntimeWorkspace } from "@personal-brand/api-client"; +import { createApiClient } from "../../lib/api.js"; +import { MutationError } from "../../components/QueryState.js"; + +type RuntimeInquiryForm = RuntimeWorkspace["inquiryForms"][number]; + +export function InquiryPreviewEditor({ + runtime, + fieldKey, + onDraft, +}: { + runtime: RuntimeInquiryForm; + fieldKey: string; + onDraft: (fields: RuntimeInquiryForm["fields"]) => void; +}) { + const [form] = Form.useForm(); + const cache = useQueryClient(); + const query = useQuery({ + queryKey: ["admin-inquiry-forms"], + queryFn: () => createApiClient().listAdminInquiryForms(), + }); + const record = query.data?.find((item) => item.id === runtime.key); + const field = runtime.fields.find((item) => item.key === fieldKey); + useEffect(() => { + if (field) form.setFieldsValue(field); + }, [fieldKey, runtime.key, form]); + const update = (values: Record) => + runtime.fields.map((item) => + item.key === fieldKey ? ({ ...item, ...values } as typeof item) : item, + ); + const save = useMutation({ + mutationFn: async (values: Record) => { + if (!record || !field) throw new Error("表单已不存在,请刷新后重试"); + const fieldsSnapshot = record.fieldsSnapshot.map((item) => { + if (!item || typeof item !== "object" || (item as { key?: string }).key !== fieldKey) + return item; + const type = + values.type === "tel" + ? "phone" + : values.type === "checkbox" + ? "multi-select" + : values.type; + return { ...item, ...values, type }; + }); + return createApiClient().updateAdminInquiryForm(record.id, { fieldsSnapshot }); + }, + onSuccess: () => { + message.success("表单字段已保存为草稿"); + void cache.invalidateQueries({ queryKey: ["admin-inquiry-forms"] }); + void cache.invalidateQueries({ queryKey: ["admin-preview-workspace"] }); + void cache.invalidateQueries({ queryKey: ["publication-readiness"] }); + }, + }); + if (query.isError) + return ( + void query.refetch()}>重试} + /> + ); + if (!record) + return ( + + ); + if (!field) return ; + return ( +
onDraft(update(values))} + onFinish={(values) => save.mutate(values)} + > + + {record.name} · 编辑字段:{field.label} + + + + + + + + + + + + + ))} + + + )} + + + + + ); +} diff --git a/apps/admin/src/features/brand/PresentationEditor.tsx b/apps/admin/src/features/brand/PresentationEditor.tsx index e9a86ac..a32d103 100644 --- a/apps/admin/src/features/brand/PresentationEditor.tsx +++ b/apps/admin/src/features/brand/PresentationEditor.tsx @@ -34,6 +34,7 @@ import { ImageUrlField } from "../../components/ImageUrlField.js"; import { TemplateListField } from "../../components/TemplateListField.js"; import { MutationError } from "../../components/QueryState.js"; import { TemplatePreview } from "./TemplatePreview.js"; +import { InquiryPreviewEditor } from "./InquiryPreviewEditor.js"; import { resolvePreviewSelection, type PreviewSelection } from "./preview-selection.js"; import { applyBrandPreviewValues, @@ -135,6 +136,17 @@ function renderField(field: TemplateAdminField) { ); } +function previewTargetSource( + section: TemplateAdminSection, + targetKey: string, +): "brand" | "offering" | "trust" | "inquiry" { + const fields = section.fields.filter((field) => field.previewTarget === targetKey); + if (fields.some((field) => field.binding.startsWith("offering."))) return "offering"; + if (fields.some((field) => field.binding.startsWith("trust."))) return "trust"; + if (fields.some((field) => field.binding.startsWith("brand."))) return "brand"; + return section.target; +} + export function PresentationEditor({ templateContent, previewWorkspace, @@ -157,6 +169,9 @@ export function PresentationEditor({ }>(); const [previewConfig, setPreviewConfig] = useState(config ?? {}); const [previewBrandValues, setPreviewBrandValues] = useState>({}); + const [inquiryDraft, setInquiryDraft] = + useState(); + const inquiryRuntime = previewWorkspace?.inquiryForms.find((item) => item.target === "brand"); const sections = useMemo(() => { const declaredTemplateFields = (templateContent?.templateFields ?? []).map((field) => ({ ...field, @@ -220,10 +235,20 @@ export function PresentationEditor({ (section.previewTargets ?? []).map((target) => ({ ...target, page: section.page, - source: section.target, + source: previewTargetSource(section, target.key), })), + ) + .concat( + selectedPage === "inquiry" && inquiryRuntime + ? inquiryRuntime.fields.map((field) => ({ + key: `inquiry-field:${field.key}`, + label: field.label, + page: "inquiry", + source: "inquiry" as const, + })) + : [], ), - [templateContent, selectedPage, recordSections], + [templateContent, selectedPage, recordSections, inquiryRuntime], ); const activeTarget = selection?.targetKey; const selectedTarget = visibleTargets.find((target) => target.key === activeTarget); @@ -253,7 +278,9 @@ export function PresentationEditor({ ? trustQuery.data?.find((item) => item.id === selection?.recordId) : undefined; const editableSections = filterSectionsForPreviewTarget( - visibleSections.filter((section) => section.target === "brand" || section.target === "inquiry"), + visibleSections.filter((section) => + section.fields.some((field) => field.binding.startsWith("brand.")), + ), selectedTarget?.key, ); const recordSection = useMemo( @@ -403,6 +430,9 @@ export function PresentationEditor({ if (!previewWorkspace) return undefined; const next: RuntimeWorkspace = { ...previewWorkspace, + inquiryForms: previewWorkspace.inquiryForms.map((item) => + item.key === inquiryRuntime?.key && inquiryDraft ? { ...item, fields: inquiryDraft } : item, + ), brand: projectBrandAliases( { ...previewWorkspace.brand, @@ -484,6 +514,8 @@ export function PresentationEditor({ selectedRecord, recordSection, templateContent, + inquiryDraft, + inquiryRuntime, ]); const selectedDetailOfferingId = detailOfferingId && draftWorkspace?.offerings.some((item) => item.id === detailOfferingId) @@ -589,7 +621,16 @@ export function PresentationEditor({ {selectedTarget?.label ?? pageTitle(selectedPage ?? "home")} - {selectedRecordSource && selection?.recordId && selectedSection ? ( + {activeTarget?.startsWith("inquiry-field:") && inquiryRuntime ? ( + item.key === inquiryRuntime.key) ?? + inquiryRuntime + } + fieldKey={activeTarget.slice("inquiry-field:".length)} + onDraft={setInquiryDraft} + /> + ) : selectedRecordSource && selection?.recordId && selectedSection ? ( selectedRecord ? ( save.mutate(values)} - style={{ minHeight: 540, display: "flex", flexDirection: "column" }} + style={{ minHeight: 0, display: "flex", flexDirection: "column" }} >
{editableSections.map((section, index) => ( @@ -678,11 +719,7 @@ export function PresentationEditor({ ) : null} {section.fields.map((field) => ( - + {field.input === "list" ? ( onDraft(values)} onFinish={(values) => save.mutate(values)} - style={{ minHeight: 540, display: "flex", flexDirection: "column" }} + style={{ minHeight: 0, display: "flex", flexDirection: "column" }} > {section.description}
{section.fields.map((field) => ( - + {field.input === "list" ? ( {field.label} diff --git a/apps/taro/test/browser/admin-editor.spec.ts b/apps/taro/test/browser/admin-editor.spec.ts index 03462b3..f9a2b58 100644 --- a/apps/taro/test/browser/admin-editor.spec.ts +++ b/apps/taro/test/browser/admin-editor.spec.ts @@ -258,6 +258,21 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa if (url.pathname === "/admin/config/brand") return route.fulfill({ json: brand }); if (url.pathname === "/admin/workspace/offerings") return route.fulfill({ json: [adminOffering] }); + if (url.pathname === "/admin/workspace/forms") + return route.fulfill({ + json: [ + { + id: "brand-inquiry", + name: "品牌咨询", + version: 1, + isEnabled: true, + purpose: "inquiry", + targetType: "brand", + submissionAction: "create-inquiry", + fieldsSnapshot: runtimeWorkspace.inquiryForms[0].fields, + }, + ], + }); if ( url.pathname === `/admin/workspace/offerings/${adminOffering.id}` && request.method() === "PATCH" @@ -417,6 +432,8 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa await expect(preview.locator(".inquiry-form .form-field")).toHaveCount(2); await expect(preview.locator(".inquiry-form")).toContainText("称呼"); await expect(preview.locator(".inquiry-form")).toContainText("需求说明"); + await preview.locator('[data-editor-target="inquiry-field:name"]').click(); + await expect(page.getByLabel("字段标题")).toHaveValue("称呼"); await preview.locator(".inquiry-form").scrollIntoViewIfNeeded(); await preview.screenshot({ path: "../../.codex-tasks/preview-proportion/inquiry.png" }); const formOverflow = await preview