fg-tabbar.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <script setup lang="ts">
  2. import { tabbarStore } from './tabbar'
  3. // 'i-carbon-code',
  4. import { tabbarList as _tabBarList, CUSTOM_TABBAR_ENABLE, CUSTOM_TABBAR_NO_CACHE } from './tabbarList'
  5. const tabbarList = _tabBarList.map(item => ({ ...item, path: `/${item.pagePath}` }))
  6. function selectTabBar({ value: index }: { value: number }) {
  7. const url = tabbarList[index].path
  8. tabbarStore.setCurIdx(index)
  9. if (CUSTOM_TABBAR_NO_CACHE) {
  10. uni.navigateTo({ url })
  11. }
  12. else {
  13. uni.switchTab({ url })
  14. }
  15. }
  16. onLoad(() => {
  17. // 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
  18. CUSTOM_TABBAR_ENABLE
  19. && uni.hideTabBar({
  20. fail(err) {
  21. console.log('hideTabBar fail: ', err)
  22. },
  23. success(res) {
  24. console.log('hideTabBar success: ', res)
  25. },
  26. })
  27. })
  28. </script>
  29. <template>
  30. <wd-tabbar
  31. v-if="CUSTOM_TABBAR_ENABLE"
  32. v-model="tabbarStore.curIdx"
  33. custom-class="bg-white/60! backdrop-blur-20" :bordered="false"
  34. safe-area-inset-bottom placeholder fixed
  35. @change="selectTabBar"
  36. >
  37. <block v-for="(item, idx) in tabbarList" :key="item.path">
  38. <wd-tabbar-item :icon="idx === tabbarStore.curIdx ? item.selectedIconPath : item.iconPath" />
  39. </block>
  40. </wd-tabbar>
  41. </template>