fg-tabbar.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <wd-tabbar
  3. fixed
  4. v-model="tabbarStore.curIdx"
  5. bordered
  6. safeAreaInsetBottom
  7. placeholder
  8. @change="selectTabBar"
  9. >
  10. <block v-for="(item, idx) in tabbarList" :key="item.path">
  11. <wd-tabbar-item
  12. v-if="item.iconType === 'wot'"
  13. :title="item.text"
  14. :icon="item.icon"
  15. ></wd-tabbar-item>
  16. <wd-tabbar-item v-else-if="item.iconType === 'unocss'" :title="item.text">
  17. <template #icon>
  18. <view
  19. h-40rpx
  20. w-40rpx
  21. :class="[item.icon, idx === tabbarStore.curIdx ? 'is-active' : 'is-inactive']"
  22. ></view>
  23. </template>
  24. </wd-tabbar-item>
  25. <wd-tabbar-item v-else-if="item.iconType === 'local'" :title="item.text">
  26. <template #icon>
  27. <image :src="item.icon" h-40rpx w-40rpx />
  28. </template>
  29. </wd-tabbar-item>
  30. </block>
  31. </wd-tabbar>
  32. </template>
  33. <script setup lang="ts">
  34. // unocss icon 默认不生效,需要在这里写一遍才能生效!注释掉也是生效的,但是必须要有!
  35. // i-carbon-3d-mpr-toggle
  36. import { tabBar } from '@/pages.json'
  37. import { tabbarStore } from './tabbar'
  38. /** tabbarList 里面的 path 必须和 pages.config.ts 的页面路径一致 */
  39. const tabbarList = tabBar.list.map((item) => ({ ...item, path: `/${item.pagePath}` }))
  40. function selectTabBar({ value: index }: { value: number }) {
  41. const url = tabbarList[index].path
  42. tabbarStore.setCurIdx(index)
  43. uni.switchTab({ url })
  44. }
  45. onLoad(() => {
  46. // 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题
  47. // #ifdef APP-PLUS | H5
  48. uni.hideTabBar({
  49. fail(err) {
  50. console.log('hideTabBar fail: ', err)
  51. },
  52. success(res) {
  53. console.log('hideTabBar success: ', res)
  54. },
  55. })
  56. // #endif
  57. })
  58. </script>