index.vue 2.3 KB

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