wangzhibo
2026-10-08 220e4fab27b7f419b3e89e2f2d28ae789aac09d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<script setup lang="ts">
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
import { onMounted, watch } from 'vue'
import { usePageAuth } from '@/hooks/usePageAuth'
import { t } from '@/i18n'
import { useConfigStore } from '@/store'
import { useLangStore } from '@/store/lang'
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
 
usePageAuth()
 
const configStore = useConfigStore()
const langStore = useLangStore()
 
onLaunch(() => {
  console.log('App Launch')
  // 获取公共配置
  configStore.fetchPublicConfig().catch((error) => {
    console.error('获取公共配置失败:', error)
  })
})
onShow(() => {
  console.log('App Show')
  // 使用setTimeout延迟执行,确保tabBar已经初始化
  setTimeout(() => {
    updateTabBarText()
  }, 100)
})
 
// 动态更新tabBar文本
function updateTabBarText() {
  try {
    // 设置首页tabBar文本
    uni.setTabBarItem({
      index: 0,
      text: t('tabBar.home'),
      success: () => {},
      fail: (err) => {
        console.log('设置首页tabBar文本失败:', err)
      },
    })
 
    // 设置配网tabBar文本
    uni.setTabBarItem({
      index: 1,
      text: t('tabBar.deviceConfig'),
      success: () => {},
      fail: (err) => {
        console.log('设置配网tabBar文本失败:', err)
      },
    })
 
    // 设置系统tabBar文本
    uni.setTabBarItem({
      index: 2,
      text: t('tabBar.settings'),
      success: () => {},
      fail: (err) => {
        console.log('设置系统tabBar文本失败:', err)
      },
    })
  }
  catch (error) {
    console.log('更新tabBar文本时出错:', error)
  }
}
// 监听语言切换事件
onMounted(() => {
  // 监听语言变化,当语言改变时自动更新tabBar文本
  watch(() => langStore.currentLang, () => {
    console.log('语言已切换,更新tabBar文本')
    // 语言切换后立即更新tabBar文本
    updateTabBarText()
  })
})
 
onHide(() => {
  console.log('App Hide')
})
</script>
 
<style lang="scss">
swiper,
scroll-view {
  flex: 1;
  height: 100%;
  overflow: hidden;
}
 
image {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}
</style>