tm-tabbar.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="tm-tabbar">
  3. <template v-for="item in rolToTabBars">
  4. <view
  5. :class="{'tab-item': true, active: item.pagePath === currentPagePath}"
  6. :key="item.text"
  7. @click="navigateTo(item.pagePath)" >
  8. <image
  9. class="icon"
  10. :src="item.pagePath === currentPagePath
  11. ? item.selectedIconPath
  12. : item.iconPath"
  13. ></image>
  14. <text>{{ item.text }}</text>
  15. </view>
  16. </template>
  17. </view>
  18. </template>
  19. <script>
  20. /**
  21. * 底部tabBar
  22. * 芦荟
  23. * 2021.2.1
  24. */
  25. export default {
  26. data() {
  27. return {
  28. // 当前路由地址
  29. currentPagePath: '',
  30. // tabbar列表(这是最全的)
  31. tabBarList: [
  32. {
  33. text: '情境', // tab上按钮文字
  34. iconPath: '/static/tabbar/creatingSituations-unselect.png', // 图片路径
  35. selectedIconPath: '/static/tabbar/creatingSituations-select.png', // 选中时的图片路径
  36. pagePath: 'pages/creatingSituations/creatingSituations' // 页面路径
  37. },{
  38. text: '任务',
  39. iconPath: '/static/tabbar/mission-unselect.png',
  40. selectedIconPath: '/static/tabbar/mission-select.png',
  41. pagePath: 'pages/mission/mission'
  42. },{
  43. text: '配置',
  44. iconPath: '/static/tabbar/setting-unselect.png',
  45. selectedIconPath: '/static/tabbar/setting-select.png',
  46. pagePath: 'pages/configure/configure'
  47. },{
  48. text: '我的',
  49. iconPath: '/static/tabbar/my-unselect.png',
  50. selectedIconPath: '/static/tabbar/my-select.png',
  51. pagePath: 'pages/home/home'
  52. },{
  53. text: '日历',
  54. iconPath: '/static/tabbar/calendar-unselect.png',
  55. selectedIconPath: '/static/tabbar/calendar-select.png',
  56. pagePath: 'pages/index/index'
  57. }
  58. ],
  59. // 不同角色的拥有 tabbar下标(1、管理员 2、查核组长 3、查核组员 4、单位负责人 5、改善者)
  60. rolList: [
  61. {permission: 1, name: '管理员', tabBarIndexs: [0, 1, 2, 3]}, // tabBarIndexs:tabBarList种对应的下标
  62. {permission: 2, name: '查核组长', tabBarIndexs: [0, 4, 3]},
  63. {permission: 3, name: '查核组员', tabBarIndexs: [0, 4, 3]},
  64. {permission: 4, name: '单位负责人', tabBarIndexs: [0, 1, 3]},
  65. {permission: 5, name: '改善者', tabBarIndexs: [1, 3]}
  66. ],
  67. rolToTabBars: [],
  68. }
  69. },
  70. created(){
  71. this.getRolToTabBars();
  72. },
  73. methods: {
  74. // 路由跳转
  75. navigateTo(pagePath){
  76. this.currentPagePath = pagePath;
  77. uni.navigateTo({
  78. url: `/${pagePath}`
  79. });
  80. },
  81. // 获取权限对应的地步导航
  82. getRolToTabBars() {
  83. const permission = uni.getStorageSync('nowPermission');
  84. if(!permission) {
  85. this.rolToTabBars = [];
  86. }else {
  87. let current = this.rolList.find(item => item.permission == permission) || {};
  88. if(current){
  89. let tabBars = [];
  90. current.tabBarIndexs.map(index => {
  91. tabBars.push(this.tabBarList[index]);
  92. });
  93. this.rolToTabBars = tabBars;
  94. }else {
  95. this.rolToTabBars = [];
  96. }
  97. }
  98. let routes = getCurrentPages();
  99. this.currentPagePath = routes[routes.length - 1].route;
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="less">
  105. .tm-tabbar {
  106. position: fixed;
  107. left: 0;
  108. bottom: 0;
  109. display: flex;
  110. width: 100%;
  111. height: 87.5rpx;
  112. border-top: 0.62rpx solid #DADEE6;
  113. background-color: #fff;
  114. .tab-item {
  115. display: flex;
  116. flex-direction: column;
  117. justify-content: center;
  118. align-items: center;
  119. flex: 1;
  120. .icon {
  121. margin-bottom: 10rpx;
  122. width: 27.5rpx;
  123. height: 28.75rpx;
  124. }
  125. >text {
  126. font-size: 15rpx;
  127. color: #3D424D;
  128. }
  129. }
  130. .active.tab-item {
  131. >text {
  132. color: #3377FF;
  133. }
  134. }
  135. }
  136. </style>