tm-tabbar.vue 3.7 KB

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