当前位置:   article > 正文

Uniapp根据权限(角色)不同动态展示底部tabbar_springboot uniapp 动态权限导航栏显示

springboot uniapp 动态权限导航栏显示

比如绑定openId展示的tabbar为:首页、巡检、工单

未绑定openId展示的tabbar为:在线报修、我的报修

首页配置pages.json中的tabbar:

这里只用配置pagePath就可以了~

具体代码如下:

  1. "tabBar": {
  2. "custom": true,
  3. "color": "#bfbfbf",
  4. "selectedColor": "#226be4", // 选中tab栏文本颜色
  5. "list": [{
  6. "pagePath": "pages/home/home"
  7. // "text": "首页",
  8. // "iconPath": "static/shouye.png",
  9. // "selectedIconPath": "static/shouye(1).png"
  10. },
  11. {
  12. "pagePath": "pages/plan/plan"
  13. // "text": "巡检",
  14. // "iconPath": "static/xunjian.png",
  15. // "selectedIconPath": "static/xunjian (1).png"
  16. },
  17. {
  18. "pagePath": "pages/tickets/tickets"
  19. // "text": "工单",
  20. // "iconPath": "static/tickets.png",
  21. // "selectedIconPath": "static/tickets(1).png"
  22. },
  23. {
  24. "pagePath": "pages/onlrepairs/onlrepairs"
  25. // "text": "在线报修",
  26. // "iconPath": "static/onlrepair.png",
  27. // "selectedIconPath": "static/onlrepair(1).png"
  28. },
  29. {
  30. "pagePath": "pages/my/my"
  31. // "text": "我的报修",
  32. // "iconPath": "static/baoxiu.png",
  33. // "selectedIconPath": "static/baoxiu (1).png"
  34. }
  35. ]
  36. }

创建一个自定义的tabbar文件:

具体代码如下:

注意:pagePath的最前面要  加  /

  1. // 未绑定openId展示的页面
  2. const publicBar = [{
  3. "pagePath": "/pages/onlrepairs/onlrepairs",
  4. "text": "在线报修",
  5. "iconPath": "/static/onlrepair.png",
  6. "selectedIconPath": "/static/onlrepair(1).png"
  7. },
  8. {
  9. "pagePath": "/pages/my/my",
  10. "text": "我的报修",
  11. "iconPath": "/static/baoxiu.png",
  12. "selectedIconPath": "/static/baoxiu (1).png"
  13. }
  14. ]
  15. // 绑定openId展示的页面
  16. const selfBar = [{
  17. "pagePath": "/pages/home/home",
  18. "text": "首页",
  19. "iconPath": "/static/shouye.png",
  20. "selectedIconPath": "/static/shouye(1).png"
  21. },
  22. {
  23. "pagePath": "/pages/plan/plan",
  24. "text": "巡检",
  25. "iconPath": "/static/xunjian.png",
  26. "selectedIconPath": "/static/xunjian (1).png"
  27. },
  28. {
  29. "pagePath": "/pages/tickets/tickets",
  30. "text": "工单",
  31. "iconPath": "/static/tickets.png",
  32. "selectedIconPath": "/static/tickets(1).png"
  33. }
  34. ]
  35. export {
  36. publicBar,
  37. selfBar
  38. }

创建index.js文件配置vuex  :

具体代码如下:

  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. const store = new Vuex.Store({
  5. state: {
  6. dynamicTabbar: [] // 动态tabbar
  7. },
  8. getters: {},
  9. actions: {
  10. changeTabbar({commit}, payload) {
  11. commit('updateTabbar', payload)
  12. }
  13. },
  14. mutations: {
  15. updateTabbar(state, payload) {
  16. state.dynamicTabbar = payload
  17. }
  18. }
  19. })
  20. export default store

Vuex简易了解:

  1. state: 统一定义公共数据(类似于data(){return {a:1, b:2,xxxxxx}})
  2. mutations : 使用它来修改数据(类似于methods)更改state中的数据必须使用mutations来进行更改
  3. getters: 类似于computed(计算属性,对现有的状态进行计算得到新的数据-------派生 )
  4. actions: 发起异步请求
  5. modules: 模块拆分

在main.js中引入并挂载store:

在Login页面引入自定义tabbar页面并判断:

最后在每个页面使用动态的tabbar:

具体代码如下:

  1. <!-- 动态渲染tabBar -->
  2. <u-tabbar v-model="current" :list="tabBarList" :active-color="activeColor" :inactive-color="inactiveColor"
  3. :border-top="borderTop" />
  4. data() {
  5. return {
  6. title: '首页',
  7. tabBarList: this.$store.state.dynamicTabbar,
  8. current: 0,
  9. borderTop: true,
  10. inactiveColor: '#909399',
  11. activeColor: '#5098FF',
  12. }
  13. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/460484
推荐阅读
相关标签
  

闽ICP备14008679号