tabBar.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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="@/images/basicsModules/btn_sy_xz.png" v-if="currentRoute == 'pages/home'">
  8. <img src="@/images/basicsModules/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="@/images/basicsModules/btn_xx_xz.png" v-if="currentRoute == 'pages/information/information'">
  14. <img src="@/images/basicsModules/btn_xx_zc.png" v-else>
  15. <view class="tip" v-if="totalCount!=0">{{totalCount}}</view>
  16. <view :class="currentRoute == 'pages/information/information'?'primary':''">消息</view>
  17. </view>
  18. <view class="null-box"></view>
  19. <view class="tba-bar-min-box" @click="tabBarGoPage(3)">
  20. <img src="@/images/basicsModules/btn_wd_xz.png" v-if="currentRoute == 'pages/mine'">
  21. <img src="@/images/basicsModules/btn_wd_zc.png" v-else>
  22. <view :class="currentRoute == 'pages/mine'?'primary':''">我的</view>
  23. </view>
  24. <view class="null-box"></view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { infoTotalCount } 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. 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. const {data} = await infoTotalCount();
  71. if(data.code==200){
  72. this.totalCount=data.data.totalCount
  73. }
  74. },
  75. tabBarGoPage(type){
  76. if(type === 1){
  77. if (this.currentRoute !== 'pages/home/home') {
  78. uni.redirectTo({
  79. url: '/pages/home/home',
  80. });
  81. }
  82. }else if(type === 2){
  83. if (this.currentRoute !== 'pages/information/information') {
  84. uni.redirectTo({
  85. url: '/pages/information/information',
  86. });
  87. }
  88. }else if(type === 3){
  89. if (this.currentRoute !== 'pages/mine/mine') {
  90. uni.redirectTo({
  91. url: '/pages/mine/mine',
  92. });
  93. }
  94. }
  95. },
  96. }
  97. }
  98. </script>
  99. <style lang="stylus" scoped>
  100. .tabBar{
  101. z-index:9999;
  102. width:100%;
  103. height:98rpx;
  104. background:#ffffff;
  105. position fixed
  106. bottom:0;
  107. left:0;
  108. box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
  109. .tab-bar-box{
  110. display flex;
  111. .null-box{
  112. flex:1;
  113. }
  114. .tba-bar-min-box{
  115. width:64rpx;
  116. position :relative;
  117. img{
  118. width:44rpx;
  119. height:44rpx;
  120. margin:14rpx auto 0;
  121. }
  122. view{
  123. line-height:37rpx;
  124. font-size:19rpx;
  125. text-align center;
  126. color:#666666;
  127. }
  128. .tip{
  129. display inline-block;
  130. background :#EF0909;
  131. border-radius 50%;
  132. position :absolute;
  133. font-size 24rpx;
  134. line-height 24rpx;
  135. color #fff;
  136. top :10rpx;
  137. left :44rpx;
  138. padding:6rpx 10rpx;
  139. box-sizing border-box;
  140. }
  141. }
  142. }
  143. }
  144. </style>