tm-tabbar.vue 4.0 KB

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