[英]Sweetalert Loading Screen Before .withsuccesshandler
我正在將 sweetalert2 集成到我的 Google Workspace 插件中。 代碼很簡單。
成功和錯誤的函數。
<script>
function swalsuccess() {
Swal.fire({
title: '¡Hecho!',
text: 'El script se ha ejecutado 👍',
icon: 'success',
confirmButtonText: 'Continuar'
})
}
</script>
<script>
function swalerror() {
Swal.fire({
title: 'Error!',
text: 'El script no ha podido ejecutarse.',
icon: 'error',
confirmButtonText: 'Entendido'
})
}
</script>
還有一個執行onclick函數的按鈕,帶有“withsuccesshandler”和“withfailurehandler”來顯示腳本是否已應用於Google Sheet文檔。
<button class="button-68" role="button" onclick="morphf354()">Eliminar filas (Max.k)</button>
<script>
function morphf354() {
google.script.run
.withSuccessHandler(swalsuccess)
.withFailureHandler(swalerror)
.deleteRows();
}
</script>
好吧,腳本需要幾秒鍾來實現該功能,所以我想添加一個加載 swal 屏幕,完成后更改為 swalsuccess。 我不知道如何實現它,也不知道如何將我的代碼與我在互聯網上閱讀的解決方案相匹配。
謝謝
設置觸發Swal
的 timerinterval
function swalsuccess() {
let timerInterval
Swal.fire({
title: '¡Hecho!',
text: 'El script se ha ejecutado 👍',
icon: 'success',
confirmButtonText: 'Continuar'
timer: 4000,
timerProgressBar: true,
didOpen: () => {
Swal.showLoading()
timerInterval = setInterval(() => {
const content = Swal.getHtmlContainer()
if (content) {
const b = content.querySelector('b')
if (b) {
b.textContent = Swal.getTimerLeft()
}
}
}, 100)
},
willClose: () => {
clearInterval(timerInterval)
}
}).then((result) => {
if (result.dismiss === Swal.DismissReason.timer) {
}
})
google.script.run
之前觸發加載程序對話框function swalsuccess() {
Swal.close()
Swal.fire({
title: '¡Hecho!',
text: 'El script se ha ejecutado 👍',
icon: 'success',
confirmButtonText: 'Continuar'
})
}
function morphf354() {
Swal.fire({
titleText: "Checking data...",
allowOutsideClick: false,
preConfirm: Swal.showLoading,
showLoaderOnConfirm: true,
})
google.script.run
.withSuccessHandler(swalsuccess)
.withFailureHandler(swalerror)
.deleteRows();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.