tabBar.vue 4.1 KB

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