chore: confirmBox 的 onConfirm 也可能是异步的 如果存在异步错误也需要捕获 (#5856)

* chore: confirmBox 的 onConfirm 也可能是异步的 如果存在异步错误也需要捕获

* 下发 loading
This commit is contained in:
liaoxuezhi 2022-12-08 15:29:34 +08:00 committed by GitHub
parent 41319213ee
commit 70665092c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ export interface ConfirmBoxProps extends LocaleProps, ThemeProps {
children?: children?:
| JSX.Element | JSX.Element
| ((methods: { | ((methods: {
loading?: boolean;
bodyRef: React.MutableRefObject< bodyRef: React.MutableRefObject<
| { | {
submit: () => Promise<Record<string, any>>; submit: () => Promise<Record<string, any>>;
@ -77,7 +78,7 @@ export function ConfirmBox({
return; return;
} }
onConfirm?.(ret); await onConfirm?.(ret);
} catch (e) { } catch (e) {
setError(e.message); setError(e.message);
} finally { } finally {
@ -103,7 +104,8 @@ export function ConfirmBox({
<Modal.Body className={bodyClassName}> <Modal.Body className={bodyClassName}>
{typeof children === 'function' {typeof children === 'function'
? children({ ? children({
bodyRef: bodyRef bodyRef: bodyRef,
loading
}) })
: children} : children}
</Modal.Body> </Modal.Body>