当前位置:   article > 正文

uniapp如何根据不同角色自定义不同的tabbar_uniapp根据不同角色跳转到不同页面

uniapp根据不同角色跳转到不同页面

思路:

1.第一种是根据登录时获取的不同角色信息,来进行 跳转到不同的页面,在这些页面中使用自定义tabbar

2.第二种思路是封装一个自定义tabbar组件,然后在所有要展示tabbar的页面中引入使用

1.根据手机号码一键登录,在回调中获取用户信息进行跳转

  1. /**
  2. * @param {object} e 获取手机号码组件回调参数
  3. * @description 家政人员一键登录组件回调
  4. */
  5. async getPhoneNumber(e) {
  6. if (e.detail.errMsg == "getPhoneNumber:ok") {
  7. this.phoneCode = e.detail.code;
  8. if (this.loginCode == "") {
  9. await this.getCode();
  10. }
  11. this.loginForm = {
  12. loginCode: this.loginCode,
  13. phoneCode: this.phoneCode,
  14. };
  15. this.$http.staffWxLogin(this.loginForm).then(res => {
  16. if (res.code == 200) {
  17. console.log(res, 'res')
  18. uni.setStorageSync("token", res.data.token);
  19. uni.setStorageSync("employeeStaffId", res.data.userId);
  20. uni.setStorageSync('userType', 1);
  21. /**
  22. * 家政端
  23. */
  24. // uni.reLaunch({
  25. // url: '/pages/bottomPage/index'
  26. // })
  27. /**
  28. * 司机端
  29. */
  30. uni.reLaunch({
  31. url: "/page-diver/diver/tabBar/tabBar"
  32. })
  33. }
  34. })
  35. }
  36. },

2.在tabbar页面中完成自定义tabbar,并完成根据激活的tabbar展示不同页面的逻辑

其实就是调用v-if来控制不同页面的显示

  1. <template>
  2. <view style="height: 100vh; overflow-y: hidden;display: flex;flex-direction: column;">
  3. <view style="overflow-y: hidden;flex-grow: 10;">
  4. <!-- 首页 -->
  5. <scroll-view style="height: 100%;" v-if="currentTab === 'index'" scroll-y>
  6. <index-com></index-com>
  7. </scroll-view>
  8. <!-- 客户 -->
  9. <scroll-view style="height: 100%;" v-if="currentTab === 'customer'">
  10. <index-com></index-com>
  11. </scroll-view>
  12. <!-- 人员 -->
  13. <view style="height: 100%;" v-if="currentTab === 'person'" >
  14. <index-com></index-com>
  15. </view>
  16. <!-- 合同 -->
  17. <view style="height: 100%;" v-if="currentTab === 'contract'">
  18. <index-com></index-com>
  19. </view>
  20. <!-- 工具 -->
  21. <view style="height: 100%;" v-if="currentTab === 'tool'" scroll-y>
  22. <index-com></index-com>
  23. </view>
  24. </view>
  25. <!-- tabBar -->
  26. <u-tabbar :value="currentTab" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true"
  27. activeColor="#FF7993" inactiveColor="#A7A7A7" style="flex: 0">
  28. <u-tabbar-item v-for="(item,index) in iconList" :text="item.label" :key="index" :icon="item.isActive?item.active:item.path"
  29. @click="barClick"></u-tabbar-item>
  30. </u-tabbar>
  31. </view>
  32. </template>
  33. <script>
  34. import indexCom from '../index/index.vue'
  35. export default {
  36. components: {
  37. indexCom,
  38. },
  39. data() {
  40. return {
  41. currentTab: 'index',
  42. iconList: [
  43. {
  44. path:'/static/tabBar/diver-home.png',
  45. active:'/static/tabBar/diver-achome.png',
  46. name:'index',
  47. isActive:true,
  48. label:'首页'
  49. },
  50. {
  51. path:'/static/tabBar/diver-car.png',
  52. active:'/static/tabBar/diver-accar.png',
  53. name:'tool',
  54. isActive:false,
  55. label:'我的车队'
  56. },
  57. {
  58. path:'/static/tabBar/diver-my.png',
  59. active:'/static/tabBar/diver-acmy.png',
  60. name:'my',
  61. isActive:false,
  62. label:'我的'
  63. }
  64. ]
  65. }
  66. },
  67. methods: {
  68. barClick(e,name){
  69. for(let i =0;i<this.iconList.length;i++){
  70. if(i === e){
  71. if(!this.iconList[i].isActive){
  72. this.iconList[i].isActive = true
  73. this.currentTab =i
  74. console.log(this.currentTab,'currentTab')
  75. }
  76. }else{
  77. this.iconList[i].isActive = false
  78. }
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style>
  85. </style>

第二张思路就不赘述了,直接用上面的tabbar封装成组件引用即可,主要在pages.json中将tabbarlist设为空数组。

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

闽ICP备14008679号