tabBar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!-- 底部导航组件 -->
  2. <template>
  3. <view class="tabBar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
  4. <view class="tab-bar-box">
  5. <view class="null-box"></view>
  6. <view class="tba-bar-min-box" @click="tabBarGoPage(1)">
  7. <img :src="imagesUrl('commonality/icon_sy_xz@1x.png')" v-if="currentRoute == 'pages/views/home/home'">
  8. <img :src="imagesUrl('commonality/icon_sy_zc@1x.png')" v-else>
  9. <view :class="currentRoute == 'pages/home'?'primary':''">首页</view>
  10. </view>
  11. <view class="null-box"></view>
  12. <view class="tba-bar-min-box" @click="tabBarGoPage(2)">
  13. <img :src="imagesUrl('commonality/icon_wd_xz@1x.png')" v-if="currentRoute == 'pages/views/mine/mine'">
  14. <img :src="imagesUrl('commonality/icon_wd_zc@1x.png')" v-else>
  15. <view :class="currentRoute == 'pages/mine'?'primary':''">我的</view>
  16. </view>
  17. <view class="null-box"></view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'tabBar',
  24. data() {
  25. return {
  26. paddingBottomHeight: 0, //苹果X以上手机底部适配高度
  27. currentRoute: "",
  28. }
  29. },
  30. created() {
  31. let that = this;
  32. uni.getSystemInfo({
  33. success: function(res) {
  34. let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
  35. model.forEach(item => {
  36. //适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
  37. if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
  38. that.paddingBottomHeight = 40;
  39. }
  40. })
  41. }
  42. });
  43. },
  44. onShow() {
  45. },
  46. mounted() {
  47. // 获取当前路由
  48. let pages = getCurrentPages();
  49. let page = pages[pages.length - 1];
  50. this.currentRoute = page.route;
  51. },
  52. methods: {
  53. tabBarGoPage(type) {
  54. if (type === 1) {
  55. if (this.currentRoute !== 'pages/views/home/home') {
  56. uni.redirectTo({
  57. url: '/pages/views/home/home',
  58. });
  59. }
  60. } else if (type === 2) {
  61. if (this.currentRoute !== 'pages/views/mine/mine') {
  62. uni.redirectTo({
  63. url: '/pages/views/mine/mine',
  64. });
  65. }
  66. }
  67. },
  68. }
  69. }
  70. </script>
  71. <style lang="stylus" scoped>
  72. .tabBar {
  73. z-index: 9999;
  74. width: 100%;
  75. height: 98rpx;
  76. background: #ffffff;
  77. position fixed ;
  78. bottom: 0;
  79. left: 0;
  80. box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
  81. .tab-bar-box {
  82. display flex;
  83. .null-box {
  84. flex: 1;
  85. }
  86. .tba-bar-min-box {
  87. width: 64rpx;
  88. position: relative;
  89. img {
  90. width: 42rpx;
  91. height: 42rpx;
  92. margin: 15rpx auto 0;
  93. }
  94. view {
  95. line-height: 37rpx;
  96. font-size: 19rpx;
  97. text-align center;
  98. color: #666666;
  99. }
  100. .tips-box {
  101. position: absolute;
  102. top: 10rpx;
  103. left: 44rpx;
  104. display inline-block;
  105. background: #fa5151;
  106. border-radius 50%;
  107. width:20rpx;
  108. height:20rpx;
  109. }
  110. }
  111. }
  112. }
  113. </style>