diff --git a/usertool.js b/usertool.js index 3b0a234..a8e1b0c 100644 --- a/usertool.js +++ b/usertool.js @@ -57,24 +57,19 @@ export default { }, localizeText(i18nText) { + i18nText = i18nText?.constructor?.name==='VueComponent' ? this.i18nText // 如果挂载到具体页面的 computed { lote: wo.localizeText } 那么 this 就是当前页面,直接取用 this.i18nText 即可。 + : ( i18nText // 如果传入i18n参数 ({zhCN:'...', enUS:'...'}) + || this.thisPage()?.i18nText) // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就报错了。因此通过 thisPage().i18nText 访问。 const mylang = getApp().$store.state.i18n.mylang // this.thisPage() 有可能为空(例如在 topWindow 里,或者在 App.vue 里),所以用 getApp().$store 更安全 - i18nText = i18nText || this.thisPage()?.i18nText // 如果本方法直接挂载到 Vue.prototype 下,那么可以直接访问 this.i18nText。但如果挂载到 wo 下,那么 this.i18nText 就报错了。因此安全起见,通过 pageNow.i18nText 访问。 - if (i18nText && typeof (i18nText) === 'object' && mylang) { - return i18nText[mylang] || '' - } - if (typeof i18nText === 'string') { - return i18nText - } - return '' + return i18nText?.[mylang] || i18nText || '' }, - localeText() { - return this.thisPage().pageNow?.i18nText?.[getApp().$store.state.i18n.mylang] || {} + localeText() { // 专供绑定到 computed { lote: wo.localeText } 使用,这时 this 就是当前页面。 + return this.i18nText?.[getApp().$store.state.i18n.mylang] || {} }, - setBarTitles ({ windowTitle, pageTitle } = {}) { + setBarTitles ({ windowTitle, pageTitle, pagesJson=wo?.pagesJson } = {}) { const mylang = getApp().$store.state.i18n.mylang - const pagesJson = getApp().wo.pagesJson const pageNow = getCurrentPages()[getCurrentPages().length - 1] // #ifdef H5