TabBar.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. function go(url) {
  43. if (url === unref(getPath)) return;
  44. uni.reLaunch({ url });
  45. }
  46. const getPath = computed(() => {
  47. const pages = getCurrentPages(); // 获取路由栈
  48. console.log('/' + pages[pages.length - 1].route);
  49. return '/' + pages[pages.length - 1].route;
  50. });
  51. </script>
  52. <style lang="scss" scoped>
  53. .placeholder {
  54. height: 140rpx;
  55. box-sizing: content-box;
  56. }
  57. .tab-bar-wrap {
  58. position: fixed;
  59. left: 0;
  60. right: 0;
  61. bottom: 0;
  62. z-index: 99;
  63. background-color: #ffffff;
  64. box-shadow: 0 -2rpx 16rpx 0 rgba(0, 0, 0, 0.08);
  65. .tab-bar {
  66. // padding: 16rpx 0;
  67. // padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
  68. display: flex;
  69. align-items: flex-end;
  70. justify-content: space-around;
  71. position: relative;
  72. padding-top: 20rpx;
  73. .menu {
  74. display: flex;
  75. flex-direction: column;
  76. align-items: center;
  77. justify-content: center;
  78. flex: 1;
  79. padding: 0 40rpx;
  80. padding-bottom: 0;
  81. transition: all 0.3s ease;
  82. image {
  83. width: 48rpx;
  84. height: 48rpx;
  85. transition: transform 0.3s ease;
  86. }
  87. .text {
  88. font-size: 22rpx;
  89. color: #999999;
  90. margin-top: 8rpx;
  91. transition: all 0.3s ease;
  92. font-weight: 400;
  93. }
  94. .text.sele {
  95. color: #333333;
  96. font-weight: 500;
  97. }
  98. &:active {
  99. opacity: 0.7;
  100. transform: scale(0.95);
  101. }
  102. }
  103. .menu-center {
  104. display: flex;
  105. flex-direction: column;
  106. align-items: center;
  107. justify-content: center;
  108. position: absolute;
  109. bottom: -20rpx;
  110. margin: 0 40rpx;
  111. // transform: translateY(-35rpx);
  112. transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  113. background-color: #fff;
  114. border-radius: 50%;
  115. padding: 20rpx;
  116. .scan-btn {
  117. width: 110rpx;
  118. height: 110rpx;
  119. border-radius: 50%;
  120. display: flex;
  121. align-items: center;
  122. justify-content: center;
  123. margin-bottom: 6rpx;
  124. position: relative;
  125. transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  126. background: linear-gradient(35deg, #FCB73F 0%, #FC733D 100%);
  127. box-shadow: 0rpx 0rpx 11rpx 0rpx rgba(0, 0, 0, 0.16);
  128. image {
  129. width: 42rpx;
  130. height: 42rpx;
  131. filter: brightness(0) invert(1);
  132. transition: transform 0.3s ease;
  133. margin-bottom: 20rpx;
  134. }
  135. }
  136. .qrT-img {
  137. width: 85rpx;
  138. height: 22rpx;
  139. position: absolute;
  140. bottom: 36rpx;
  141. left: 50%;
  142. transform: translateX(-50%);
  143. }
  144. .text-center {
  145. font-size: 22rpx;
  146. color: #ff8844;
  147. margin-top: 4rpx;
  148. font-weight: 500;
  149. transition: all 0.3s ease;
  150. }
  151. &:active {
  152. transform: translateY(-35rpx) scale(0.92);
  153. .scan-btn {
  154. box-shadow: 0 4rpx 16rpx 0 rgba(255, 136, 68, 0.3),
  155. 0 1rpx 4rpx 0 rgba(255, 136, 68, 0.15);
  156. image {
  157. transform: scale(0.9);
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. </style>