feat: 接入后台动态咨询表单配置
This commit is contained in:
1 parent
32d3db90de
commit
7e83d16cc9
1 file changed
+94
@@ -8,7 +8,9 @@ export function WorkspacePage() {
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
const [fieldOpen, setFieldOpen] = useState(false);
|
||||
const [formOpen, setFormOpen] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const [inquiryForm] = Form.useForm();
|
||||
const query = useQuery({
|
||||
queryKey: ["admin-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
@@ -39,6 +41,20 @@ export function WorkspacePage() {
|
||||
mutationFn: (id: string) => client.deleteAdminField(id),
|
||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] }),
|
||||
});
|
||||
const forms = useQuery({
|
||||
queryKey: ["admin-inquiry-forms"],
|
||||
queryFn: () => client.listAdminInquiryForms(),
|
||||
});
|
||||
const createForm = useMutation({
|
||||
mutationFn: (values: { name: string; fieldsSnapshot: unknown[] }) =>
|
||||
client.createAdminInquiryForm(values),
|
||||
onSuccess: () => {
|
||||
message.success("咨询表单已创建");
|
||||
setFormOpen(false);
|
||||
inquiryForm.resetFields();
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
|
||||
},
|
||||
});
|
||||
if (query.isLoading) return <Card loading />;
|
||||
if (query.isError || !query.data) return <Card>工作空间加载失败,请刷新重试。</Card>;
|
||||
const { modules, fields, installations } = query.data;
|
||||
@@ -59,6 +75,30 @@ export function WorkspacePage() {
|
||||
>
|
||||
<Tag>{installations.length ? `已安装 ${installations.length} 个模板` : "尚未安装模板"}</Tag>
|
||||
</Card>
|
||||
<Card
|
||||
title="动态咨询表单"
|
||||
extra={
|
||||
<Button type="primary" onClick={() => setFormOpen(true)}>
|
||||
新增表单
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={forms.isLoading}
|
||||
dataSource={forms.data ?? []}
|
||||
columns={[
|
||||
{ title: "名称", dataIndex: "name" },
|
||||
{ title: "版本", dataIndex: "version", render: (value) => <Tag>v{value}</Tag> },
|
||||
{
|
||||
title: "字段数",
|
||||
dataIndex: "fieldsSnapshot",
|
||||
render: (value: unknown[]) => value?.length ?? 0,
|
||||
},
|
||||
{ title: "状态", dataIndex: "isEnabled", render: (value) => (value ? "启用" : "停用") },
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
<Card title="页面模块">
|
||||
<Table
|
||||
rowKey="id"
|
||||
@@ -193,6 +233,60 @@ export function WorkspacePage() {
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
<Modal
|
||||
open={formOpen}
|
||||
title="新增动态咨询表单"
|
||||
onCancel={() => {
|
||||
setFormOpen(false);
|
||||
inquiryForm.resetFields();
|
||||
}}
|
||||
onOk={() => inquiryForm.submit()}
|
||||
confirmLoading={createForm.isPending}
|
||||
>
|
||||
<Form form={inquiryForm} layout="vertical" onFinish={(values) => createForm.mutate(values)}>
|
||||
<Form.Item name="name" label="表单名称" rules={[{ required: true }]}>
|
||||
<Input placeholder="例如:合作咨询" />
|
||||
</Form.Item>
|
||||
<Form.List name="fieldsSnapshot">
|
||||
{(fields, { add, remove }) => (
|
||||
<>
|
||||
<Form.Item label="表单字段">
|
||||
<Button onClick={() => add({ type: "text", required: false })}>新增字段</Button>
|
||||
</Form.Item>
|
||||
{fields.map(({ key, name, ...restField }) => (
|
||||
<Space key={key} align="start" style={{ display: "flex", marginBottom: 8 }}>
|
||||
<Form.Item {...restField} name={[name, "key"]} rules={[{ required: true }]}>
|
||||
<Input placeholder="Key" />
|
||||
</Form.Item>
|
||||
<Form.Item {...restField} name={[name, "label"]} rules={[{ required: true }]}>
|
||||
<Input placeholder="字段名称" />
|
||||
</Form.Item>
|
||||
<Form.Item {...restField} name={[name, "type"]}>
|
||||
<Select
|
||||
style={{ width: 120 }}
|
||||
options={[
|
||||
"text",
|
||||
"textarea",
|
||||
"number",
|
||||
"date",
|
||||
"select",
|
||||
"multi-select",
|
||||
"image",
|
||||
"url",
|
||||
"phone",
|
||||
].map((value) => ({ value, label: value }))}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Button danger onClick={() => remove(name)}>
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</Form.List>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user