fg-tabbar.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <script setup lang="ts">
  2. import { tabbarStore } from './tabbar'
  3. // 'i-carbon-code',
  4. import { tabbarList as _tabBarList, cacheTabbarEnable, selectedTabbarStrategy } from './tabbarList'
  5. // @ts-expect-error 预知的判断
  6. const customTabbarEnable = selectedTabbarStrategy === 2 || selectedTabbarStrategy === 3
  7. /** tabbarList 里面的 path 从 pages.config.ts 得到 */
  8. const tabbarList = _tabBarList.map(item => ({ ...item, path: `/${item.pagePath}` }))
  9. function selectTabBar({ value: index }: { value: number }) {
  10. const url = tabbarList[index].path
  11. tabbarStore.setCurIdx(index)
  12. if (cacheTabbarEnable) {
  13. uni.switchTab({ url })
  14. }
  15. else {
  16. uni.navigateTo({ url })
  17. }
  18. }
  19. onLoad(() => {
  20. // 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
  21. // @ts-expect-error 预知的判断
  22. const hideRedundantTabbarEnable = selectedTabbarStrategy === 2
  23. hideRedundantTabbarEnable
  24. && uni.hideTabBar({
  25. fail(err) {
  26. console.log('hideTabBar fail: ', err)
  27. },
  28. success(res) {
  29. console.log('hideTabBar success: ', res)
  30. },
  31. })
  32. })
  33. </script>
  34. <template>
  35. <wd-tabbar
  36. v-if="customTabbarEnable"
  37. v-model="tabbarStore.curIdx"
  38. bordered
  39. safeareainsetbottom
  40. placeholder
  41. fixed
  42. @change="selectTabBar"
  43. >
  44. <block v-for="(item, idx) in tabbarList" :key="item.path">
  45. <wd-tabbar-item v-if="item.iconType === 'uiLib'" :title="item.text" :icon="item.icon" />
  46. <wd-tabbar-item
  47. v-else-if="item.iconType === 'unocss' || item.iconType === 'iconfont'"
  48. :title="item.text"
  49. >
  50. <template #icon>
  51. <view
  52. h-40rpx
  53. w-40rpx
  54. :class="[item.icon, idx === tabbarStore.curIdx ? 'is-active' : 'is-inactive']"
  55. />
  56. </template>
  57. </wd-tabbar-item>
  58. <wd-tabbar-item v-else-if="item.iconType === 'local'" :title="item.text">
  59. <template #icon>
  60. <image :src="item.icon" h-40rpx w-40rpx />
  61. </template>
  62. </wd-tabbar-item>
  63. </block>
  64. </wd-tabbar>
  65. </template>