首页无权限跳转到第一个有权限的菜单
This commit is contained in:
@@ -17,8 +17,29 @@ router.beforeEach((to, from, next) => {
|
|||||||
if (Vue.ls.get(ACCESS_TOKEN)) {
|
if (Vue.ls.get(ACCESS_TOKEN)) {
|
||||||
/* has token */
|
/* has token */
|
||||||
if (to.path === '/user/login') {
|
if (to.path === '/user/login') {
|
||||||
next({ path: INDEX_MAIN_PAGE_PATH })
|
|
||||||
NProgress.done()
|
store.dispatch('GetPermissionList').then(res => {
|
||||||
|
const menuData = res.result.menu;
|
||||||
|
if (menuData === null || menuData === "" || menuData === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let constRoutes = [];
|
||||||
|
constRoutes = generateIndexRouter(menuData);
|
||||||
|
// 添加主界面路由
|
||||||
|
store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {
|
||||||
|
// 根据roles权限生成可访问的路由表
|
||||||
|
// 动态添加可访问路由表
|
||||||
|
router.addRoutes(store.getters.addRouters)
|
||||||
|
const redirect = decodeURIComponent(from.query.redirect || to.path)
|
||||||
|
next(findFirstRoute(menuData))
|
||||||
|
NProgress.done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
store.dispatch('Logout').then(() => {
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
if (store.getters.permissionList.length === 0) {
|
if (store.getters.permissionList.length === 0) {
|
||||||
store.dispatch('GetPermissionList').then(res => {
|
store.dispatch('GetPermissionList').then(res => {
|
||||||
|
|||||||
@@ -81,13 +81,14 @@ export function formatDate(value, fmt) {
|
|||||||
|
|
||||||
// 生成首页路由
|
// 生成首页路由
|
||||||
export function generateIndexRouter(data) {
|
export function generateIndexRouter(data) {
|
||||||
|
const redirectPath = findFirstRoute(data)
|
||||||
let indexRouter = [{
|
let indexRouter = [{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'dashboard',
|
name: 'dashboard',
|
||||||
//component: () => import('@/components/layouts/BasicLayout'),
|
//component: () => import('@/components/layouts/BasicLayout'),
|
||||||
component: resolve => require(['@/components/layouts/TabLayout'], resolve),
|
component: resolve => require(['@/components/layouts/TabLayout'], resolve),
|
||||||
meta: { title: '首页' },
|
meta: { title: '首页' },
|
||||||
redirect: '/dashboard/analysis',
|
redirect: redirectPath,
|
||||||
children: [
|
children: [
|
||||||
...generateChildRouters(data)
|
...generateChildRouters(data)
|
||||||
]
|
]
|
||||||
@@ -561,3 +562,14 @@ export function removeArrayElement(array, prod, value) {
|
|||||||
array.splice(index, 1);
|
array.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export function findFirstRoute(data){
|
||||||
|
if (data[0]) {
|
||||||
|
if (data[0] && data[0].children && data[0].children.length > 0) {
|
||||||
|
return findFirstRoute(data[0].children)
|
||||||
|
} else {
|
||||||
|
return data[0].path
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return '/'
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user