tabBar.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 { pageRestrictVerify } from '@/utils/index'
  36. import {
  37. systemNoticeGetNoticeCount
  38. } from '@/pages/api/index.js'
  39. export default {
  40. name: 'tabBar',
  41. data() {
  42. return {
  43. paddingBottomHeight: 0, //苹果X以上手机底部适配高度
  44. currentRoute: "",
  45. userType: "",
  46. totalCount: 0,
  47. }
  48. },
  49. created() {
  50. let that = this;
  51. uni.getSystemInfo({
  52. success: function(res) {
  53. let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
  54. model.forEach(item => {
  55. //适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
  56. if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
  57. that.paddingBottomHeight = 40;
  58. }
  59. })
  60. }
  61. });
  62. },
  63. onShow() {
  64. },
  65. mounted() {
  66. // 获取当前路由
  67. let pages = getCurrentPages();
  68. let page = pages[pages.length - 1];
  69. this.currentRoute = page.route;
  70. // 获取当前角色
  71. this.userType = uni.getStorageSync('userType');
  72. this.systemNoticeGetNoticeCount();
  73. },
  74. methods: {
  75. tabBarGoPage(type) {
  76. if (type === 1) {
  77. if (this.currentRoute !== 'pages/views/home/home') {
  78. uni.redirectTo({
  79. url: '/pages/views/home/home',
  80. });
  81. }
  82. } else if (type === 2) {
  83. if (!pageRestrictVerify('laboratoryManagement')) {
  84. uni.showToast({
  85. title: '没有相关权限,请联系管理员',
  86. icon: "none",
  87. mask: true,
  88. duration: 2000
  89. });
  90. return
  91. }
  92. if (this.currentRoute !== 'pages/views/teacherPage/laboratoryList') {
  93. uni.redirectTo({
  94. url: '/pages/views/teacherPage/laboratoryList',
  95. });
  96. }
  97. } else if (type === 3) {
  98. if (this.currentRoute !== 'pages/views/information/information') {
  99. uni.redirectTo({
  100. url: '/pages/views/information/information',
  101. });
  102. }
  103. } else if (type === 4) {
  104. if (this.currentRoute !== 'pages/views/mine/mine') {
  105. uni.redirectTo({
  106. url: '/pages/views/mine/mine',
  107. });
  108. }
  109. }
  110. },
  111. async systemNoticeGetNoticeCount(){
  112. const {
  113. data
  114. } = await systemNoticeGetNoticeCount();
  115. if(data.code == 200){
  116. this.$set(this,'totalCount',data.data);
  117. }
  118. },
  119. }
  120. }
  121. </script>
  122. <style lang="stylus" scoped>
  123. .tabBar {
  124. z-index: 9999;
  125. width: 100%;
  126. height: 98rpx;
  127. background: #ffffff;
  128. position fixed ;
  129. bottom: 0;
  130. left: 0;
  131. box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
  132. .tab-bar-box {
  133. display flex;
  134. .null-box {
  135. flex: 1;
  136. }
  137. .tba-bar-min-box {
  138. width: 64rpx;
  139. position: relative;
  140. img {
  141. width: 42rpx;
  142. height: 42rpx;
  143. margin: 15rpx auto 0;
  144. }
  145. view {
  146. line-height: 37rpx;
  147. font-size: 19rpx;
  148. text-align center;
  149. color: #666666;
  150. }
  151. .tips-box {
  152. position: absolute;
  153. top: 10rpx;
  154. left: 44rpx;
  155. display inline-block;
  156. background: #fa5151;
  157. border-radius 50%;
  158. width:20rpx;
  159. height:20rpx;
  160. }
  161. }
  162. }
  163. }
  164. </style>