xiaohuo 8 months ago
commit 71e198a1c4
  1. 24
      ALOps_sys_fe/alops-ui/src/permission.js
  2. 28
      ALOps_sys_fe/alops-ui/src/router/index.js
  3. 2154
      ALOps_sys_fe/alops-ui/src/views/index.vue

@ -21,12 +21,8 @@ router.beforeEach((to, from, next) => {
to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
/* has token*/
if (to.path === '/login') {
// 登录后根据角色重定向到不同主页
if (store.getters.roles && store.getters.roles.includes('admin')) {
next({ path: '/index_admin' })
} else {
// 登录后直接重定向到首页
next({ path: '/' })
}
NProgress.done()
} else if (isWhiteList(to.path)) {
next()
@ -37,11 +33,10 @@ router.beforeEach((to, from, next) => {
store.dispatch('user/getInfo').then(() => {
isRelogin.show = false
store.dispatch('permission/GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表
// 获取角色信息后,判断是跳转到默认路由还是管理员路由
const redirectPath = store.getters.roles.includes('admin') ? '/index_admin' : to.path
next({ path: redirectPath, replace: true }) // hack方法 确保addRoutes已完成
// 动态添加可访问路由表
router.addRoutes(accessRoutes)
// 统一使用目标路径进行跳转
next({ path: to.path, replace: true }) // hack方法 确保addRoutes已完成
})
}).catch(err => {
store.dispatch('user/LogOut').then(() => {
@ -49,18 +44,9 @@ router.beforeEach((to, from, next) => {
next({ path: '/' })
})
})
} else {
// 如果访问的是根路径,根据角色重定向
if (to.path === '/') {
if (store.getters.roles.includes('admin')) {
next({ path: '/index_admin', replace: true })
} else {
next()
}
} else {
next()
}
}
}
} else {
// 没有token

@ -30,32 +30,6 @@ import Layout from '@/layout'
// 公共路由
export const constantRoutes = [
{
path: '',
component: Layout,
redirect: 'index',
children: [
{
path: 'index_admin',
component: () => import('@/views/index'),
name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true, roles: ['common'] }
}
]
},
// {
// path: '',
// component: Layout,
// redirect: 'index',
// children: [
// {
// path: 'index_admin',
// component: () => import('@/views/index_1'),
// name: 'IndexAdmin',
// meta: { title: '管理员首页', icon: 'dashboard', affix: true, fullscreen: true }
// }
// ]
// },
{
path: '/redirect',
component: Layout,
@ -96,7 +70,7 @@ export const constantRoutes = [
path: 'index',
component: () => import('@/views/index'),
name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true, roles: ['common'] }
meta: { title: '首页', icon: 'dashboard' }
}
]
},

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save