index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view class="custom-tabbar">
  3. <view
  4. v-for="(item, index) in tabList"
  5. :key="index"
  6. class="tab-item"
  7. :class="{ active: currentTab === item.name }"
  8. @click="handleTabClick(item)"
  9. >
  10. <image
  11. class="tab-icon"
  12. :src="currentTab === item.name ? item.activeIcon : item.icon"
  13. mode="aspectFit"
  14. />
  15. <text class="tab-text">{{ item.label }}</text>
  16. </view>
  17. </view>
  18. </template>
  19. <script setup>
  20. import { computed } from 'vue'
  21. import { useI18n } from 'vue-i18n'
  22. const { t } = useI18n()
  23. // 定义props
  24. const props = defineProps({
  25. currentTab: {
  26. type: String,
  27. default: 'home'
  28. }
  29. })
  30. // 底部导航配置
  31. const tabList = computed(() => [
  32. {
  33. name: 'home',
  34. label: t('common.page.home'),
  35. icon: '/static/pages/tabbar/home.png',
  36. activeIcon: '/static/pages/tabbar/home-active.png',
  37. url: '/pages/home/index'
  38. },
  39. {
  40. name: 'scan',
  41. label: t('common.page.scan'),
  42. icon: '/static/pages/tabbar/scan.png',
  43. activeIcon: '/static/pages/tabbar/scan-active.png',
  44. url: '/pages/scan/index'
  45. },
  46. {
  47. name: 'mine',
  48. label: t('common.page.mine'),
  49. icon: '/static/pages/tabbar/mine.png',
  50. activeIcon: '/static/pages/tabbar/mine-active.png',
  51. url: '/pages/my/index'
  52. }
  53. ])
  54. // 处理tab点击
  55. const handleTabClick = (item) => {
  56. if (props.currentTab === item.name) return
  57. // 使用reLaunch跳转,清空页面栈
  58. uni.reLaunch({
  59. url: item.url
  60. })
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .custom-tabbar {
  65. position: fixed;
  66. bottom: 0;
  67. left: 0;
  68. right: 0;
  69. height: 100rpx;
  70. background-color: #ffffff;
  71. display: flex;
  72. border-top: 1rpx solid #e5e5e5;
  73. padding-bottom: env(safe-area-inset-bottom);
  74. z-index: 1000;
  75. .tab-item {
  76. flex: 1;
  77. display: flex;
  78. flex-direction: column;
  79. align-items: center;
  80. justify-content: center;
  81. padding: 8rpx 0;
  82. transition: all 0.3s ease;
  83. .tab-icon {
  84. width: 48rpx;
  85. height: 48rpx;
  86. margin-bottom: 4rpx;
  87. transition: transform 0.3s ease;
  88. }
  89. .tab-text {
  90. font-size: 20rpx;
  91. color: #666666;
  92. transition: color 0.3s ease;
  93. }
  94. &.active {
  95. .tab-icon {
  96. transform: scale(1.1);
  97. }
  98. .tab-text {
  99. color: #1ec9c9;
  100. font-weight: 500;
  101. }
  102. }
  103. &:active {
  104. opacity: 0.8;
  105. }
  106. }
  107. }
  108. </style>