西藏巴青项目

tabPage.js 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { ensureTabBarEntry, installTabBarApiGuard, isTabBarPage, syncTabBarText } from '@/utils/tabBar'
  2. /**
  3. * Tab 子页共用:根节点语言 class、导航标题、底部 tab 文案与 i18n 同步
  4. * 页面需在 data 中提供 navTitleKey,如 'nav.home'
  5. */
  6. export default {
  7. data() {
  8. return {
  9. layoutKey: 0
  10. }
  11. },
  12. computed: {
  13. lang() {
  14. return this.$i18n.locale
  15. },
  16. pageRootClass() {
  17. return this.lang === 'bo' ? 'lang-bo' : 'lang-zh'
  18. }
  19. },
  20. onShow() {
  21. installTabBarApiGuard()
  22. const applyTabPageUi = () => {
  23. if (!isTabBarPage()) {
  24. return
  25. }
  26. syncTabBarText((k) => this.$t(k))
  27. const key = this.navTitleKey
  28. if (key) {
  29. const p = uni.setNavigationBarTitle({
  30. title: this.$t(key)
  31. })
  32. if (p && typeof p.catch === 'function') {
  33. p.catch(() => {})
  34. }
  35. }
  36. }
  37. if (isTabBarPage()) {
  38. applyTabPageUi()
  39. return
  40. }
  41. ensureTabBarEntry().then((ok) => {
  42. if (ok) {
  43. applyTabPageUi()
  44. }
  45. })
  46. }
  47. }