@@ -3,12 +3,16 @@ import { Collapse, Card } from 'uiw';
33import FormDom from './formdom' ;
44import ReadFormDom from './readform' ;
55import { getFormFields } from './widgets' ;
6- import { ProFormProps , UseFormStateProps } from './type' ;
6+ import { ProFormProps , UseFormStateProps , UseFormProps } from './type' ;
77import { StoreCtx , ColPropsContext } from './hooks/store' ;
8- import { isObjectEmpty } from './utils' ;
98import './style/form-item.less' ;
109
11- function ProForm ( props : ProFormProps , ref : any ) {
10+ function ProForm (
11+ props : ProFormProps ,
12+ ref : React . ForwardedRef <
13+ Partial < React . LegacyRef < UseFormProps > > | undefined | null
14+ > ,
15+ ) {
1216 const {
1317 formDatas = [ ] ,
1418 title = '' ,
@@ -34,37 +38,7 @@ function ProForm(props: ProFormProps, ref: any) {
3438
3539 // 通过ref导出实例方法
3640 const formInstanceRef = useRef < { current : UseFormStateProps } > ( ) ;
37- useImperativeHandle ( ref , ( ) => {
38- // 表单验证(同时兼容老api submitvalidate和新api onSubmit )
39- const submitvalidate = ( ) =>
40- formInstanceRef . current ?. current ?. onSubmit ( ) || null ;
41- // 获取表单的值
42- const getFieldValues = ( ) =>
43- formInstanceRef . current ?. current ?. getFieldValues ( ) || { } ;
44- // 获取表单错误信息
45- const getError = ( ) => formInstanceRef ?. current ?. current ?. getError ( ) || { } ;
46-
47- // 验证并获取表单值
48- const validateFieldsAndGetValue = ( ) => {
49- return new Promise ( async function ( resolve , reject ) {
50- await submitvalidate ( ) ;
51- const errors = getError ( ) ;
52- if ( isObjectEmpty ( errors ) ) {
53- const value = getFieldValues ( ) ;
54- resolve ( value ) ;
55- } else {
56- reject ( errors ) ;
57- }
58- } ) ;
59- } ;
60- return {
61- ...formInstanceRef . current ?. current ,
62- submitvalidate,
63- getFieldValues,
64- getError,
65- validateFieldsAndGetValue,
66- } ;
67- } ) ;
41+ useImperativeHandle ( ref , ( ) => ( { ...form } ) ) ;
6842
6943 let children : React . ReactNode ;
7044 const formDomProps = { ...props , formfields, formInstanceRef } ;
0 commit comments