tm-tabbar.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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', { 'icon-large': isLargeIcon(item) }]"
  11. :style="isLargeIcon(item) ? { marginBottom: largeIconGap + 'rpx' } : {}"
  12. :src="item.pagePath === currentPagePath
  13. ? item.selectedIconPath
  14. : item.iconPath"
  15. ></image>
  16. <text>{{ item.text }}</text>
  17. </view>
  18. </template>
  19. </view>
  20. </template>
  21. <script>
  22. /**
  23. * 底部tabBar
  24. * 芦荟
  25. * 2021.2.1
  26. */
  27. import appUpdate from "@/components/app-update/app-update.vue"
  28. export default {
  29. components:{appUpdate},
  30. props: {
  31. permission: {
  32. type: Number | String,
  33. default: 0
  34. }
  35. },
  36. data() {
  37. return {
  38. // 当前路由地址
  39. currentPagePath: '',
  40. // 需要放大图标的页面路径集合(可扩展)
  41. largeIconPages: ['pages/ai-qa/ai-qa'],
  42. // 放大图标与文字间距(仅 largeIconPages 生效)
  43. largeIconGap: 3,
  44. // tabbar列表(这是最全的)
  45. tabBarList: [
  46. {
  47. text: '情境', // tab上按钮文字
  48. iconPath: '/static/tabbar/creatingSituations-unselect.png', // 图片路径
  49. selectedIconPath: '/static/tabbar/creatingSituations-select.png', // 选中时的图片路径
  50. pagePath: 'pages/situationsCenter/situationsCenter' // 页面路径
  51. },{
  52. text: '任务',
  53. iconPath: '/static/tabbar/mission-unselect.png',
  54. selectedIconPath: '/static/tabbar/mission-select.png',
  55. pagePath: 'pages/mission/mission'
  56. },{
  57. text: '配置',
  58. iconPath: '/static/tabbar/setting-unselect.png',
  59. selectedIconPath: '/static/tabbar/setting-select.png',
  60. pagePath: 'pages/configure/configure'
  61. },{
  62. text: '我的',
  63. iconPath: '/static/tabbar/my-unselect.png',
  64. selectedIconPath: '/static/tabbar/my-select.png',
  65. pagePath: 'pages/home/home'
  66. },{
  67. text: '日历',
  68. iconPath: '/static/tabbar/calendar-unselect.png',
  69. selectedIconPath: '/static/tabbar/calendar-select.png',
  70. pagePath: 'pages/calendar/calendar'
  71. },
  72. {
  73. text: '自查督查',
  74. iconPath: '/static/tabbar/tabicon-zhineng.png',
  75. selectedIconPath: '/static/tabbar/tabicon-actived-zhineng.png',
  76. pagePath: 'pages/situationsCenter/situationsCenter' // 页面路径
  77. },
  78. {
  79. text: 'AI问答',
  80. iconPath: '/static/aiwenda_tabicon.png',
  81. selectedIconPath: '/static/aiwenda_tabicon_color.png',
  82. pagePath: 'pages/ai-qa/ai-qa'
  83. }
  84. ],
  85. // 不同角色的拥有 tabbar下标(1、管理员 2、查核组长 3、查核组员 4、单位负责人 5、改善者)
  86. // {permission: 1, name: '管理员', msg: '个改善任务待处理'},
  87. // {permission: 2, name: '查核组长', msg: '个情境待分配'},
  88. // {permission: 3, name: '查核组员', msg: '个单位待查核'},
  89. // {permission: 4, name: '单位负责人', msg: '个改善任务待处理'},
  90. // {permission: 5, name: '改善者', msg: '个改善任务待处理'},
  91. // {permission: 6, name: '职能科室负责人', msg: '个改善任务待处理'},
  92. // {permission: 7, name: '职能科室普通人员', msg: '个改善任务待处理'},
  93. // {permission: 8, name: '自查人', msg: '个改善任务待处理'},
  94. rolList: [
  95. {permission: 1, name: '管理员', tabBarIndexs: [0,2, 3]}, // tabBarIndexs:tabBarList种对应的下标
  96. {permission: 2, name: '查核组长', tabBarIndexs: [0,1, 4, 3]},
  97. {permission: 3, name: '查核组员', tabBarIndexs: [0, 4, 3]},
  98. {permission: 4, name: '单位负责人', tabBarIndexs: [1,5,3]},
  99. {permission: 5, name: '改善者', tabBarIndexs: [1, 3]},
  100. {permission: 6, name: '职能科室负责人', tabBarIndexs: [5,1,4,3]},
  101. {permission: 7, name: '职能科室普通人员', tabBarIndexs: [5,4,3]},
  102. {permission: 8, name: '自查人', tabBarIndexs: [5,3]}
  103. ],
  104. rolToTabBars: [],
  105. }
  106. },
  107. watch: {
  108. permission(newVal) {
  109. this.getRolToTabBars(newVal)
  110. }
  111. },
  112. created(){
  113. this.getRolToTabBars(uni.getStorageSync('nowPermission'));
  114. },
  115. methods: {
  116. // 路由跳转
  117. navigateTo(pagePath){
  118. this.currentPagePath = pagePath;
  119. uni.reLaunch({
  120. url: `/${pagePath}`
  121. });
  122. // uni.redirectTo({
  123. // url: `/${pagePath}`
  124. // });
  125. // uni.navigateTo({
  126. // url: `/${pagePath}`
  127. // });
  128. },
  129. // 获取权限对应的地步导航
  130. getRolToTabBars(permission) {
  131. if(!permission) {
  132. this.rolToTabBars = [];
  133. }else {
  134. let current = this.rolList.find(item => item.permission == permission) || {};
  135. if(current){
  136. let tabBars = [];
  137. current.tabBarIndexs.map(index => {
  138. tabBars.push(this.tabBarList[index]);
  139. });
  140. // H5 平台显示 AI问答,APP 端隐藏入口
  141. // #ifdef H5
  142. const aiTab = this.tabBarList.find(item => item.pagePath === 'pages/ai-qa/ai-qa');
  143. if (aiTab) {
  144. const alreadyHas = tabBars.some(item => item.pagePath === aiTab.pagePath);
  145. if (!alreadyHas) {
  146. const middleIndex = Math.floor(tabBars.length / 2);
  147. tabBars.splice(middleIndex, 0, aiTab);
  148. }
  149. }
  150. // #endif
  151. this.rolToTabBars = tabBars;
  152. }else {
  153. this.rolToTabBars = [];
  154. }
  155. }
  156. let routes = getCurrentPages();
  157. this.currentPagePath = routes[routes.length - 1].route;
  158. },
  159. // 判断该项是否需要使用大图标
  160. isLargeIcon(item){
  161. return this.largeIconPages.includes(item.pagePath);
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="less">
  167. .tm-tabbar {
  168. position: fixed;
  169. left: 0;
  170. bottom: 0;
  171. z-index: 999;
  172. display: flex;
  173. width: 100%;
  174. height: 87.5rpx;
  175. background-color: #fff;
  176. .tab-item {
  177. display: flex;
  178. flex-direction: column;
  179. justify-content: center;
  180. align-items: center;
  181. flex: 1;
  182. .icon {
  183. margin-bottom: 10rpx;
  184. width: 27.5rpx;
  185. height: 28.75rpx;
  186. }
  187. // 放大图标样式(仅配置的页面使用)
  188. .icon-large {
  189. width: 35rpx;
  190. height: 38rpx;
  191. }
  192. >text {
  193. font-size: 15rpx;
  194. color: #3D424D;
  195. }
  196. }
  197. .active.tab-item {
  198. >text {
  199. color: #3377FF;
  200. }
  201. }
  202. }
  203. </style>