bugfix: langNow() --> my.langNow()
This commit is contained in:
parent
c4d6b8ee79
commit
6bf2b39983
16
unitool.js
16
unitool.js
@ -2,10 +2,11 @@
|
||||
|
||||
import './ican-H5Api.js' // 对齐H5Api: https://ext.dcloud.net.cn/plugin?id=415 // 注意要取消默认自带的 showToast https://uniapp.dcloud.io/api/system/clipboard?id=%e6%b3%a8%e6%84%8f
|
||||
const BASE_TYPE_DEFAULT = 'SERVER' // one of { SERVER: 服务器, UNICLOUD_FUNC: 云函数, UNICLOUD_OBJECT: 云对象 }
|
||||
|
||||
function langNow () {
|
||||
// getCurrentPages() 在 topWindow/App.vue 里有可能为空,所以用 getApp().$store 更安全. 20230513: 发现在微信小程序模拟器里,getApp().$store.state 未定义,所以还是用 wo.ss
|
||||
return wo?.ss?.i18n?.mylang || getApp()?.$store?.state?.i18n?.mylang
|
||||
const my = {
|
||||
langNow () {
|
||||
// getCurrentPages() 在 topWindow/App.vue 里有可能为空,所以用 getApp().$store 更安全. 20230513: 发现在微信小程序模拟器里,getApp().$store.state 未定义,所以还是用 wo.ss
|
||||
return wo?.ss?.i18n?.mylang || getApp()?.$store?.state?.i18n?.mylang
|
||||
},
|
||||
}
|
||||
|
||||
export default {
|
||||
@ -44,16 +45,16 @@ export default {
|
||||
i18nText || // 如果传入i18n参数 ({zhCN:'...', enUS:'...'})
|
||||
this.i18nText || // 1) 如果挂载到具体页面的 computed { lote: wo.localizeText } 那么 this 就是当前页面,直接取用 this.i18nText 即可。2) 对于组件内定义的 i18nText,要使用 this 来获得组件内的 i18nText
|
||||
getCurrentPages()?.pop()?.i18nText // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就不存在了。因此通过 pageNow.i18nText 访问。
|
||||
return i18nText?.[langNow()] || (typeof i18nText === 'string' ? i18nText : '') // 必须检测是否string,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
||||
return i18nText?.[my.langNow()] || (typeof i18nText === 'string' ? i18nText : '') // 必须检测是否string,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
||||
},
|
||||
|
||||
localeText () {
|
||||
// 专供绑定到 computed { lote: wo.localeText } 使用,这时 this 就是当前页面。
|
||||
return this.i18nText?.[langNow()] || {}
|
||||
return this.i18nText?.[my.langNow()] || {}
|
||||
},
|
||||
|
||||
setBarTitles ({ windowTitle, pageTitle, pagesJson = this.pagesJson || wo?.pagesJson, envar = this.envar || wo?.envar } = {}) {
|
||||
const langNow = langNow()
|
||||
const langNow = my.langNow()
|
||||
const pageNow = getCurrentPages()?.pop?.() // 需要兼顾在 App.vue 时无法获取当前页面的情况,因为如果在 topWindow 里调用本函数,getApp() 和 getCurrentPages() 就是 undefined。
|
||||
|
||||
const navibarTitle =
|
||||
@ -63,6 +64,7 @@ export default {
|
||||
pageNow?.pageTitle ||
|
||||
pagesJson?.pages?.find((page) => page.path === pageNow?.route)?.i18nPageTitle?.[langNow] || // pages.json 的页面配置里
|
||||
''
|
||||
// 在app里,pageNow.route 是正确的,但是 pageNow.i18nPageTitle 未定义,不知为何
|
||||
|
||||
windowTitle =
|
||||
windowTitle || wo?.envar?.callname?.[langNow] || pagesJson?.appInfo?.i18nText?.[langNow] || pagesJson?.globalStyle?.navigationBarTitleText || ''
|
||||
|
Loading…
Reference in New Issue
Block a user