tabbar.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="tabbar-container">
  3. <block>
  4. <view class="tabbar-item" v-for="(item, index) in tabbarList" :key="index" :class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
  5. <view class="item-top"><image :src="currentItem == item.id ? item.selectIcon : item.icon"></image></view>
  6. <view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
  7. <text>{{ item.text }}</text>
  8. </view>
  9. </view>
  10. </block>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. props: {
  16. currentPage: {
  17. type: Number,
  18. default: 0
  19. }
  20. },
  21. data() {
  22. return {
  23. currentItem: 0,
  24. tabbarList: [
  25. {
  26. id: 0,
  27. path: '/packageShang/pages/tabbar/home',
  28. icon: '/packageShang/static/images/tabbar/home.png',
  29. selectIcon: '/packageShang/static/images/tabbar/home-active.png',
  30. text: '首页',
  31. centerItem: false
  32. },
  33. {
  34. id: 1,
  35. path: '/packageShang/pages/tabbar/category',
  36. icon: '/packageShang/static/images/tabbar/category.png',
  37. selectIcon: '/packageShang/static/images/tabbar/category-active.png',
  38. text: '分类',
  39. centerItem: true
  40. },
  41. {
  42. id: 2,
  43. path: '/packageShang/pages/tabbar/cart',
  44. icon: '/packageShang/static/images/tabbar/cart.png',
  45. selectIcon: '/packageShang/static/images/tabbar/cart-active.png',
  46. text: '购物车',
  47. centerItem: false
  48. },
  49. {
  50. id: 3,
  51. path: '/packageShang/pages/tabbar/user',
  52. icon: '/packageShang/static/images/tabbar/user.png',
  53. selectIcon: '/packageShang/static/images/tabbar/user-active.png',
  54. text: '我的',
  55. centerItem: false
  56. }
  57. ]
  58. };
  59. },
  60. mounted() {
  61. this.currentItem = this.currentPage;
  62. uni.hideTabBar();
  63. },
  64. methods: {
  65. changeItem(item) {
  66. let _this = this;
  67. //_this.currentItem = item.id;
  68. uni.redirectTo({
  69. url: item.path
  70. });
  71. }
  72. }
  73. };
  74. </script>
  75. <style>
  76. view {
  77. padding: 0;
  78. margin: 0;
  79. box-sizing: border-box;
  80. }
  81. @import url('/packageShang/components/iconfont/iconfont.css');
  82. @import url('/packageShang/common/common.scss');
  83. .tabbar-container {
  84. position: fixed;
  85. bottom: 0;
  86. left: 0;
  87. width: 100%;
  88. height: 167rpx;
  89. box-shadow: 0 0 5px #999;
  90. display: flex;
  91. align-items: center;
  92. padding: 5rpx 0;
  93. color: #999999;
  94. background-color: white;
  95. /* background-image: url('../static/images/tabbar/bgkuang.png'); */
  96. background-size: 100%;
  97. }
  98. .tabbar-container .tabbar-item {
  99. width: 33%;
  100. height: 100rpx;
  101. display: flex;
  102. flex-direction: column;
  103. justify-content: center;
  104. align-items: center;
  105. text-align: center;
  106. }
  107. .tabbar-container .item-active {
  108. color: #1E7DFB;
  109. }
  110. .tabbar-container .center-item {
  111. display: block;
  112. position: relative;
  113. }
  114. .tabbar-container .tabbar-item .item-top {
  115. width: 70rpx;
  116. height: 70rpx;
  117. padding: 10rpx;
  118. top: 24px;
  119. position: absolute;
  120. }
  121. .tabbar-container .center-item .item-top {
  122. flex-shrink: 0;
  123. width: 70rpx;
  124. height: 70rpx;
  125. position: absolute;
  126. top: 10rpx;
  127. left: calc(60% - 50rpx);
  128. border-radius: 50%;
  129. /* box-shadow: 0 0 5px #999; */
  130. /* background-color: #ffffff; */
  131. }
  132. .tabbar-container .tabbar-item .item-top image {
  133. width: 100%;
  134. height: 100%;
  135. }
  136. .tabbar-container .tabbar-item .item-bottom {
  137. font-size: 28rpx;
  138. width: 100%;
  139. top: 55px;
  140. position: absolute;
  141. }
  142. .tabbar-container .center-item .item-bottom {
  143. position: absolute;
  144. top: 37px;
  145. position: absolute;
  146. }
  147. </style>