feat: 完善动态咨询表单设计器
This commit is contained in:
1 parent
c62e3aa5f0
commit
ef0aa169a6
6 files changed
+116
-4
No files matched your search
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user