From 2a85c906ddfa152d5a5646589d73ba96291066cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TOP=E7=B3=AF=E7=B1=B3?= <1130395124@qq.com> Date: Wed, 8 Mar 2023 14:55:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96utils=E7=9A=84toast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/libs/utils.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/libs/utils.js b/src/core/libs/utils.js index 01c4aed..edeceba 100644 --- a/src/core/libs/utils.js +++ b/src/core/libs/utils.js @@ -187,11 +187,24 @@ function toPage(url, options, type) { } } +let toastTimer; function toast(title, options) { - uni.showToast({ - ...{ title: title, icon: "none" }, - ...options - }); + if (typeof options === "undefined") { + options = {}; + } + return new Promise((resolve, reject) => { + if (!options.duration) { + options.duration = 1500; + } + uni.showToast({ + ...{ title: title, icon: "none" }, + ...options + }); + clearTimeout(toastTimer); + toastTimer = setTimeout(() => { + resolve(); + }, options.duration); + }) } function formatNumber(num, limit) {