tabBar.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!-- 底部导航组件 -->
  2. <template>
  3. <view class="tabBar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
  4. <!-- 运输 -->
  5. <view class="tab-bar-box">
  6. <view class="null-box"></view>
  7. <view class="tba-bar-min-box" @click="tabBarGoPage(1)">
  8. <img src="@/images/Version2.2/btn_sy_xz.png" v-if="currentRoute == 'pages/home'">
  9. <img src="@/images/Version2.2/btn_sy_zc.png" v-else>
  10. <view :class="currentRoute == 'pages/home'?'primary':''">首页</view>
  11. </view>
  12. <view class="null-box"></view>
  13. <view class="tba-bar-min-box" @click="tabBarGoPage(2)">
  14. <img src="@/images/Version2.2/btn_xx_xz.png" v-if="currentRoute == 'pages/information/information'">
  15. <img src="@/images/Version2.2/btn_xx_zc.png" v-else>
  16. <view class="tip" v-if="totalCount!=0">{{totalCount}}</view>
  17. <view :class="currentRoute == 'pages/information/information'?'primary':''">消息</view>
  18. </view>
  19. <view class="null-box"></view>
  20. <view class="tba-bar-min-box" @click="tabBarGoPage(3)">
  21. <img src="@/images/Version2.2/btn_wd_xz.png" v-if="currentRoute == 'pages/mine'">
  22. <img src="@/images/Version2.2/btn_wd_zc.png" v-else>
  23. <view :class="currentRoute == 'pages/mine'?'primary':''">我的</view>
  24. </view>
  25. <view class="null-box"></view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { infoTotalCount } from '@/api/index.js'
  31. export default {
  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. this.getTotalList();
  56. },
  57. mounted(){
  58. this.getTotalList();
  59. this.totalCount=uni.getStorageSync('totalCount')
  60. // 获取当前路由
  61. let pages = getCurrentPages();
  62. let page = pages[pages.length - 1];
  63. this.currentRoute = page.route;
  64. // 获取当前角色
  65. this.userType = uni.getStorageSync('userType');
  66. },
  67. methods: {
  68. //获取消息总数接口
  69. async getTotalList(){
  70. console.log('消息')
  71. const {data} = await infoTotalCount();
  72. if(data.code==200){
  73. console.log(data)
  74. this.totalCount=data.data.totalCount
  75. }
  76. },
  77. tabBarGoPage(type){
  78. if(type === 1){
  79. if (this.currentRoute !== 'pages/home') {
  80. uni.redirectTo({
  81. url: '/pages/home',
  82. });
  83. }
  84. }else if(type === 2){
  85. if (this.currentRoute !== 'pages/information/information') {
  86. uni.redirectTo({
  87. url: '/pages/information/information',
  88. });
  89. }
  90. }else if(type === 3){
  91. if (this.currentRoute !== 'pages/mine') {
  92. uni.redirectTo({
  93. url: '/pages/mine',
  94. });
  95. }
  96. }
  97. },
  98. }
  99. }
  100. </script>
  101. <style lang="stylus" scoped>
  102. .tabBar{
  103. z-index:9999;
  104. width:100%;
  105. height:98rpx;
  106. background:#ffffff;
  107. position fixed
  108. bottom:0;
  109. left:0;
  110. box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
  111. .tab-bar-box{
  112. display flex;
  113. .null-box{
  114. flex:1;
  115. }
  116. .tba-bar-min-box{
  117. width:64rpx;
  118. position :relative;
  119. img{
  120. width:44rpx;
  121. height:44rpx;
  122. margin:14rpx auto 0;
  123. }
  124. view{
  125. line-height:37rpx;
  126. font-size:19rpx;
  127. text-align center;
  128. color:#666666;
  129. }
  130. .tip{
  131. display inline-block;
  132. background :#EF0909;
  133. border-radius 50%;
  134. position :absolute;
  135. font-size 24rpx;
  136. line-height 24rpx;
  137. color #fff;
  138. top :10rpx;
  139. left :44rpx;
  140. padding:6rpx 10rpx;
  141. box-sizing border-box;
  142. }
  143. }
  144. }
  145. }
  146. </style>