index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="tabbar-container">
  3. <view class="tabbar-item" v-for="(item, index) in tabbarList" :key="item.id" :class="item.position" @click="changeItem(item)">
  4. <view class="item-top">
  5. <image :src="currentItem == item.id ? item.selectIcon : item.icon"></image>
  6. </view>
  7. <view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
  8. <text>{{ item.text }}</text>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: "Tabbar",
  16. props: {
  17. currentPage: {
  18. type: Number,
  19. default: 0
  20. }
  21. },
  22. data() {
  23. return {
  24. currentItem: 0,
  25. tabbarList: [{
  26. id: 0,
  27. path: '/pages/index/index',
  28. icon: "/static/tabbar/home.png",
  29. selectIcon: "/static/tabbar/home_ac.png",
  30. text: '',
  31. position: 'left'
  32. },
  33. {
  34. id: 1,
  35. path: '/pages/video/index',
  36. icon: "/static/tabbar/video.png",
  37. selectIcon: "/static/tabbar/video_ac.png",
  38. text: '',
  39. position: 'left left_last' // 左侧元素的最后一个,为了找到具体元素添加圆角
  40. },
  41. {
  42. id: 2,
  43. path: '/pages/exercise/index',
  44. icon: "",
  45. selectIcon: "",
  46. text: '答题',
  47. position: 'center'
  48. },
  49. {
  50. id: 3,
  51. path: '/pages/me/index',
  52. icon: "/static/tabbar/msg.png",
  53. selectIcon: "/static/tabbar/msg_ac.png",
  54. text: '',
  55. position: 'right'
  56. },
  57. {
  58. id: 4,
  59. path: '/pages/me/me',
  60. icon: "/static/tabbar/me.png",
  61. selectIcon: "/static/tabbar/me_ac.png",
  62. text: '',
  63. position: 'right'
  64. }
  65. ]
  66. };
  67. },
  68. mounted() {
  69. this.currentItem = this.currentPage;
  70. console.log('currentItem', this.currentItem,this.currentPage)
  71. // 非微信小程序需隐藏原生tabBar(微信小程序已通过"custom": true配置项隐藏原生tabbar)
  72. if (process.env.VUE_APP_PLATFORM != 'mp-weixin') {
  73. uni.hideTabBar()
  74. }
  75. },
  76. methods: {
  77. changeItem(item) {
  78. uni.switchTab({
  79. url: item.path
  80. });
  81. }
  82. }
  83. };
  84. </script>
  85. <style lang="scss" scoped>
  86. .tabbar-container {
  87. position: fixed;
  88. bottom: 0;
  89. left: 0;
  90. z-index: 1;
  91. width: 100%;
  92. height: 120rpx;
  93. display: flex;
  94. align-items: center;
  95. justify-content: space-around;
  96. padding: 5rpx 0;
  97. box-shadow: 0 -20rpx 40rpx 4rpx rgba(0, 0, 0, 0.1);
  98. background-color: rgba(0, 0, 0, 0.1);
  99. .tabbar-item {
  100. width: 20%;
  101. height: 120rpx;
  102. display: flex;
  103. flex-direction: column;
  104. justify-content: center;
  105. align-items: center;
  106. text-align: center;
  107. .item-top image {
  108. width: 50rpx;
  109. height: 50rpx;
  110. }
  111. .item-bottom {
  112. font-size: 28rpx;
  113. width: 100%;
  114. }
  115. }
  116. .left {
  117. flex: 1;
  118. background-color: #fff;
  119. display: flex;
  120. }
  121. .left_last {
  122. border-top-right-radius: 20rpx;
  123. }
  124. .center {
  125. width: 159rpx;
  126. background: radial-gradient(circle at 50% 0rpx, transparent 80rpx, white 0) top left 100% no-repeat;
  127. position: relative;
  128. .item-bottom {
  129. text-align: center;
  130. line-height: 130rpx;
  131. position: absolute;
  132. background: linear-gradient(45deg, #f84a1a, #ffa53e);
  133. border-radius: 50%;
  134. top: -60rpx;
  135. left: 50%;
  136. transform: translateX(-50%);
  137. width: 130rpx;
  138. height: 130rpx;
  139. color: #fff;
  140. font-size: 20px;
  141. }
  142. &+.right {
  143. border-top-left-radius: 20rpx;
  144. }
  145. }
  146. .right {
  147. flex: 1;
  148. background-color: #fff;
  149. display: flex;
  150. }
  151. }
  152. </style>