tabBar.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!-- 底部导航组件 -->
  2. <template>
  3. <view class="tabBar">
  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. currentRoute:"",
  35. userType:"",
  36. totalCount:0,
  37. }
  38. },
  39. created() {
  40. },
  41. onShow(){
  42. this.getTotalList();
  43. },
  44. mounted(){
  45. this.getTotalList();
  46. this.totalCount=uni.getStorageSync('totalCount')
  47. // 获取当前路由
  48. let pages = getCurrentPages();
  49. let page = pages[pages.length - 1];
  50. this.currentRoute = page.route;
  51. // 获取当前角色
  52. this.userType = uni.getStorageSync('userType');
  53. },
  54. methods: {
  55. //获取消息总数接口
  56. async getTotalList(){
  57. console.log('消息')
  58. const {data} = await infoTotalCount();
  59. if(data.code==200){
  60. console.log(data)
  61. this.totalCount=data.data.totalCount
  62. }
  63. },
  64. tabBarGoPage(type){
  65. if(type === 1){
  66. if (this.currentRoute !== 'pages/home') {
  67. uni.redirectTo({
  68. url: '/pages/home',
  69. });
  70. }
  71. }else if(type === 2){
  72. if (this.currentRoute !== 'pages/information/information') {
  73. uni.redirectTo({
  74. url: '/pages/information/information',
  75. });
  76. }
  77. }else if(type === 3){
  78. if (this.currentRoute !== 'pages/mine') {
  79. uni.redirectTo({
  80. url: '/pages/mine',
  81. });
  82. }
  83. }
  84. },
  85. }
  86. }
  87. </script>
  88. <style lang="stylus" scoped>
  89. .tabBar{
  90. z-index:9999;
  91. width:100%;
  92. height:98rpx;
  93. background:#ffffff;
  94. position fixed
  95. bottom:0;
  96. left:0;
  97. box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
  98. .tab-bar-box{
  99. display flex;
  100. .null-box{
  101. flex:1;
  102. }
  103. .tba-bar-min-box{
  104. width:64rpx;
  105. position :relative;
  106. img{
  107. width:44rpx;
  108. height:44rpx;
  109. margin:14rpx auto 0;
  110. }
  111. view{
  112. line-height:37rpx;
  113. font-size:19rpx;
  114. text-align center;
  115. color:#666666;
  116. }
  117. .tip{
  118. display inline-block;
  119. background :#EF0909;
  120. border-radius 50%;
  121. position :absolute;
  122. font-size 24rpx;
  123. line-height 24rpx;
  124. color #fff;
  125. top :10rpx;
  126. left :44rpx;
  127. padding:6rpx 10rpx;
  128. box-sizing border-box;
  129. }
  130. }
  131. }
  132. }
  133. </style>