feat: 函数式弹框组件添加 beforeCancelbeforeSure回调

This commit is contained in:
xiaoxian521 2023-05-10 17:42:43 +08:00
parent b2d06d2b3b
commit 47f951312e
2 changed files with 18 additions and 2 deletions

View File

@ -19,7 +19,13 @@ const footerButtons = computed(() => {
text: true, text: true,
bg: true, bg: true,
btnClick: ({ dialog: { options, index } }) => { btnClick: ({ dialog: { options, index } }) => {
closeDialog(options, index, { command: "cancel" }); const done = () =>
closeDialog(options, index, { command: "cancel" });
if (options?.beforeCancel && isFunction(options?.beforeCancel)) {
options.beforeCancel(done);
} else {
done();
}
} }
}, },
{ {
@ -28,7 +34,13 @@ const footerButtons = computed(() => {
text: true, text: true,
bg: true, bg: true,
btnClick: ({ dialog: { options, index } }) => { btnClick: ({ dialog: { options, index } }) => {
closeDialog(options, index, { command: "sure" }); const done = () =>
closeDialog(options, index, { command: "sure" });
if (options?.beforeSure && isFunction(options?.beforeSure)) {
options.beforeSure(done);
} else {
done();
}
} }
} }
] as Array<ButtonProps>); ] as Array<ButtonProps>);

View File

@ -189,6 +189,10 @@ interface DialogOptions extends DialogProps {
options: DialogOptions; options: DialogOptions;
index: number; index: number;
}) => void; }) => void;
/** 点击底部取消按钮的回调,会暂停 `Dialog` 的关闭. 回调函数内执行 `done` 参数方法的时候才是真正关闭对话框的时候 */
beforeCancel?: (done: Function) => void;
/** 点击底部确定按钮的回调,会暂停 `Dialog` 的关闭. 回调函数内执行 `done` 参数方法的时候才是真正关闭对话框的时候 */
beforeSure?: (done: Function) => void;
} }
export type { EventType, ArgsType, DialogProps, ButtonProps, DialogOptions }; export type { EventType, ArgsType, DialogProps, ButtonProps, DialogOptions };