当前位置:   article > 正文

uniapp自定义权限菜单,动态tabbar_uniapp自定义动态权限 tabbar

uniapp自定义动态权限 tabbar

已封装为组件,亲测4个菜单项目可以切换,

以下为示例,根据Storage 中 userType 的 值,判断权限菜单

  1. <template>
  2. <view class="tab-bar pb10">
  3. <view class="tabli" v-for="(tab, index) in tabs" :key="index" @click="switchTab(tab)">
  4. <image :src="currentTab === tab.text ? tab.selectedIconPath : tab.iconPath" mode="aspectFit"></image>
  5. <text :class="currentTab === tab.text ? 'active' : ''">{{ tab.text }}</text>
  6. </view>
  7. <loginTourist ref="loginPop"></loginTourist>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props: {//当前页
  13. currentTab: {
  14. type: String,
  15. required: true
  16. }
  17. },
  18. data() {
  19. return {
  20. // 游客、管理员、村民
  21. usertype: uni.getStorageSync('userType'),
  22. }
  23. },
  24. computed: {
  25. // 权限菜单
  26. tabs() {
  27. if (this.usertype =='村民') {
  28. return [
  29. {
  30. "pagePath": "/pages/homepage/index",
  31. "iconPath": this.img('home-1'),
  32. "selectedIconPath": this.img('home'),
  33. "text": "首页"
  34. },
  35. {
  36. "pagePath": "/workPages/teach/index",
  37. "iconPath": this.img('bs-1'),
  38. "selectedIconPath": this.img('bs'),
  39. "text": "办事指南"
  40. },
  41. {
  42. "pagePath": "/pages/messag/index",
  43. "iconPath": this.img('mass-1'),
  44. "selectedIconPath": this.img('mass'),
  45. "text": "消息"
  46. },
  47. {
  48. "pagePath": "/pages/mine/index",
  49. "iconPath": this.img('mine-1'),
  50. "selectedIconPath": this.img('mine'),
  51. "text": "我的"
  52. }
  53. ],
  54. }else if (this.usertype =='管理员') {
  55. // 管理员
  56. return [
  57. {
  58. "pagePath": "/pages/homepage/index",
  59. "iconPath": this.img('home-1'),
  60. "selectedIconPath": this.img('home'),
  61. "text": "首页"
  62. },
  63. ],
  64. }
  65. }
  66. },
  67. methods: {
  68. switchTab(tab) {
  69. // console.log("底部导航", tab)
  70. let userType = uni.getStorageSync('userType')||this.userType
  71. let token = uni.getStorageSync('token')
  72. console.log('底部导航,用户,token|',tab.text ,userType,token)
  73. uni.navigateTo({
  74. url: tab.pagePath
  75. });
  76. },
  77. // 统一加图片域名路径
  78. img(img) {
  79. return 图片网址前缀 + 'tabBar/' + img + '.png'
  80. },
  81. },
  82. </script>
  83. <style>
  84. .tab-bar {
  85. justify-content: space-around;
  86. align-items: center;
  87. height: 150upx;
  88. position: fixed;
  89. left: 0;
  90. z-index: 99999999999999999999;
  91. width: 100%;
  92. display: flex;
  93. justify-content: space-around;
  94. background: rgb(240 242 245 / 97%);
  95. border-top: 0.5px solid rgba(240, 242, 245, 1)
  96. }
  97. .tab-bar .tabli {
  98. flex: 1;
  99. display: flex;
  100. flex-direction: column;
  101. align-items: center;
  102. justify-content: center;
  103. }
  104. .tab-bar image {
  105. width: 25px;
  106. height: 25px;
  107. }
  108. .tab-bar text {
  109. font-size: 12px;
  110. margin-top: 5px;
  111. }
  112. .tab-bar text.active {
  113. font-weight: bold;
  114. }
  115. </style>

声明为全局组件:main.js 中添加

  1. import tzTabBar from "@/components/atz-tabbar/atz-tabbar.vue"//自定义底部菜单
  2. Vue.component('tzTabBar', tzTabBar)

在页面中使用:

<tzTabBar :currentTab="'消息'"></tzTabBar>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/89795
推荐阅读