import type { ModalAction } from '../types/modal'; /** * 创建弹窗关闭流程处理函数。 * @param onCloseState - 更新 visible/promise 状态 * @returns closeFn(before, action) */ function createCloseHandler( onCloseState: () => void, ) { return function closeFn( this: any, before: ((next: () => void) => any) | null | undefined, action: ModalAction, ) { const close = async function closeInner(this: any) { const _close = () => { onCloseState(); setTimeout(() => { this.afterCloseModal && this.afterCloseModal(this.data, action, this); this.modalOptions.afterCloseModal && this.modalOptions.afterCloseModal(this.data, action, this); }); }; if (before) await before(_close); else _close(); }; const modalClose = () => { if (this.modalOptions.beforeCloseModal) { return this.modalOptions.beforeCloseModal( (ok: any) => ((ok !== false) && close.call(this)), action, ); } return close.call(this); }; if (this.beforeCloseModal) { return this.beforeCloseModal( (ok: any) => ((ok !== false) && modalClose.call(this)), action, this, ); } return modalClose.call(this); }; } export { createCloseHandler, };