feat: 完成模板区域与咨询字段编辑闭环
This commit is contained in:
1 parent
c5db30f817
commit
66dbba5748
6 files changed
+211
-24
No files matched your search
@@ -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 保存、发布隔离和重载验证。
|
||||
@@ -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
|
||||
|
@@ -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<string, unknown>) =>
|
||||
runtime.fields.map((item) =>
|
||||
item.key === fieldKey ? ({ ...item, ...values } as typeof item) : item,
|
||||
);
|
||||
const save = useMutation({
|
||||
mutationFn: async (values: Record<string, unknown>) => {
|
||||
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 (
|
||||
<Alert
|
||||
type="error"
|
||||
message="表单读取失败"
|
||||
action={<Button onClick={() => void query.refetch()}>重试</Button>}
|
||||
/>
|
||||
);
|
||||
if (!record)
|
||||
return (
|
||||
<Alert
|
||||
type="info"
|
||||
message={query.isPending ? "正在读取表单" : "未找到对应表单,请刷新后重试"}
|
||||
/>
|
||||
);
|
||||
if (!field) return <Alert type="warning" message="字段已不存在" />;
|
||||
return (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={field}
|
||||
onValuesChange={(_, values) => onDraft(update(values))}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
>
|
||||
<Typography.Paragraph type="secondary">
|
||||
{record.name} · 编辑字段:{field.label}
|
||||
</Typography.Paragraph>
|
||||
<Form.Item
|
||||
name="label"
|
||||
label="字段标题"
|
||||
rules={[{ required: true, message: "请填写字段标题" }]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="type" label="输入方式">
|
||||
<Select
|
||||
options={[
|
||||
{ value: "text", label: "简短文字" },
|
||||
{ value: "textarea", label: "详细说明" },
|
||||
{ value: "tel", label: "联系电话" },
|
||||
{ value: "number", label: "数字" },
|
||||
{ value: "date", label: "日期" },
|
||||
{ value: "select", label: "单项选择" },
|
||||
{ value: "radio", label: "单选按钮" },
|
||||
{ value: "checkbox", label: "多项选择" },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="required" label="必填" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Form.List name="options">
|
||||
{(fields, { add, remove }) => (
|
||||
<div>
|
||||
{fields.length ? <Typography.Title level={5}>选项</Typography.Title> : null}
|
||||
{fields.map(({ key, name }) => (
|
||||
<Space key={key} align="start">
|
||||
<Form.Item name={[name, "label"]} label="选项名称" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name={[name, "value"]} label="选项标识" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Button onClick={() => remove(name)}>删除</Button>
|
||||
</Space>
|
||||
))}
|
||||
<Button onClick={() => add({ label: "新选项", value: crypto.randomUUID() })}>
|
||||
添加选项
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</Form.List>
|
||||
<MutationError error={save.error} />
|
||||
<Button style={{ marginTop: 24 }} type="primary" htmlType="submit" loading={save.isPending}>
|
||||
保存表单字段
|
||||
</Button>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -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<Record<string, unknown>>({});
|
||||
const [inquiryDraft, setInquiryDraft] =
|
||||
useState<RuntimeWorkspace["inquiryForms"][number]["fields"]>();
|
||||
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({
|
||||
<Typography.Title level={5}>
|
||||
{selectedTarget?.label ?? pageTitle(selectedPage ?? "home")}
|
||||
</Typography.Title>
|
||||
{selectedRecordSource && selection?.recordId && selectedSection ? (
|
||||
{activeTarget?.startsWith("inquiry-field:") && inquiryRuntime ? (
|
||||
<InquiryPreviewEditor
|
||||
runtime={
|
||||
draftWorkspace?.inquiryForms.find((item) => item.key === inquiryRuntime.key) ??
|
||||
inquiryRuntime
|
||||
}
|
||||
fieldKey={activeTarget.slice("inquiry-field:".length)}
|
||||
onDraft={setInquiryDraft}
|
||||
/>
|
||||
) : selectedRecordSource && selection?.recordId && selectedSection ? (
|
||||
selectedRecord ? (
|
||||
<RecordEditor
|
||||
key={`${selectedRecordSource}:${selectedRecord.id}:${selectedSection.key}`}
|
||||
@@ -660,7 +701,7 @@ export function PresentationEditor({
|
||||
initialValues={initialValues}
|
||||
onValuesChange={handleValuesChange}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
style={{ minHeight: 0, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
{editableSections.map((section, index) => (
|
||||
@@ -678,11 +719,7 @@ export function PresentationEditor({
|
||||
) : null}
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col
|
||||
key={field.key}
|
||||
xs={24}
|
||||
md={field.input === "textarea" || field.input === "list" ? 24 : 12}
|
||||
>
|
||||
<Col key={field.key} xs={24} md={24}>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
@@ -841,17 +878,13 @@ function RecordEditor({
|
||||
initialValues={initialValues}
|
||||
onValuesChange={(_, values) => onDraft(values)}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
style={{ minHeight: 0, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col
|
||||
key={field.key}
|
||||
xs={24}
|
||||
md={field.input === "textarea" || field.input === "list" ? 24 : 12}
|
||||
>
|
||||
<Col key={field.key} xs={24} md={24}>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
|
||||
@@ -103,6 +103,7 @@ export function Inquiry({
|
||||
<View
|
||||
className={`form-field ${food && ["people", "date", "budget", "delivery"].includes(field.key) ? "half-field" : ""}`}
|
||||
key={field.key}
|
||||
data-editor-target={preview ? `inquiry-field:${field.key}` : undefined}
|
||||
>
|
||||
<Text className="field-label">
|
||||
{field.label}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user