tabBar.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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="@/pages/images/btn_sy_xz.png" v-if="currentRoute == 'pages/views/home/home'">
  8. <img src="@/pages/images/btn_sy_zc.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="@/pages/images/btn_xx_xz.png" v-if="currentRoute == 'pages/views/information/information'">
  14. <img src="@/pages/images/btn_xx_zc.png" v-else>
  15. <view :class="currentRoute == 'pages/information/information'?'primary':''">消息</view>
  16. </view>
  17. <view class="null-box"></view>
  18. <view class="tba-bar-min-box" @click="tabBarGoPage(3)">
  19. <img src="@/pages/images/btn_wd_xz.png" v-if="currentRoute == 'pages/views/mine/mine'">
  20. <img src="@/pages/images/btn_wd_zc.png" v-else>
  21. <view :class="currentRoute == 'pages/mine'?'primary':''">我的</view>
  22. </view>
  23. <view class="null-box"></view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. } from '@/api/apiDemo/index.js'
  30. export default {
  31. name: 'tabBar',
  32. data() {
  33. return {
  34. paddingBottomHeight: 0, //苹果X以上手机底部适配高度
  35. currentRoute: "",
  36. userType: "",
  37. totalCount: 0,
  38. }
  39. },
  40. created() {
  41. let that = this;
  42. uni.getSystemInfo({
  43. success: function(res) {
  44. let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
  45. model.forEach(item => {
  46. //适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
  47. if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
  48. that.paddingBottomHeight = 40;
  49. }
  50. })
  51. }
  52. });
  53. },
  54. onShow() {
  55. },
  56. mounted() {
  57. this.totalCount = uni.getStorageSync('totalCount')
  58. // 获取当前路由
  59. let pages = getCurrentPages();
  60. let page = pages[pages.length - 1];
  61. this.currentRoute = page.route;
  62. // 获取当前角色
  63. this.userType = uni.getStorageSync('userType');
  64. },
  65. methods: {
  66. tabBarGoPage(type) {
  67. if (type === 1) {
  68. if (this.currentRoute !== 'pages/views/home/home') {
  69. uni.redirectTo({
  70. url: '/pages/views/home/home',
  71. });
  72. }
  73. } else if (type === 2) {
  74. if (this.currentRoute !== 'pages/views/information/information') {
  75. uni.redirectTo({
  76. url: '/pages/views/information/information',
  77. });
  78. }
  79. } else if (type === 3) {
  80. if (this.currentRoute !== 'pages/views/mine/mine') {
  81. uni.redirectTo({
  82. url: '/pages/views/mine/mine',
  83. });
  84. }
  85. }
  86. },
  87. }
  88. }
  89. </script>
  90. <style lang="stylus" scoped>
  91. .tabBar {
  92. z-index: 9999;
  93. width: 100%;
  94. height: 98rpx;
  95. background: #ffffff;
  96. position fixed ;
  97. bottom: 0;
  98. left: 0;
  99. box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
  100. .tab-bar-box {
  101. display flex;
  102. .null-box {
  103. flex: 1;
  104. }
  105. .tba-bar-min-box {
  106. width: 64rpx;
  107. position: relative;
  108. img {
  109. width: 44rpx;
  110. height: 44rpx;
  111. margin: 14rpx auto 0;
  112. }
  113. view {
  114. line-height: 37rpx;
  115. font-size: 19rpx;
  116. text-align center;
  117. color: #666666;
  118. }
  119. .tip {
  120. display inline-block;
  121. background: #EF0909;
  122. border-radius 50%;
  123. position: absolute;
  124. font-size 24rpx;
  125. line-height 24rpx;
  126. color #fff;
  127. top: 10rpx;
  128. left: 44rpx;
  129. padding: 6rpx 10rpx;
  130. box-sizing border-box;
  131. }
  132. }
  133. }
  134. }
  135. </style>