xiaohuo 8 months ago
commit 71e198a1c4
  1. 28
      ALOps_sys_fe/alops-ui/src/permission.js
  2. 28
      ALOps_sys_fe/alops-ui/src/router/index.js
  3. 2110
      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) to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
/* has token*/ /* has token*/
if (to.path === '/login') { if (to.path === '/login') {
// 登录后根据角色重定向到不同主页 // 登录后直接重定向到首页
if (store.getters.roles && store.getters.roles.includes('admin')) { next({ path: '/' })
next({ path: '/index_admin' })
} else {
next({ path: '/' })
}
NProgress.done() NProgress.done()
} else if (isWhiteList(to.path)) { } else if (isWhiteList(to.path)) {
next() next()
@ -37,11 +33,10 @@ router.beforeEach((to, from, next) => {
store.dispatch('user/getInfo').then(() => { store.dispatch('user/getInfo').then(() => {
isRelogin.show = false isRelogin.show = false
store.dispatch('permission/GenerateRoutes').then(accessRoutes => { store.dispatch('permission/GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表 // 动态添加可访问路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表 router.addRoutes(accessRoutes)
// 获取角色信息后,判断是跳转到默认路由还是管理员路由 // 统一使用目标路径进行跳转
const redirectPath = store.getters.roles.includes('admin') ? '/index_admin' : to.path next({ path: to.path, replace: true }) // hack方法 确保addRoutes已完成
next({ path: redirectPath, replace: true }) // hack方法 确保addRoutes已完成
}) })
}).catch(err => { }).catch(err => {
store.dispatch('user/LogOut').then(() => { store.dispatch('user/LogOut').then(() => {
@ -50,16 +45,7 @@ router.beforeEach((to, from, next) => {
}) })
}) })
} else { } else {
// 如果访问的是根路径,根据角色重定向 next()
if (to.path === '/') {
if (store.getters.roles.includes('admin')) {
next({ path: '/index_admin', replace: true })
} else {
next()
}
} else {
next()
}
} }
} }
} else { } else {

@ -30,32 +30,6 @@ import Layout from '@/layout'
// 公共路由 // 公共路由
export const constantRoutes = [ 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', path: '/redirect',
component: Layout, component: Layout,
@ -96,7 +70,7 @@ export const constantRoutes = [
path: 'index', path: 'index',
component: () => import('@/views/index'), component: () => import('@/views/index'),
name: '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