关于crm系统中根据权限首次路由到不同工作台的实现

在公司CRM系统里,需首屏根据权限加载不同工作台,如CEO、区经等工作台。通过实现路由中重定向设置,在TagsView组件的created钩子函数里根据当前路由名选择跳转路由,可实现首屏加载工作台,刷新时保持当前路由。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在公司crm系统中需要首屏根据权限加载不同工作台,有ceo工作台、区经工作台、综合管家工作台、直销管家工作台,此时首先实现路由中重定向设置,代码如下

export const asyncRouterMap = [
  {
    path: '/',
    component: Layout,
    redirect: ''
  },
  {
    path: '',
    component: Layout,
    redirect: '/workbench/index',
    // redirect: '/renterResource/renterResourceList',
    name: 'workbench',
    meta: { permission: 'crm:workplat', role: ['1', '18', '30', '31'] },
    hidden: true,
    children: [{
      path: 'workbench',
      component: _import('workbench/index')
    }]
  },
  {
    path: '',
    component: Layout,
    redirect: '/workbench/index2',
    name: 'workbench',
    meta: { permission: 'crm:workplat', role: ['2', '3', '18'] },
    hidden: true,
    children: [{
      path: 'workbench',
      component: _import('workbench/index2')
    }]
  },
  {
    path: '',
    component: Layout,
    redirect: '/workbench/index3',
    name: 'workbench',
    meta: { permission: 'crm:workplat', role: ['4', '18'] },
    hidden: true,
    children: [{
      path: 'workbench',
      component: _import('workbench/index3')
    }]
  },
  {
    path: '',
    component: Layout,
    redirect: '/workbench/index4',
    name: 'workbench',
    meta: { permission: 'crm:workplat', role: ['5', '18'] },
    hidden: true,
    children: [{
      path: 'workbench',
      component: _import('workbench/index4')
    }]
  },
  {
    path: '/workbench',
    component: Layout,
    meta: { permission: 'crm:workplat', role: ['1', '18', '30', '31'] },
    children: [{
      path: 'index',
      name: 'workbench',
      component: _import('workbench/index'),
      meta: { title: 'ceo工作台', icon: 'workbench-icon', role: ['1', '18', '30', '31'] },
      id: 'workbench'
    }]

  },
  {
    path: '/workbench',
    component: Layout,
    meta: { permission: 'crm:workplat', role: ['2', '3', '18'] },
    children: [{
      path: 'index2',
      name: 'workbench2',
      component: _import('workbench/index2'),
      meta: { title: '区经工作台', icon: 'workbench-icon', role: ['2', '3', '18'] },
      id: 'workbench2'
    }]
  },
  {
    path: '/workbench',
    component: Layout,
    meta: { permission: 'crm:workplat', role: ['4', '18'] },
    children: [{
      path: 'index3',
      name: 'workbench3',
      component: _import('workbench/index3'),
      meta: { title: '综合管家工作台', icon: 'workbench-icon', role: ['4', '18'] },
      id: 'workbench3'
    }]
  },
  {
    path: '/workbench',
    component: Layout,
    meta: { permission: 'crm:workplat', role: ['5', '18'] },
    children: [{
      path: 'index4',
      name: 'workbench4',
      component: _import('workbench/index4'),
      meta: { title: '直销管家工作台', icon: 'workbench-icon', role: ['5', '18'] },
      id: 'workbench4'
    }]
  },

在TagsView组件中的created钩子函数中根据当前路由名,选择跳转路由,代码如下:

created() {
    if(this.$route.name == 'workbench'){
      if(this.roles.indexOf('1')>-1||this.roles.indexOf('18')>-1){
          this.$store.dispatch('itemArrAdd', {
            id: 'workbench',
            name: 'ceo工作台',
            params: {}
          })
      }else if(this.roles.indexOf('2')>-1||this.roles.indexOf('3')>-1||this.roles.indexOf('18')>-1){
          this.$store.dispatch('itemArrAdd', {
            id: 'workbench2',
            name: '区经工作台',
            params: {}
          })
      }else if(this.roles.indexOf('4')>-1||this.roles.indexOf('18')>-1){
          this.$store.dispatch('itemArrAdd', {
            id: 'workbench3',
            name: '综合管家工作台',
            params: {}
          })
      }else if(this.roles.indexOf('5')>-1||this.roles.indexOf('18')>-1){
          this.$store.dispatch('itemArrAdd', {
            id: 'workbench4',
            name: '直销管家工作台',
            params: {}
          })
      }
    } else {
      this.$store.dispatch('itemArrAdd', {
        id: this.$route.name,
        name: this.$route.meta.title
      })
    }
  }

如此可以实现首屏时加载工作台,刷新时保持当前路由,不会回到工作台!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值