index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view class="page-container">
  3. <!-- 主内容区 -->
  4. <view class="main-content">
  5. <!-- 首页内容 -->
  6. <HomePage v-if="currentTab === 'home'" />
  7. <!-- 扫描内容 -->
  8. <ScanPage v-else-if="currentTab === 'scan'" />
  9. <!-- 我的内容 -->
  10. <MyPage v-else-if="currentTab === 'mine'" />
  11. </view>
  12. <!-- 自定义底部导航栏 -->
  13. <view class="custom-tabbar">
  14. <view
  15. v-for="(item, index) in tabList"
  16. :key="index"
  17. class="tab-item"
  18. :class="{ active: currentTab === item.name }"
  19. @click="switchTab(item.name)"
  20. >
  21. <image
  22. class="tab-icon"
  23. :src="currentTab === item.name ? item.activeIcon : item.icon"
  24. mode="aspectFit"
  25. />
  26. <text class="tab-text">{{ item.label }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script setup>
  32. import { ref, computed } from 'vue'
  33. import { useI18n } from 'vue-i18n'
  34. import HomePage from '../pages-content/home/index.vue'
  35. import ScanPage from '../pages-content/scan/index.vue'
  36. import MyPage from '../pages-content/my/index.vue'
  37. const { t } = useI18n()
  38. // 当前激活的tab
  39. const currentTab = ref('home')
  40. // 底部导航配置
  41. const tabList = computed(() => [
  42. {
  43. name: 'home',
  44. label: t('common.page.home'),
  45. icon: '/static/tabbar/home.png',
  46. activeIcon: '/static/tabbar/home-active.png'
  47. },
  48. {
  49. name: 'scan',
  50. label: t('common.page.scan'),
  51. icon: '/static/tabbar/scan.png',
  52. activeIcon: '/static/tabbar/scan-active.png'
  53. },
  54. {
  55. name: 'mine',
  56. label: t('common.page.mine'),
  57. icon: '/static/tabbar/mine.png',
  58. activeIcon: '/static/tabbar/mine-active.png'
  59. }
  60. ])
  61. // 切换tab
  62. const switchTab = (name) => {
  63. if (currentTab.value === name) return
  64. currentTab.value = name
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. .page-container {
  69. width: 100%;
  70. height: 100vh;
  71. display: flex;
  72. flex-direction: column;
  73. background-color: #f5f5f5;
  74. }
  75. // 主内容区
  76. .main-content {
  77. flex: 1;
  78. overflow-y: auto;
  79. padding-bottom: calc(100rpx + env(safe-area-inset-bottom));
  80. }
  81. // 自定义底部导航栏
  82. .custom-tabbar {
  83. position: fixed;
  84. bottom: 0;
  85. left: 0;
  86. right: 0;
  87. height: 100rpx;
  88. background-color: #ffffff;
  89. display: flex;
  90. border-top: 1rpx solid #e5e5e5;
  91. padding-bottom: env(safe-area-inset-bottom);
  92. z-index: 1000;
  93. .tab-item {
  94. flex: 1;
  95. display: flex;
  96. flex-direction: column;
  97. align-items: center;
  98. justify-content: center;
  99. padding: 8rpx 0;
  100. transition: all 0.3s ease;
  101. .tab-icon {
  102. width: 48rpx;
  103. height: 48rpx;
  104. margin-bottom: 4rpx;
  105. transition: transform 0.3s ease;
  106. }
  107. .tab-text {
  108. font-size: 20rpx;
  109. color: #666666;
  110. transition: color 0.3s ease;
  111. }
  112. &.active {
  113. .tab-icon {
  114. transform: scale(1.1);
  115. }
  116. .tab-text {
  117. color: #007aff;
  118. font-weight: 500;
  119. }
  120. }
  121. &:active {
  122. opacity: 0.8;
  123. }
  124. }
  125. }
  126. </style>