我正在尝试创建一个sweetAlert2函数,在这里我想要启动一个加载屏幕。在加载屏幕期间,我想执行一些功能,这可能需要一些时间。之后,我想显示火灾的成功或错误,这取决于返回的是什么。我尝试了几种方法:
Swal.fire({
title: 'Auto close alert!',
html: 'In progress',
timerProgressBar: true,
didOpen: () => {
try {
Swal.showLoading();
call other functions..
if success show
Swal.fire({
icon: 'success',
title: 'Success...',
html: message
});
or else fire error
catch(err){
etc.
}
}
)};
现在,当我执行函数时,它等待几秒钟(执行函数),然后显示成功或错误触发,但它没有首先显示正在加载对话框。知道怎么弄到这个吗?
发布于 2022-11-15 12:45:38
通过使用setTimouts和允诺修复了它:
//Start
Swal.fire({
title: 'In progress',
html: 'Please wait while your action is being carried out.',
timerProgressBar: true,
didOpen: () => {
//here it will open the in progress box
Swal.showLoading();
//setTimeout with 1000 or more ms is needed in order to show the inprogress box
setTimeout(async () => {
let currentRecID = currentRecord.get().id;
//load complete record
currentRec = record.load({
type: record.Type.OPPORTUNITY,
id: currentRecID,
isDynamic: true
});
const promiseVar = () =>
new Promise((resolve, reject) => {
resolve(canCreateORD(currentRec));
});
canORDbeCreated = await promiseVar();
//Automatically close popup so it continues with willClose
Swal.close();
}, 1000);
},
willClose: () => {
//Show success / error box with Swal.fire
https://stackoverflow.com/questions/74390258
复制相似问题