tm-tabbar.vue 4.0 KB

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