tabBar.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/icon_sy_xz@1x.png" v-if="currentRoute == 'pages/views/home/home'">
  8. <img src="@/pages/images/icon_sy_zc@1x.png" v-else>
  9. <view :class="currentRoute == 'pages/home'?'primary':''">首页</view>
  10. </view>
  11. <view class="null-box" v-if="userType == 1"></view>
  12. <view class="tba-bar-min-box" @click="tabBarGoPage(2)" v-if="userType == 1">
  13. <img src="@/pages/images/icon_sys_xz@1x.png" v-if="currentRoute == 'pages/views/teacherPage/laboratoryList'">
  14. <img src="@/pages/images/icon_sys_zc@1x.png" v-else>
  15. <view :class="currentRoute == 'pages/information/information'?'primary':''">实验室</view>
  16. </view>
  17. <view class="null-box"></view>
  18. <view class="tba-bar-min-box" @click="tabBarGoPage(3)">
  19. <img src="@/pages/images/icon_xx_xz@1x.png" v-if="currentRoute == 'pages/views/information/information'">
  20. <img src="@/pages/images/icon_xx_zc@1x.png" v-else>
  21. <view :class="currentRoute == 'pages/information/information'?'primary':''">消息</view>
  22. <view class="tips-box" v-if="totalCount>0"></view>
  23. </view>
  24. <view class="null-box"></view>
  25. <view class="tba-bar-min-box" @click="tabBarGoPage(4)">
  26. <img src="@/pages/images/icon_wd_xz@1x.png" v-if="currentRoute == 'pages/views/mine/mine'">
  27. <img src="@/pages/images/icon_wd_zc@1x.png" v-else>
  28. <view :class="currentRoute == 'pages/mine'?'primary':''">我的</view>
  29. </view>
  30. <view class="null-box"></view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. systemNoticeGetNoticeCount
  37. } from '@/pages/api/index.js'
  38. export default {
  39. name: 'tabBar',
  40. data() {
  41. return {
  42. paddingBottomHeight: 0, //苹果X以上手机底部适配高度
  43. currentRoute: "",
  44. userType: "",
  45. totalCount: 0,
  46. }
  47. },
  48. created() {
  49. let that = this;
  50. uni.getSystemInfo({
  51. success: function(res) {
  52. let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
  53. model.forEach(item => {
  54. //适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
  55. if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
  56. that.paddingBottomHeight = 40;
  57. }
  58. })
  59. }
  60. });
  61. },
  62. onShow() {
  63. },
  64. mounted() {
  65. // 获取当前路由
  66. let pages = getCurrentPages();
  67. let page = pages[pages.length - 1];
  68. this.currentRoute = page.route;
  69. // 获取当前角色
  70. this.userType = uni.getStorageSync('userType');
  71. this.systemNoticeGetNoticeCount();
  72. },
  73. methods: {
  74. tabBarGoPage(type) {
  75. if (type === 1) {
  76. if (this.currentRoute !== 'pages/views/home/home') {
  77. uni.redirectTo({
  78. url: '/pages/views/home/home',
  79. });
  80. }
  81. } else if (type === 2) {
  82. if (this.currentRoute !== 'pages/views/teacherPage/laboratoryList') {
  83. uni.redirectTo({
  84. url: '/pages/views/teacherPage/laboratoryList',
  85. });
  86. }
  87. } else if (type === 3) {
  88. if (this.currentRoute !== 'pages/views/information/information') {
  89. uni.redirectTo({
  90. url: '/pages/views/information/information',
  91. });
  92. }
  93. } else if (type === 4) {
  94. if (this.currentRoute !== 'pages/views/mine/mine') {
  95. uni.redirectTo({
  96. url: '/pages/views/mine/mine',
  97. });
  98. }
  99. }
  100. },
  101. async systemNoticeGetNoticeCount(){
  102. const {
  103. data
  104. } = await systemNoticeGetNoticeCount();
  105. if(data.code == 200){
  106. this.$set(this,'totalCount',data.data);
  107. }
  108. },
  109. }
  110. }
  111. </script>
  112. <style lang="stylus" scoped>
  113. .tabBar {
  114. z-index: 9999;
  115. width: 100%;
  116. height: 98rpx;
  117. background: #ffffff;
  118. position fixed ;
  119. bottom: 0;
  120. left: 0;
  121. box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
  122. .tab-bar-box {
  123. display flex;
  124. .null-box {
  125. flex: 1;
  126. }
  127. .tba-bar-min-box {
  128. width: 64rpx;
  129. position: relative;
  130. img {
  131. width: 42rpx;
  132. height: 42rpx;
  133. margin: 15rpx auto 0;
  134. }
  135. view {
  136. line-height: 37rpx;
  137. font-size: 19rpx;
  138. text-align center;
  139. color: #666666;
  140. }
  141. .tips-box {
  142. position: absolute;
  143. top: 10rpx;
  144. left: 44rpx;
  145. display inline-block;
  146. background: #fa5151;
  147. border-radius 50%;
  148. width:20rpx;
  149. height:20rpx;
  150. }
  151. }
  152. }
  153. }
  154. </style>