改进 showToast,调用getCurrentPages()获取当前页面,使得不需要 call(this, ...)

This commit is contained in:
陆柯 2020-05-24 09:18:03 +08:00
parent ad75cd1aee
commit 76a58883be
2 changed files with 21 additions and 18 deletions

View File

@ -1,17 +0,0 @@
module.exports = function showToast({type, icon, image, title, duration}){
if (this.$refs && this.$refs.toast) {
this.$refs.toast.open({type, content:title, duration})
}else {
// #ifndef APP-PLUS
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
}
}

View File

@ -73,4 +73,24 @@ module.exports = {
}
},
showToast({type, icon, image, title, duration}){
let pageStack = getCurrentPages()
let pageNow = pageStack[pageStack.length-1]
if (pageNow.$refs && pageNow.$refs.toast) {
pageNow.$refs.toast.open({type, content:title, duration})
}else {
// #ifndef APP-PLUS
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
}
},
}