在公司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
})
}
}
如此可以实现首屏时加载工作台,刷新时保持当前路由,不会回到工作台!