| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { ensureTabBarEntry, isTabBarPage, syncTabBarText } from '@/utils/tabBar'
- /**
- * Tab 子页共用:根节点语言 class、导航标题、底部 tab 文案与 i18n 同步
- * 页面需在 data 中提供 navTitleKey,如 'nav.home'
- */
- export default {
- data() {
- return {
- layoutKey: 0
- }
- },
- computed: {
- lang() {
- return this.$i18n.locale
- },
- pageRootClass() {
- return this.lang === 'bo' ? 'lang-bo' : 'lang-zh'
- }
- },
- onShow() {
- const applyTabPageUi = () => {
- if (!isTabBarPage()) {
- return
- }
- syncTabBarText((k) => this.$t(k))
- const key = this.navTitleKey
- if (key) {
- const p = uni.setNavigationBarTitle({
- title: this.$t(key)
- })
- if (p && typeof p.catch === 'function') {
- p.catch(() => {})
- }
- }
- }
- if (isTabBarPage()) {
- applyTabPageUi()
- return
- }
- ensureTabBarEntry().then((ok) => {
- if (ok) {
- applyTabPageUi()
- }
- })
- }
- }
|