tabbar.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view>
  3. <!-- <view>
  4. </view> -->
  5. <view class="tabbar-container" :class="isIpx?'IpxBot':''">
  6. <view class="tabbar-containers">
  7. <view class="tabbar-item" v-for="(item,index) in tabList" :class="[item.centerItem ? 'center-item' : '']"
  8. @click="changeItem(item)" :key="index">
  9. <view class="item-top">
  10. <image :src="tabId==item.id?item.selectIcon:item.icon" mode=""></image>
  11. </view>
  12. <view class="item-bottom" :class="[tabId==item.id ? 'item-active' : '']">
  13. <text>{{item.text}}</text>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. props: {
  23. currentPage: {
  24. type: Number,
  25. default: 0
  26. }
  27. },
  28. data() {
  29. return {
  30. //适配IPhoneX
  31. isIpx: false,
  32. //底部Tab
  33. tabId: 0,
  34. tabList: [{
  35. id: 0,
  36. path: "/pages/index/index",
  37. icon: "/static/table/tab1.png",
  38. selectIcon: "/static/table/tab1_pre.png",
  39. text: "首页",
  40. centerItem: false
  41. }, {
  42. id: 1,
  43. path: "/pages/code/code",
  44. icon: "/static/table/tab_code.png",
  45. selectIcon: "/static/table/tab_code.png",
  46. text: "",
  47. centerItem: true
  48. }, {
  49. id: 2,
  50. path: "/pages/mine/mine",
  51. icon: "/static/table/tab2.png",
  52. selectIcon: "/static/table/tab2_pre.png",
  53. text: "我的",
  54. centerItem: false
  55. }],
  56. };
  57. },
  58. mounted() {
  59. this.tabId = this.currentPage;
  60. //隐藏原生tab
  61. uni.hideTabBar();
  62. },
  63. created() {
  64. // 判断为 iPhone X 给予底部距离
  65. let that = this
  66. uni.getSystemInfo({
  67. success: function(res) {
  68. if (res.model.indexOf('iPhone X') !== -1) {
  69. that.isIpx = true;
  70. }
  71. }
  72. })
  73. },
  74. methods: {
  75. // tab 切换
  76. changeItem(item) {
  77. if (item.id == 1) {
  78. uni.navigateTo({
  79. url:item.path
  80. })
  81. console.log('点击中间' + '快速');
  82. } else {
  83. uni.switchTab({
  84. url: item.path,
  85. });
  86. }
  87. },
  88. }
  89. }
  90. </script>
  91. <style scoped>
  92. view {
  93. padding: 0;
  94. margin: 0;
  95. box-sizing: border-box;
  96. }
  97. .tabbar-container {
  98. position: fixed;
  99. bottom: 0;
  100. left: 0;
  101. width: 100%;
  102. background-color: #FFFFFF;
  103. }
  104. .tabbar-containers {
  105. height: 134rpx;
  106. box-sizing: border-box;
  107. /* height: 100rpx; */
  108. /* box-shadow: 0 0 5px #999; */
  109. box-shadow: 0px -6px 11px 0px rgba(215, 215, 215, 0.4);
  110. display: flex;
  111. align-items: center;
  112. /* padding: 24rpx 0; */
  113. color: #999999;
  114. }
  115. .tabbar-container .tabbar-item {
  116. width: 33.33%;
  117. /* height: 100rpx; */
  118. display: flex;
  119. flex-direction: column;
  120. justify-content: center;
  121. align-items: center;
  122. text-align: center;
  123. }
  124. .tabbar-container .item-active {
  125. color: #343434;
  126. }
  127. .tabbar-container .center-item {
  128. display: block;
  129. position: relative;
  130. }
  131. .tabbar-container .tabbar-item .item-top {
  132. width: 46rpx;
  133. height: 48rpx;
  134. margin-bottom: 10rpx;
  135. /* padding: 5rpx; */
  136. }
  137. .tabbar-container .center-item .item-top {
  138. flex-shrink: 0;
  139. width: 138rpx;
  140. height: 136rpx;
  141. position: absolute;
  142. bottom:calc(50% - 40rpx);
  143. left: calc(50% - 69rpx);
  144. border-radius: 50%;
  145. /* background-color: #FFFFFF; */
  146. /* box-shadow: 0px -6px 11px 0px rgba(215, 215, 215, 0.4); */
  147. }
  148. .tabbar-container .tabbar-item .item-top image {
  149. width: 100%;
  150. height: 100%;
  151. }
  152. .tabbar-container .tabbar-item .item-bottom {
  153. font-size: 26rpx;
  154. width: 100%;
  155. }
  156. .tabbar-container .center-item .item-bottom {
  157. position: absolute;
  158. bottom: 2rpx;
  159. }
  160. /* 适配iPhone X */
  161. .IpxBot {
  162. padding-bottom: 30rpx !important;
  163. }
  164. </style>