tm-tabbar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 | String,
  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/situationsCenter/situationsCenter' // 页面路径
  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: [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.redirectTo({
  89. url: `/${pagePath}`
  90. });
  91. // uni.navigateTo({
  92. // url: `/${pagePath}`
  93. // });
  94. },
  95. // 获取权限对应的地步导航
  96. getRolToTabBars(permission) {
  97. if(!permission) {
  98. this.rolToTabBars = [];
  99. }else {
  100. let current = this.rolList.find(item => item.permission == permission) || {};
  101. if(current){
  102. let tabBars = [];
  103. current.tabBarIndexs.map(index => {
  104. tabBars.push(this.tabBarList[index]);
  105. });
  106. this.rolToTabBars = tabBars;
  107. }else {
  108. this.rolToTabBars = [];
  109. }
  110. }
  111. let routes = getCurrentPages();
  112. this.currentPagePath = routes[routes.length - 1].route;
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="less">
  118. .tm-tabbar {
  119. position: fixed;
  120. left: 0;
  121. bottom: 0;
  122. display: flex;
  123. width: 100%;
  124. height: 87.5rpx;
  125. border-top: 0.62rpx solid #DADEE6;
  126. background-color: #fff;
  127. .tab-item {
  128. display: flex;
  129. flex-direction: column;
  130. justify-content: center;
  131. align-items: center;
  132. flex: 1;
  133. .icon {
  134. margin-bottom: 10rpx;
  135. width: 27.5rpx;
  136. height: 28.75rpx;
  137. }
  138. >text {
  139. font-size: 15rpx;
  140. color: #3D424D;
  141. }
  142. }
  143. .active.tab-item {
  144. >text {
  145. color: #3377FF;
  146. }
  147. }
  148. }
  149. </style>