tm-tabbar.vue 3.8 KB

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