TabBar.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="placeholder safe-area" v-if="placeholder && fixed"></view>
  3. <view class="tab-bar-wrap safe-area" :style="[getTabBarWrapStyle]">
  4. <view class="tab-bar">
  5. <!-- 左侧:首页 -->
  6. <view class="menu" @click="go(menus[0].link)">
  7. <image v-if="getPath === menus[0].link" :src="getFileUrl(menus[0].img)" mode="aspectFill"></image>
  8. <image v-else :src="getFileUrl(menus[0].imgon)" mode="aspectFill"></image>
  9. <view class="text" :class="{ sele: getPath === menus[0].link }">{{ menus[0].title }}</view>
  10. </view>
  11. <!-- 中间:扫码点餐 - 特殊圆形按钮 -->
  12. <view class="menu-center" @click="go(menus[1].link)">
  13. <view class="scan-btn">
  14. <image :src="getFileUrl(menus[1].img)" mode="aspectFill"></image>
  15. </view>
  16. <image :src="getFileUrl(menus[1].imgon)" mode="heightFix" class="qrT-img"></image>
  17. </view>
  18. <!-- 右侧:我的 -->
  19. <view class="menu" @click="go(menus[2].link)">
  20. <image v-if="getPath === menus[2].link" :src="getFileUrl(menus[2].img)" mode="aspectFill"></image>
  21. <image v-else :src="getFileUrl(menus[2].imgon)" mode="aspectFill"></image>
  22. <view class="text" :class="{ sele: getPath === menus[2].link }">{{ menus[2].title }}</view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup>
  28. import { computed, unref } from 'vue';
  29. import { getFileUrl } from '@/utils/file.js';
  30. const menus = [
  31. { title: '首页', link: '/pages/index/index', img: 'img/tabbar/index1.png', imgon: 'img/tabbar/index2.png' },
  32. { title: '扫码点餐', link: '/pages/numberOfDiners/index', img: 'img/tabbar/qr2.png', imgon: 'img/tabbar/qr.png' },
  33. { title: '我的', link: '/pages/personal/index', img: 'img/tabbar/personal1.png', imgon: 'img/tabbar/personal2.png' }
  34. ];
  35. const props = defineProps({
  36. placeholder: { type: Boolean, default: false }, // 是否显示占位
  37. fixed: { type: Boolean, default: true } // 是否定位
  38. });
  39. const getTabBarWrapStyle = computed(() => ({
  40. position: props.fixed ? 'fixed' : 'relative'
  41. }));
  42. // 底部 tabBar 跳转(需在 pages.json 中配置 tabBar.list)
  43. function go(url) {
  44. if (url === unref(getPath)) return;
  45. uni.switchTab({ url });
  46. }
  47. const getPath = computed(() => {
  48. const pages = getCurrentPages(); // 获取路由栈
  49. console.log('/' + pages[pages.length - 1].route);
  50. return '/' + pages[pages.length - 1].route;
  51. });
  52. </script>
  53. <style lang="scss" scoped>
  54. .placeholder {
  55. height: 140rpx;
  56. box-sizing: content-box;
  57. }
  58. .tab-bar-wrap {
  59. position: fixed;
  60. left: 0;
  61. right: 0;
  62. bottom: 0;
  63. z-index: 99;
  64. background-color: #ffffff;
  65. box-shadow: 0 -2rpx 16rpx 0 rgba(0, 0, 0, 0.08);
  66. .tab-bar {
  67. // padding: 16rpx 0;
  68. // padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
  69. display: flex;
  70. align-items: flex-end;
  71. justify-content: space-around;
  72. position: relative;
  73. padding-top: 20rpx;
  74. .menu {
  75. display: flex;
  76. flex-direction: column;
  77. align-items: center;
  78. justify-content: center;
  79. flex: 1;
  80. padding: 0 40rpx;
  81. padding-bottom: 0;
  82. transition: all 0.3s ease;
  83. image {
  84. width: 48rpx;
  85. height: 48rpx;
  86. transition: transform 0.3s ease;
  87. }
  88. .text {
  89. font-size: 22rpx;
  90. color: #999999;
  91. margin-top: 8rpx;
  92. transition: all 0.3s ease;
  93. font-weight: 400;
  94. }
  95. .text.sele {
  96. color: #333333;
  97. font-weight: 500;
  98. }
  99. &:active {
  100. opacity: 0.7;
  101. transform: scale(0.95);
  102. }
  103. }
  104. .menu-center {
  105. display: flex;
  106. flex-direction: column;
  107. align-items: center;
  108. justify-content: center;
  109. position: absolute;
  110. bottom: -20rpx;
  111. margin: 0 40rpx;
  112. // transform: translateY(-35rpx);
  113. transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  114. background-color: #fff;
  115. border-radius: 50%;
  116. padding: 20rpx;
  117. .scan-btn {
  118. width: 110rpx;
  119. height: 110rpx;
  120. border-radius: 50%;
  121. display: flex;
  122. align-items: center;
  123. justify-content: center;
  124. margin-bottom: 6rpx;
  125. position: relative;
  126. transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  127. background: linear-gradient(35deg, #FCB73F 0%, #FC733D 100%);
  128. box-shadow: 0rpx 0rpx 11rpx 0rpx rgba(0, 0, 0, 0.16);
  129. image {
  130. width: 42rpx;
  131. height: 42rpx;
  132. filter: brightness(0) invert(1);
  133. transition: transform 0.3s ease;
  134. margin-bottom: 20rpx;
  135. }
  136. }
  137. .qrT-img {
  138. width: 85rpx;
  139. height: 22rpx;
  140. position: absolute;
  141. bottom: 36rpx;
  142. left: 50%;
  143. transform: translateX(-50%);
  144. }
  145. .text-center {
  146. font-size: 22rpx;
  147. color: #ff8844;
  148. margin-top: 4rpx;
  149. font-weight: 500;
  150. transition: all 0.3s ease;
  151. }
  152. &:active {
  153. transform: translateY(-35rpx) scale(0.92);
  154. .scan-btn {
  155. box-shadow: 0 4rpx 16rpx 0 rgba(255, 136, 68, 0.3),
  156. 0 1rpx 4rpx 0 rgba(255, 136, 68, 0.15);
  157. image {
  158. transform: scale(0.9);
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. </style>