feat: 完善动态咨询表单设计器

This commit is contained in:
que01 committed 2026-09-23 10:19:18 +08:00
1 parent c62e3aa5f0
commit ef0aa169a6
6 files changed
+116 -4

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# 表单设计器完善
## 目标
让个人品牌平台的后台可以完整配置跨行业咨询表单:表单用途、关联业务、字段类型、必填规则和选项都由配置驱动,小程序继续只消费 Runtime Workspace。
## 验收
- 可配置 `inquiry`、`quote-request` 等用途。
- 可将表单关联到品牌或具体业务提供项。
- `select` / `radio` 字段可配置选项并正确下发。
- 编辑失败时保留表单输入,成功后刷新 Runtime。
- API、Admin build、小程序 fixture 全部通过。
@@ -0,0 +1,13 @@
# 进度
- 任务:表单设计器完善
- 形态:epic
- 进度:3/3
- 当前:全部子任务完成
- 真相文件:`SUBTASKS.csv`
## 验证
- API integration tests:25 passed。
- Admin production build:通过。
- Miniapp fixture 和 visual fixture:通过。
@@ -0,0 +1,4 @@
id,title,task_type,depends_on,status,task_dir,acceptance_criteria,validation_command,notes
1,表单设计器配置项,single-full,,DONE,tasks/designer,后台可配置用途业务关联和字段选项,pnpm --filter @personal-brand/admin build,已完成
2,Runtime 契约测试,single-full,1,DONE,tasks/designer,用途和选项正确进入公开工作空间,pnpm --filter @personal-brand/api test:integration,已完成
3,跨模板回归,single-full,2,DONE,tasks/regression,小程序 fixture 和视觉 fixture 通过,pnpm --filter @personal-brand/miniapp test:fixture && pnpm --filter @personal-brand/miniapp test:visual-fixture,已完成
1 id title task_type depends_on status task_dir acceptance_criteria validation_command notes
2 1 表单设计器配置项 single-full DONE tasks/designer 后台可配置用途业务关联和字段选项 pnpm --filter @personal-brand/admin build 已完成
3 2 Runtime 契约测试 single-full 1 DONE tasks/designer 用途和选项正确进入公开工作空间 pnpm --filter @personal-brand/api test:integration 已完成
4 3 跨模板回归 single-full 2 DONE tasks/regression 小程序 fixture 和视觉 fixture 通过 pnpm --filter @personal-brand/miniapp test:fixture && pnpm --filter @personal-brand/miniapp test:visual-fixture 已完成
@@ -0,0 +1,7 @@
# 表单设计器配置项
状态:DONE
- 支持需求咨询、获取报价、预约服务用途。
- 支持品牌级或业务提供项级关联。
- 支持 select / radio 字段选项 JSON 编辑。
@@ -0,0 +1,7 @@
# 跨模板回归
状态:DONE
- API 集成测试:25 passed。
- Miniapp fixture:通过。
- Miniapp visual fixture:通过。
@@ -133,8 +133,14 @@ export function WorkspacePage() {
},
});
const createForm = useMutation({
mutationFn: (values: { name: string; fieldsSnapshot: unknown[] }) =>
client.createAdminInquiryForm(values),
mutationFn: (values: {
name: string;
offeringId?: string;
purpose?: InquiryForm["purpose"];
targetType?: InquiryForm["targetType"];
submissionAction?: InquiryForm["submissionAction"];
fieldsSnapshot: unknown[];
}) => client.createAdminInquiryForm(values),
onSuccess: () => {
message.success("咨询表单已创建");
setFormOpen(false);
@@ -478,7 +484,17 @@ export function WorkspacePage() {
setEditingForm(item);
inquiryForm.setFieldsValue({
name: item.name,
fieldsSnapshot: item.fieldsSnapshot,
purpose: item.purpose,
offeringId: item.offeringId ?? undefined,
fieldsSnapshot: item.fieldsSnapshot.map((field) => {
const value = field as Record<string, unknown>;
return {
...value,
...(Array.isArray(value.options)
? { optionsText: JSON.stringify(value.options) }
: {}),
};
}),
});
setFormOpen(true);
}}
@@ -659,7 +675,25 @@ export function WorkspacePage() {
(() => {
const body = {
name: typeof values.name === "string" ? values.name : "",
fieldsSnapshot: Array.isArray(values.fieldsSnapshot) ? values.fieldsSnapshot : [],
offeringId: typeof values.offeringId === "string" ? values.offeringId : undefined,
purpose: values.purpose as InquiryForm["purpose"],
targetType: values.offeringId ? "offering" : "brand",
submissionAction:
values.purpose === "quote-request" ? "create-quote" : "create-inquiry",
fieldsSnapshot: (Array.isArray(values.fieldsSnapshot)
? values.fieldsSnapshot
: []
).map((field) => {
const item = field as Record<string, unknown>;
if (typeof item.optionsText !== "string") return item;
try {
const options = JSON.parse(item.optionsText);
const { optionsText: _optionsText, ...rest } = item;
return { ...rest, options };
} catch {
return item;
}
}),
};
if (editingForm) updateForm.mutate({ id: editingForm.id, body });
else createForm.mutate(body);
@@ -669,6 +703,29 @@ export function WorkspacePage() {
<Form.Item name="name" label="表单名称" rules={[{ required: true }]}>
<Input placeholder="例如:合作咨询" />
</Form.Item>
<Space style={{ display: "flex" }} align="start">
<Form.Item name="purpose" label="用途" initialValue="inquiry">
<Select
style={{ width: 160 }}
options={[
{ value: "inquiry", label: "需求咨询" },
{ value: "quote-request", label: "获取报价" },
{ value: "booking", label: "预约服务" },
]}
/>
</Form.Item>
<Form.Item name="offeringId" label="关联业务">
<Select
allowClear
style={{ width: 220 }}
placeholder="品牌级表单"
options={(runtimeQuery.data?.offerings ?? []).map((item) => ({
value: item.id,
label: item.name,
}))}
/>
</Form.Item>
</Space>
<Form.List name="fieldsSnapshot">
{(fields, { add, remove }) => (
<>
@@ -699,6 +756,17 @@ export function WorkspacePage() {
].map((value) => ({ value, label: value }))}
/>
</Form.Item>
<Form.Item noStyle shouldUpdate>
{({ getFieldValue }) =>
["select", "radio"].includes(
getFieldValue(["fieldsSnapshot", name, "type"]),
) ? (
<Form.Item {...restField} name={[name, "optionsText"]}>
<Input placeholder="选项 JSON" />
</Form.Item>
) : null
}
</Form.Item>
<Button danger onClick={() => remove(name)}>
删除
</Button>