mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types(Dialog): improve showDialog return type (#12316)
This commit is contained in:
parent
bd7ee34eba
commit
7b6a99da2f
@ -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);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -99,8 +99,8 @@ export default {
|
|||||||
showConfirmDialog({
|
showConfirmDialog({
|
||||||
title: '确定删除吗?',
|
title: '确定删除吗?',
|
||||||
})
|
})
|
||||||
.then(resolve)
|
.then(() => resolve(true))
|
||||||
.catch(resolve);
|
.catch(() => resolve(false));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user