首页无权限跳转到第一个有权限的菜单

This commit is contained in:
姚亚男
2022-01-26 09:58:36 +08:00
parent 2cb4c1f481
commit fe83dd07ae
2 changed files with 36 additions and 3 deletions
+23 -2
View File
@@ -17,8 +17,29 @@ router.beforeEach((to, from, next) => {
if (Vue.ls.get(ACCESS_TOKEN)) {
/* has token */
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 {
if (store.getters.permissionList.length === 0) {
store.dispatch('GetPermissionList').then(res => {