types(Dialog): improve showDialog return type (#12316)

This commit is contained in:
neverland 2023-09-24 15:52:29 +08:00 committed by GitHub
parent bd7ee34eba
commit 7b6a99da2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 10 deletions

View File

@ -46,10 +46,12 @@ function initInstance() {
({ instance } = mountComponent(Wrapper)); ({ instance } = mountComponent(Wrapper));
} }
export function showDialog(options: DialogOptions) { export function showDialog(
options: DialogOptions,
): Promise<DialogAction | undefined> {
/* istanbul ignore if */ /* istanbul ignore if */
if (!inBrowser) { if (!inBrowser) {
return Promise.resolve(); return Promise.resolve(undefined);
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -59,7 +61,7 @@ export function showDialog(options: DialogOptions) {
instance.open( instance.open(
extend({}, currentOptions, options, { extend({}, currentOptions, options, {
callback: (action: DialogAction) => { callback: (action?: DialogAction) => {
(action === 'confirm' ? resolve : reject)(action); (action === 'confirm' ? resolve : reject)(action);
}, },
}), }),

View File

@ -92,8 +92,8 @@ export default {
showConfirmDialog({ showConfirmDialog({
title: 'Are you sure to delete?', title: 'Are you sure to delete?',
}) })
.then(resolve) .then(() => resolve(true))
.catch(resolve); .catch(() => resolve(false));
}); });
} }
}; };

View File

@ -99,8 +99,8 @@ export default {
showConfirmDialog({ showConfirmDialog({
title: '确定删除吗?', title: '确定删除吗?',
}) })
.then(resolve) .then(() => resolve(true))
.catch(resolve); .catch(() => resolve(false));
}); });
} }
}; };

View File

@ -38,9 +38,13 @@ const beforeClose = ({ position }: { position: string }) => {
case 'outside': case 'outside':
return true; return true;
case 'right': case 'right':
return showConfirmDialog({ return new Promise<boolean>((resolve) => {
showConfirmDialog({
title: t('confirm'), title: t('confirm'),
}) as Promise<boolean>; })
.then(() => resolve(true))
.catch(() => resolve(false));
});
} }
}; };
</script> </script>