[英]SweetAlert2 executing functions while showing loading showing success after done
I am trying to create a sweetAlert2 function where I want to fire a loading screen.我正在尝试创建一个 sweetAlert2 function 我想在其中触发加载屏幕。 And during the loading screen, I want to execute some functions, which can take some time.
在加载屏幕期间,我想执行一些功能,这可能需要一些时间。 Afterward I want to display a fire success or error, depending on what the return will be.
之后我想显示火灾成功或错误,具体取决于返回的内容。 I tried several methods:
我尝试了几种方法:
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.
}
}
)};
Now when I execute the function it waits a few seconds (executing functions) and then it shows the success or error fire, but it doesn't show the in-progress loading dialog first.现在,当我执行 function 时,它会等待几秒钟(执行函数),然后显示成功或错误触发,但它不会首先显示正在进行的加载对话框。 Any idea how to get this?
知道如何得到这个吗?
Fixed it by using setTimouts and promises:通过使用 setTimouts 和 promises 修复它:
//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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.