Skip to content

Commit 3dfcc4a

Browse files
committed
fix: 修复表单数据回填异常
1 parent b622a9b commit 3dfcc4a

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/components/Form/FullForm.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useRef, useImperativeHandle } from 'react';
1+
import { useImperativeHandle, useRef, useState } from 'react';
22
import type { FormStatus } from './typings';
33
import type { ProFormInstance } from '@ant-design/pro-form';
44
import ProForm from '@ant-design/pro-form';
@@ -43,14 +43,16 @@ const FullForm = <E, P = E>(props: FullFormProps<E, P>) => {
4343
setTitle(undefined);
4444
return;
4545
}
46-
// 清空数据
47-
formRef.current?.resetFields();
48-
// 如果需要回填数据
49-
if (data !== undefined && data !== null) {
50-
formRef.current?.setFieldsValue(data);
51-
}
5246
setTitle(`${defautlTitle[st]}${titleSuffix}`);
5347
setHidden(false);
48+
setTimeout(() => {
49+
// 清空数据
50+
formRef.current?.resetFields();
51+
// 如果需要回填数据
52+
if (data !== undefined && data !== null) {
53+
formRef.current?.setFieldsValue(data);
54+
}
55+
});
5456
};
5557

5658
const submit = async (

src/components/Form/ModalForm.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useState, useRef, useImperativeHandle } from 'react';
2-
import type { ModalFormProps, FormStatus } from './typings';
1+
import { useImperativeHandle, useRef, useState } from 'react';
2+
import type { FormStatus, ModalFormProps } from './typings';
33
import type { ProFormInstance } from '@ant-design/pro-form';
44
import { ModalForm as AntdModalForm } from '@ant-design/pro-form';
55
import type { R } from '@/typings';
@@ -58,14 +58,16 @@ const ModalForm = <E, P = E>(props: ModalFormProps<E, P>) => {
5858
setModalTitle(undefined);
5959
return;
6060
}
61-
// 清空数据
62-
formRef.current?.resetFields();
63-
// 如果需要回填数据
64-
if (data !== undefined && data !== null) {
65-
formRef.current?.setFieldsValue(data);
66-
}
6761
setModalTitle(`${defautlTitle[st]}${titleSuffix}`);
6862
setVisible(true);
63+
setTimeout(() => {
64+
// 清空数据
65+
formRef.current?.resetFields();
66+
// 如果需要回填数据
67+
if (data !== undefined && data !== null) {
68+
formRef.current?.setFieldsValue(data);
69+
}
70+
});
6971
};
7072

7173
useImperativeHandle(currencyRef, () => ({

0 commit comments

Comments
 (0)