From dda8e135873691abf71ef9c0bb198f60ecc7d4a0 Mon Sep 17 00:00:00 2001 From: mamamiyear Date: Wed, 12 Nov 2025 12:19:46 +0800 Subject: [PATCH] feat: support edit people --- src/components/PeopleForm.tsx | 28 +++- src/components/ResourceList.tsx | 229 ++++++++++++++++++++++++++++++-- 2 files changed, 241 insertions(+), 16 deletions(-) diff --git a/src/components/PeopleForm.tsx b/src/components/PeopleForm.tsx index 02e0051..383d645 100644 --- a/src/components/PeopleForm.tsx +++ b/src/components/PeopleForm.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect } from 'react'; import { Form, Input, Select, InputNumber, Button, message, Row, Col } from 'antd'; +import type { FormInstance } from 'antd'; import './PeopleForm.css'; import KeyValueList from './KeyValueList.tsx' import { createPeople, type People } from '../apis'; @@ -8,9 +9,13 @@ const { TextArea } = Input; interface PeopleFormProps { initialData?: any; + // 编辑模式下由父组件控制提交,隐藏内部提交按钮 + hideSubmitButton?: boolean; + // 暴露 AntD Form 实例给父组件,用于在外部触发校验与取值 + onFormReady?: (form: FormInstance) => void; } -const PeopleForm: React.FC = ({ initialData }) => { +const PeopleForm: React.FC = ({ initialData, hideSubmitButton = false, onFormReady }) => { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); @@ -36,10 +41,17 @@ const PeopleForm: React.FC = ({ initialData }) => { form.setFieldsValue(formData); // 显示成功消息 - message.success('已自动填充表单,请检查并确认信息'); + // message.success('已自动填充表单,请检查并确认信息'); } }, [initialData, form]); + // 将表单实例暴露给父组件 + useEffect(() => { + onFormReady?.(form); + // 仅在首次挂载时调用一次 + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + const onFinish = async (values: any) => { setLoading(true); @@ -161,11 +173,13 @@ const PeopleForm: React.FC = ({ initialData }) => {