custom-tabbar.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="custom_tabbar">
  3. <view class="side_help">
  4. <view class="help" @click="navTo('help')">
  5. <image class="w-30 h-30 mgb-6" src="/static/image/tabbar/help.png" mode="scaleToFill" />
  6. <view class="text">帮助</view>
  7. </view>
  8. <view class="mgt-20" @click="navTo('complaint')">
  9. <image class="w-30 h-30 mgb-6" src="/static/image/tabbar/complaint.png" mode="scaleToFill" />
  10. <view class="text">投诉</view>
  11. </view>
  12. </view>
  13. <view class="tools" @click="navTo('toolsMall')">
  14. <image class="w-80 h-80" src="/static/image/tabbar/tools_icon.png" mode="scaleToFill" />
  15. <view class="title">工具广场</view>
  16. </view>
  17. <view class="red_packet" @click="navTo('redPacket')">
  18. <image class="img" src="/static/image/tabbar/red_packet.png" mode="scaleToFill" />
  19. </view>
  20. <view class="custom-tabbar">
  21. <view v-for="(item, index) in list" :key="index" class="tabbar-item" @click="switchTab(index)">
  22. <view class="menu-item">
  23. <image v-if="currentIndex === index" class="w-48 h-48" :src="item.check_icon" mode="scaleToFill" />
  24. <image v-else class="w-48 h-48" :src="item.icon" mode="scaleToFill" />
  25. <text class="mgt-4" :class="{ active: currentIndex === index }">{{ item.text }}</text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script setup>
  32. import { ref } from 'vue';
  33. // 当前选中的 Tab 索引
  34. const props = defineProps(["currentIndex"])
  35. // TabBar 列表
  36. const list = ref([{
  37. text: "书架",
  38. pagePath: "/pages/index/index",
  39. icon: '/static/image/tabbar/bookshelf.png',
  40. check_icon: '/static/image/tabbar/bookshelf_on.png'
  41. },
  42. {
  43. text: "书城",
  44. pagePath: "/pages/bookMall/index",
  45. icon: '/static/image/tabbar/bookMall.png',
  46. check_icon: '/static/image/tabbar/bookMall_on.png'
  47. },
  48. {
  49. text: "我的",
  50. pagePath: "/pages/my/index",
  51. icon: '/static/image/tabbar/my.png',
  52. check_icon: '/static/image/tabbar/my_on.png'
  53. },
  54. ]);
  55. // 切换 Tab
  56. const switchTab = (index) => {
  57. uni.switchTab({
  58. url: list.value[index].pagePath,
  59. });
  60. };
  61. const navList = {
  62. help: '/pages/commonModule/help',
  63. complaint: '/pages/commonModule/complaint',
  64. redPacket: '/pages/commonModule/redPacket',
  65. toolsMall: '/pages/toolsMall/index'
  66. }
  67. const navTo = (name) => {
  68. uni.navigateTo({
  69. url: navList[name],
  70. });
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .custom_tabbar {
  75. z-index: 9999;
  76. }
  77. .side_help {
  78. position: fixed;
  79. left: 0;
  80. bottom: 20%;
  81. width: 50rpx;
  82. background-color: red;
  83. display: flex;
  84. flex-direction: column;
  85. align-items: center;
  86. justify-content: center;
  87. color: #fff;
  88. text-align: center;
  89. padding: 20rpx 0;
  90. border-radius: 0 30rpx 30rpx 0;
  91. z-index: 9999;
  92. .text {
  93. text-align: center;
  94. }
  95. }
  96. .tools {
  97. position: fixed;
  98. right: 20rpx;
  99. bottom: 33%;
  100. display: flex;
  101. flex-direction: column;
  102. align-items: center;
  103. justify-content: center;
  104. z-index: 9999;
  105. .title {
  106. margin-top: 2rpx;
  107. font-size: 20rpx;
  108. width: 100rpx;
  109. height: 30rpx;
  110. display: flex;
  111. align-items: center;
  112. justify-content: center;
  113. background: linear-gradient(to right, #c7dae2, #84c9e6);
  114. border-radius: 50rpx;
  115. color: #fff;
  116. }
  117. }
  118. .red_packet {
  119. position: fixed;
  120. right: 20rpx;
  121. bottom: 20%;
  122. z-index: 9999;
  123. .img {
  124. width: 127rpx;
  125. height: 96rpx;
  126. }
  127. }
  128. .custom-tabbar {
  129. position: fixed;
  130. left: 0;
  131. right: 0;
  132. bottom: 0;
  133. z-index: 9999;
  134. display: flex;
  135. height: 100rpx;
  136. /* 适配安全区 */
  137. padding-top: 10rpx;
  138. /* 默认 Android */
  139. padding-bottom: 10rpx;
  140. background-color: #ffffff;
  141. /* background-color: transparent; */
  142. justify-content: space-between;
  143. }
  144. /* 兼容 iOS 安全区域 */
  145. @supports (bottom: env(safe-area-inset-bottom)) {
  146. .custom-tabbar {
  147. height: calc(100rpx + env(safe-area-inset-bottom));
  148. padding-bottom: env(safe-area-inset-bottom);
  149. }
  150. }
  151. .tabbar-item {
  152. flex: 1;
  153. }
  154. .menu-item {
  155. position: relative;
  156. display: flex;
  157. flex-direction: column;
  158. align-items: center;
  159. color: #E5DCD6;
  160. font-size: 20rpx;
  161. }
  162. .add_icon {
  163. position: absolute;
  164. top: -30rpx;
  165. width: 96rpx;
  166. height: 96rpx;
  167. }
  168. .active {
  169. color: #FFA74F;
  170. }
  171. </style>