move setBarTitles
from user.i18n.uniapp/ to user.tool.uniapp
This commit is contained in:
parent
dfa1ae0179
commit
4268f629ed
34
index.js
34
index.js
@ -51,6 +51,40 @@ export default {
|
||||
return pageNow.i18nText?.[pageNow.$store.state.i18n.mylang] || {}
|
||||
},
|
||||
|
||||
setBarTitles ({ windowTitle, pageTitle } = {}) {
|
||||
const pageNow = getCurrentPages()[getCurrentPages().length - 1]
|
||||
const mylang = getApp().$store.state.i18n.mylang
|
||||
|
||||
// #ifdef H5
|
||||
document.title = windowTitle || pagesJson?.appInfo?.i18nText?.[mylang] // 必须放在 setNavigationBarTitle 之后,否则会被其覆盖掉。
|
||||
// #endif
|
||||
|
||||
uni.setNavigationBarTitle({
|
||||
title:
|
||||
pageTitle ||
|
||||
pageNow.i18nText?.[mylang]?.tPageTitle || // 页面.vue 的 i18nText 对象
|
||||
pageNow.i18nPageTitle?.[mylang] || // 页面.vue 的 i18nPageTitle 变量
|
||||
pagesJson?.pages?.find((page) => page.path === pageNow.route)?.i18nPageTitle?.[mylang], // pages.json 的页面配置里
|
||||
})
|
||||
|
||||
// 必须要在有 tab 的页面里 setTabBarItem 才有效果
|
||||
//const midIndex = parseInt(pagesJson?.tabBar?.list?.length/2) // 如果存在midButton,实际上tabBar.list.length必须为偶数。不过为了心安,再parseInt一下。
|
||||
pagesJson?.tabBar?.list?.forEach((tab, tabIndex) => {
|
||||
if (tab.i18nText && tab.i18nText[mylang]) {
|
||||
uni.setTabBarItem({
|
||||
// #ifdef H5
|
||||
index: tabIndex, // + ((pagesJson?.tabBar?.midButton?.iconPath && tabIndex >= midIndex)?1:0), // H5 里,如果使用了 midButton,tabBarItem的index出现错位,需hack调整。推测,在H5里 midButton 作为一个普通tab被插入到 tabBar 里,导致 tabBar 的 index 和 pagesJson.tabBar.list 的 index 错位了。[20211031] 注意到,从 HBuilderX 3.2.12.20211029 起,在 H5 里也没有错位了。
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
index: tabIndex,
|
||||
// #endif
|
||||
text: tab.i18nText[mylang],
|
||||
})
|
||||
}
|
||||
})
|
||||
// uni.showTabBar({})
|
||||
},
|
||||
|
||||
makeServerUrl(route = '') {
|
||||
if (typeof route !== 'string') route = '' // 防止 route 为 null, undefined 等由于后台数据库默认值而造成的异常。
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user