1- import { memo , ReactElement , useEffect , useMemo } from "react" ;
2- import { Button , Form , FormInstance , FormProps } from "antd" ;
1+ import type { FormInstance , FormProps } from "antd" ;
2+ import type { ReactElement } from "react" ;
3+ import { Button , Form } from "antd" ;
4+ import { memo , useEffect , useMemo } from "react" ;
35
46import { getFormElement } from "../tools" ;
57
@@ -31,7 +33,7 @@ export interface FormListProps extends Omit<FormProps, "labelCol" | "wrapperCol"
3133 *
3234 * @description extend antd Form
3335 */
34- const FormList = ( props : FormListProps ) => {
36+ function FormList ( props : FormListProps ) {
3537 const {
3638 form,
3739 itemInfo,
@@ -50,16 +52,17 @@ const FormList = (props: FormListProps) => {
5052 } = props ;
5153
5254 const [ insideForm ] = Form . useForm ( ) ;
53- const realForm = form ? form : insideForm ;
55+ const realForm = form || insideForm ;
5456
5557 // 只在初始化时生效
5658 useEffect ( ( ) => {
5759 onForm ?.( realForm ) ;
5860
5961 if ( initialValues ) {
6062 realForm . setFieldsValue ( initialValues ) ;
61- } else {
62- itemInfo . forEach ( e => {
63+ }
64+ else {
65+ itemInfo . forEach ( ( e ) => {
6366 if ( e . initialValue !== undefined && e . initialValue !== null ) {
6467 realForm . setFieldValue ( e . name , e . initialValue ) ;
6568 }
@@ -84,22 +87,24 @@ const FormList = (props: FormListProps) => {
8487 if ( submitBtn ) {
8588 if ( submitNode ) {
8689 return submitNode ;
87- } else {
90+ }
91+ else {
8892 return (
8993 < Button htmlType = "submit" type = "primary" block >
9094 保存
9195 </ Button >
9296 ) ;
9397 }
94- } else {
98+ }
99+ else {
95100 return null ;
96101 }
97102 } , [ submitBtn , submitNode ] ) ;
98103
99104 return (
100105 < Form form = { realForm } labelCol = { labelCol ? { span : labelCol } : undefined } wrapperCol = { wrapperCol ? { span : wrapperCol } : undefined } onFinish = { onOk } { ...restProps } >
101106 { itemInfo . map ( ( e , idx ) => {
102- const key = e . name instanceof Array ? e . name . join ( "_" ) : e . name || idx ;
107+ const key = Array . isArray ( e . name ) ? e . name . join ( "_" ) : e . name || idx ;
103108
104109 if ( e . hide ) {
105110 return null ;
@@ -131,6 +136,6 @@ const FormList = (props: FormListProps) => {
131136 { submitBtnNode }
132137 </ Form >
133138 ) ;
134- } ;
139+ }
135140
136141export default memo ( FormList ) ;
0 commit comments