tabBar.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!-- 底部导航组件 -->
  2. <template>
  3. <view class="tabBar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
  4. <!-- 运输 -->
  5. <view class="tab-bar-box">
  6. <view class="null-box"></view>
  7. <view class="tba-bar-min-box" @click="tabBarGoPage(1)">
  8. <img src="@/images/Version2.2/btn_sy_xz.png" v-if="currentRoute == 'pages/home'">
  9. <img src="@/images/Version2.2/btn_sy_zc.png" v-else>
  10. <view :class="currentRoute == 'pages/home'?'primary':''">首页</view>
  11. </view>
  12. <view class="null-box"></view>
  13. <view class="tba-bar-min-box" @click="tabBarGoPage(2)">
  14. <img src="@/images/Version2.2/btn_xx_xz.png" v-if="currentRoute == 'pages/information/information'">
  15. <img src="@/images/Version2.2/btn_xx_zc.png" v-else>
  16. <view class="tip" v-if="totalCount!=0">{{totalCount}}</view>
  17. <view :class="currentRoute == 'pages/information/information'?'primary':''">消息</view>
  18. </view>
  19. <view class="null-box"></view>
  20. <view class="tba-bar-min-box" @click="tabBarGoPage(3)">
  21. <img src="@/images/Version2.2/btn_wd_xz.png" v-if="currentRoute == 'pages/mine'">
  22. <img src="@/images/Version2.2/btn_wd_zc.png" v-else>
  23. <view :class="currentRoute == 'pages/mine'?'primary':''">我的</view>
  24. </view>
  25. <view class="null-box"></view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { infoTotalCount } from '@/api/index.js'
  31. export default {
  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. let safetyIdentity=uni.getStorageSync('gentleIdentifier')[0].pageType
  78. if(safetyIdentity=='mine'){//安全检查模块判断身份是否有权限
  79. uni.showToast({
  80. title: '暂无安全检查权限',
  81. mask:true,
  82. icon:"none",
  83. duration: 2000
  84. });
  85. }else{
  86. if (this.currentRoute !== 'pages/home') {
  87. uni.redirectTo({
  88. url: '/pages/home',
  89. });
  90. }
  91. }
  92. }else if(type === 2){
  93. if (this.currentRoute !== 'pages/information/information') {
  94. uni.redirectTo({
  95. url: '/pages/information/information',
  96. });
  97. }
  98. }else if(type === 3){
  99. if (this.currentRoute !== 'pages/mine') {
  100. uni.redirectTo({
  101. url: '/pages/mine',
  102. });
  103. }
  104. }
  105. },
  106. }
  107. }
  108. </script>
  109. <style lang="stylus" scoped>
  110. .tabBar{
  111. z-index:9999;
  112. width:100%;
  113. height:98rpx;
  114. background:#ffffff;
  115. position fixed
  116. bottom:0;
  117. left:0;
  118. box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
  119. .tab-bar-box{
  120. display flex;
  121. .null-box{
  122. flex:1;
  123. }
  124. .tba-bar-min-box{
  125. width:64rpx;
  126. position :relative;
  127. img{
  128. width:44rpx;
  129. height:44rpx;
  130. margin:14rpx auto 0;
  131. }
  132. view{
  133. line-height:37rpx;
  134. font-size:19rpx;
  135. text-align center;
  136. color:#666666;
  137. }
  138. .tip{
  139. display inline-block;
  140. background :#EF0909;
  141. border-radius 50%;
  142. position :absolute;
  143. font-size 24rpx;
  144. line-height 24rpx;
  145. color #fff;
  146. top :10rpx;
  147. left :44rpx;
  148. padding:6rpx 10rpx;
  149. box-sizing border-box;
  150. }
  151. }
  152. }
  153. }
  154. </style>