From 6c3819c544b662fb045d361a7a1231dd799d6d14 Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Wed, 24 Jun 2020 12:19:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A9=20showToast=20=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=20complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 25 ++++++++++++------------- ucToast/ucToast.vue | 7 +++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 81e6801..c73713b 100644 --- a/index.js +++ b/index.js @@ -78,22 +78,21 @@ module.exports = { } }, - showToast({type, icon, image, title, duration}){ - let pageNow = getCurrentPages().pop() - if (pageNow.$refs && pageNow.$refs.toast) { - pageNow.$refs.toast.open({type, content:title, duration}) + showToast({type, icon, image, title, duration, ...rest}){ + let pageNow = this.$store ? this : getCurrentPages().pop() + if (pageNow.$refs && pageNow.$refs.toast) { // 在 ios app 里,虽然能获得 pageNow,但是不存在 pageNow.$refs,不知为何。android app 没有测试 + pageNow.$refs.toast.open({type, content:title, duration, ...rest}) }else { - // #ifndef APP-PLUS + // #ifdef APP-PLUS + if (uni.getSystemInfoSync().platform==='android') { + uni.showToast({icon:'none', title, duration, ...rest}) + return + } + // #endif if (!image){ image = `../static/Common.${type?type:'info'}.png` } - uni.showToast({icon, image, title, duration}) - // #endif - // #ifdef APP-PLUS - if (uni.getSystemInfoSync().platform==='android') { - uni.showToast({icon:'none', title, duration}) - } - // #endif + uni.showToast({icon, image, title, duration, ...rest}) } }, @@ -116,7 +115,7 @@ module.exports = { }, formatPercent(value, decimal){ - return `${Number(value*100).toFixed(decimal||2)}%` + return `${Number(value*100).toFixed(decimal||2)}` }, formatDate(date, format){ diff --git a/ucToast/ucToast.vue b/ucToast/ucToast.vue index 2d76ec8..2ba54c6 100644 --- a/ucToast/ucToast.vue +++ b/ucToast/ucToast.vue @@ -47,7 +47,7 @@ based on this.popup_list.push(toast) if(!toast.clickable){ - this.disappear(toast.uuid,toast.duration) + this.disappear(toast.uuid,toast.duration,toast.complete) }//可点击消失 else{ this.$emit('uuidCallback',toast.uuid) @@ -55,7 +55,7 @@ based on }, //自动消失 - disappear:function(uuid,duration){ + disappear:function(uuid,duration,complete){ //退出动画之后,短暂延迟后移除本元素 this.fade_out_animator(uuid,duration).then(res=>{ setTimeout(()=>{ @@ -66,6 +66,9 @@ based on this.$forceUpdate() } } + if (typeof(complete)==='function'){ + complete() + } },250) }) },