feat: 支持后台配置动态咨询表单

This commit is contained in:
que01 committed 2026-09-23 09:53:35 +08:00
1 parent aee1cff5a3
commit 54bf385f68
5 files changed
+118 -7

No files matched your search

@@ -17,6 +17,7 @@ import { ApiClientError } from "@personal-brand/api-client";
import type {
BrandFieldDefinition,
BrandModule,
InquiryForm,
PublicWorkspace,
} from "@personal-brand/api-client";
import { useState } from "react";
@@ -28,6 +29,7 @@ export function WorkspacePage() {
const queryClient = useQueryClient();
const [fieldOpen, setFieldOpen] = useState(false);
const [formOpen, setFormOpen] = useState(false);
const [editingForm, setEditingForm] = useState<InquiryForm | null>(null);
const [visualTarget, setVisualTarget] = useState<string | null>(null);
const [industryTarget, setIndustryTarget] = useState<{
key: "personal" | "food";
@@ -140,6 +142,18 @@ export function WorkspacePage() {
void queryClient.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
},
});
const updateForm = useMutation({
mutationFn: ({ id, body }: { id: string; body: Partial<InquiryForm> }) =>
client.updateAdminInquiryForm(id, body),
onSuccess: () => {
message.success("咨询表单已更新");
setFormOpen(false);
setEditingForm(null);
inquiryForm.resetFields();
void queryClient.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] });
},
});
if (query.isLoading) return <Card loading />;
if (query.isError || !query.data) {
const errorStatus =
@@ -429,7 +443,14 @@ export function WorkspacePage() {
<Card
title="动态咨询表单"
extra={
<Button type="primary" onClick={() => setFormOpen(true)}>
<Button
type="primary"
onClick={() => {
setEditingForm(null);
inquiryForm.resetFields();
setFormOpen(true);
}}
>
新增表单
</Button>
}
@@ -447,9 +468,41 @@ export function WorkspacePage() {
render: (value: unknown[]) => value?.length ?? 0,
},
{ title: "状态", dataIndex: "isEnabled", render: (value) => (value ? "启用" : "停用") },
{
title: "操作",
render: (_: unknown, item: InquiryForm) => (
<Space>
<Button
size="small"
onClick={() => {
setEditingForm(item);
inquiryForm.setFieldsValue({
name: item.name,
fieldsSnapshot: item.fieldsSnapshot,
});
setFormOpen(true);
}}
>
编辑
</Button>
<Select
size="small"
value={item.isEnabled}
options={[
{ value: true, label: "启用" },
{ value: false, label: "停用" },
]}
onChange={(isEnabled) =>
updateForm.mutate({ id: item.id, body: { isEnabled } })
}
/>
</Space>
),
},
]}
/>
<MutationError error={createForm.error} />
<MutationError error={updateForm.error} />
</Card>
<Card title="页面模块">
<Table
@@ -590,22 +643,27 @@ export function WorkspacePage() {
</Modal>
<Modal
open={formOpen}
title="新增动态咨询表单"
title={editingForm ? "编辑动态咨询表单" : "新增动态咨询表单"}
onCancel={() => {
setFormOpen(false);
setEditingForm(null);
inquiryForm.resetFields();
}}
onOk={() => inquiryForm.submit()}
confirmLoading={createForm.isPending}
confirmLoading={createForm.isPending || updateForm.isPending}
>
<Form
form={inquiryForm}
layout="vertical"
onFinish={(values) =>
createForm.mutate({
name: typeof values.name === "string" ? values.name : "",
fieldsSnapshot: Array.isArray(values.fieldsSnapshot) ? values.fieldsSnapshot : [],
})
(() => {
const body = {
name: typeof values.name === "string" ? values.name : "",
fieldsSnapshot: Array.isArray(values.fieldsSnapshot) ? values.fieldsSnapshot : [],
};
if (editingForm) updateForm.mutate({ id: editingForm.id, body });
else createForm.mutate(body);
})()
}
>
<Form.Item name="name" label="表单名称" rules={[{ required: true }]}>