简体   繁体   English

SweetAlert2 在显示加载时执行功能,完成后显示成功

[英]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.

相关问题 Bootstrap V5 表单验证和 Sweetalert2:成功提交后显示成功消息 - Bootstrap V5 Form Validation & Sweetalert2 : Showing success message after successful submission PHP echo 不显示 SweetAlert2 弹出窗口 - PHP echo not showing SweetAlert2 pop-up SweetAlert2-从showLoading()开始并在执行函数后关闭 - SweetAlert2 - Start with showLoading () and close after executing a function SweetAlert2 模态加载后加载脚本 - Loading scripts after SweetAlert2 modal has loaded 角度2:bootstrap-sweetalert未显示成功弹出窗口 - Angular 2: bootstrap-sweetalert not showing popup for success 在页面加载时显示div,完成时隐藏 - Showing a div while page is loading, hiding when its done 如何在使用 sweetalert2 显示下一个警报之前等待操作完成 - How do I wait for an action to finish before showing the next alert using sweetalert2 等待所有 ajax 调用结束,然后再显示 SweetAlert2 Toastr mixin - Wait for all ajax calls to end before showing SweetAlert2 Toastr mixin SweetAlert2:单击按钮后根据div的选择执行“功能”或“异步功能” - SweetAlert2 : Executing “function” or “async function” based on selection of a div after clicking a button while按钮中的SweetAlert2在最后一行不起作用 - SweetAlert2 in while button not working on last row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM