tabbar.vue 4.6 KB

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