diff --git a/usertool.js b/usertool.js index 8c3aeaa..c695148 100644 --- a/usertool.js +++ b/usertool.js @@ -47,7 +47,7 @@ export default { localizeText (i18nText) { i18nText = i18nText?.__page__ - ? this.i18nText // 如果挂载到具体页面的 computed { lote: wo.localizeText } 那么 i18nText 会被自动赋值为 this 就是当前页面,直接取用 this.i18nText 即可。 + ? this.i18nText // 如果挂载到具体页面的 computed { lote: wo.localizeText } 那么 this 就是当前页面,直接取用 this.i18nText 即可。 : i18nText || this.thisPage()?.i18nText // 如果传入i18n参数 ({zhCN:'...', enUS:'...'}) // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就报错了。因此通过 thisPage().i18nText 访问。 const mylang = getApp().$store.state.i18n.mylang // this.thisPage() 有可能为空(例如在 topWindow 里,或者在 App.vue 里),所以用 getApp().$store 更安全 return i18nText?.[mylang] || (typeof i18nText === 'string' ? i18nText : '') // 必须检测是否string,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错 @@ -453,14 +453,9 @@ export default { }) */ showToast ({ tool, type, image, title, duration = 2000, ...rest }) { - const pageNow = this.thisPage() - const toast = pageNow?.$refs?.toast || getApp().globalData.toast || wo.toast - const popupMessage = pageNow?.$refs?.popupMessage || getApp().globalData.popupMessage || wo.popupMessage + const toast = this.thisPage()?.$refs?.toast || getApp().globalData.toast || wo.toast if (tool!=='uni' && toast) { // 来自 toast.show({ type, title, duration, ...rest }) - } else if (tool!=='uni' && popupMessage) { // 来自 - popupMessage.popmsg = title - popupMessage.open() } else { // #ifdef APP-PLUS uni.showToast({ icon: 'none', title, duration, ...rest })