tabbar.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="tab-bar">
  3. <view class="content">
  4. <view
  5. class="one-tab"
  6. v-for="(item, index) in tabBarList"
  7. :key="index"
  8. @click="selectTabBar(index)"
  9. >
  10. <view>
  11. <view class="tab-img">
  12. <image v-if="tabIndex === index" class="img" :src="item.selectedIconPath"></image>
  13. <image v-else class="img" :src="item.iconPath"></image>
  14. </view>
  15. </view>
  16. <view v-if="tabIndex === index" class="tit select-texts">{{ item.text }}</view>
  17. <view v-else class="tit texts">{{ item.text }}</view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script setup lang="ts">
  23. import { useTabbarStore } from '@/store/tabbar'
  24. import { storeToRefs } from 'pinia'
  25. const tabbar = useTabbarStore()
  26. const { tabBarList, tabIndex } = storeToRefs(tabbar)
  27. const { setTabIndex } = tabbar
  28. function selectTabBar(index: number) {
  29. setTabIndex(index)
  30. uni.switchTab({ url: tabBarList.value[index].pagePath })
  31. }
  32. </script>
  33. <style lang="scss">
  34. .tab-bar {
  35. position: fixed;
  36. bottom: 0;
  37. left: 0;
  38. width: 100vw;
  39. padding-top: 10rpx;
  40. padding-bottom: calc(10rpx + constant(safe-area-inset-bottom));
  41. padding-bottom: calc(10rpx + env(safe-area-inset-bottom));
  42. background-color: #f8f8f8;
  43. .content {
  44. display: flex;
  45. .one-tab {
  46. display: flex;
  47. flex-direction: column;
  48. align-items: center;
  49. width: 50%;
  50. .tab-img {
  51. width: 50rpx;
  52. height: 50rpx;
  53. .img {
  54. width: 100%;
  55. height: 100%;
  56. }
  57. }
  58. .tit {
  59. font-size: 30rpx;
  60. transform: scale(0.7);
  61. }
  62. .select-texts {
  63. color: #018d71;
  64. }
  65. .texts {
  66. color: block;
  67. }
  68. }
  69. }
  70. }
  71. </style>