tm-tabbar.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. text: '自查督查',
  69. iconPath: '/static/tabbar/tabicon-zhineng.png',
  70. selectedIconPath: '/static/tabbar/tabicon-actived-zhineng.png',
  71. pagePath: 'pages/situationsCenter/situationsCenter' // 页面路径
  72. }
  73. ],
  74. // 不同角色的拥有 tabbar下标(1、管理员 2、查核组长 3、查核组员 4、单位负责人 5、改善者)
  75. // {permission: 1, name: '管理员', msg: '个改善任务待处理'},
  76. // {permission: 2, name: '查核组长', msg: '个情境待分配'},
  77. // {permission: 3, name: '查核组员', msg: '个单位待查核'},
  78. // {permission: 4, name: '单位负责人', msg: '个改善任务待处理'},
  79. // {permission: 5, name: '改善者', msg: '个改善任务待处理'},
  80. // {permission: 6, name: '职能科室负责人', msg: '个改善任务待处理'},
  81. // {permission: 7, name: '职能科室普通人员', msg: '个改善任务待处理'},
  82. // {permission: 8, name: '自查人', msg: '个改善任务待处理'},
  83. rolList: [
  84. {permission: 1, name: '管理员', tabBarIndexs: [0,2, 3]}, // tabBarIndexs:tabBarList种对应的下标
  85. {permission: 2, name: '查核组长', tabBarIndexs: [0,1, 4, 3]},
  86. {permission: 3, name: '查核组员', tabBarIndexs: [0, 4, 3]},
  87. {permission: 4, name: '单位负责人', tabBarIndexs: [1,5,3]},
  88. {permission: 5, name: '改善者', tabBarIndexs: [1, 3]},
  89. {permission: 6, name: '职能科室负责人', tabBarIndexs: [5,1,4,3]},
  90. {permission: 7, name: '职能科室普通人员', tabBarIndexs: [5,4,3]},
  91. {permission: 8, name: '自查人', tabBarIndexs: [5,3]}
  92. ],
  93. rolToTabBars: [],
  94. }
  95. },
  96. watch: {
  97. permission(newVal) {
  98. this.getRolToTabBars(newVal)
  99. }
  100. },
  101. created(){
  102. this.getRolToTabBars(uni.getStorageSync('nowPermission'));
  103. },
  104. methods: {
  105. // 路由跳转
  106. navigateTo(pagePath){
  107. this.currentPagePath = pagePath;
  108. uni.reLaunch({
  109. url: `/${pagePath}`
  110. });
  111. // uni.redirectTo({
  112. // url: `/${pagePath}`
  113. // });
  114. // uni.navigateTo({
  115. // url: `/${pagePath}`
  116. // });
  117. },
  118. // 获取权限对应的地步导航
  119. getRolToTabBars(permission) {
  120. if(!permission) {
  121. this.rolToTabBars = [];
  122. }else {
  123. let current = this.rolList.find(item => item.permission == permission) || {};
  124. if(current){
  125. let tabBars = [];
  126. current.tabBarIndexs.map(index => {
  127. tabBars.push(this.tabBarList[index]);
  128. });
  129. this.rolToTabBars = tabBars;
  130. }else {
  131. this.rolToTabBars = [];
  132. }
  133. }
  134. let routes = getCurrentPages();
  135. this.currentPagePath = routes[routes.length - 1].route;
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="less">
  141. .tm-tabbar {
  142. position: fixed;
  143. left: 0;
  144. bottom: 0;
  145. display: flex;
  146. width: 100%;
  147. height: 87.5rpx;
  148. border-top: 0.62rpx solid #DADEE6;
  149. background-color: #fff;
  150. .tab-item {
  151. display: flex;
  152. flex-direction: column;
  153. justify-content: center;
  154. align-items: center;
  155. flex: 1;
  156. .icon {
  157. margin-bottom: 10rpx;
  158. width: 27.5rpx;
  159. height: 28.75rpx;
  160. }
  161. >text {
  162. font-size: 15rpx;
  163. color: #3D424D;
  164. }
  165. }
  166. .active.tab-item {
  167. >text {
  168. color: #3377FF;
  169. }
  170. }
  171. }
  172. </style>