tabBar.vue 3.7 KB

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