让 localizeText 能够完全替代 localeText
This commit is contained in:
parent
7c1151a987
commit
98b3ef9d96
19
usertool.js
19
usertool.js
@ -57,24 +57,19 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
localizeText(i18nText) {
|
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 更安全
|
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 访问。
|
return i18nText?.[mylang] || i18nText || ''
|
||||||
if (i18nText && typeof (i18nText) === 'object' && mylang) {
|
|
||||||
return i18nText[mylang] || ''
|
|
||||||
}
|
|
||||||
if (typeof i18nText === 'string') {
|
|
||||||
return i18nText
|
|
||||||
}
|
|
||||||
return ''
|
|
||||||
},
|
},
|
||||||
|
|
||||||
localeText() {
|
localeText() { // 专供绑定到 computed { lote: wo.localeText } 使用,这时 this 就是当前页面。
|
||||||
return this.thisPage().pageNow?.i18nText?.[getApp().$store.state.i18n.mylang] || {}
|
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 mylang = getApp().$store.state.i18n.mylang
|
||||||
const pagesJson = getApp().wo.pagesJson
|
|
||||||
const pageNow = getCurrentPages()[getCurrentPages().length - 1]
|
const pageNow = getCurrentPages()[getCurrentPages().length - 1]
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
|
Loading…
Reference in New Issue
Block a user