登录后跳转到打标页面
This commit is contained in:
@@ -8,6 +8,38 @@ import { isRelogin } from '@/utils/request'
|
||||
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
/**
|
||||
* 从菜单树中查找 jumpFlag===1 的默认跳转路径
|
||||
* 若打标在父节点则取其下第一个可见叶子路径;若在叶子则直接返回该路径
|
||||
*/
|
||||
function findDefaultPathFromMenus(menus) {
|
||||
if (!Array.isArray(menus) || menus.length === 0) return null
|
||||
|
||||
function dfs(list, parentPath = '') {
|
||||
for (const item of list) {
|
||||
if (item.visible === false) continue
|
||||
const rawPath = item.path || ''
|
||||
const currentPath = rawPath.startsWith('/')
|
||||
? rawPath
|
||||
: `${parentPath}/${rawPath}`.replace(/\/+/g, '/')
|
||||
|
||||
if (item.jumpFlag === 1) {
|
||||
if (item.children && item.children.length > 0) {
|
||||
const childPath = dfs(item.children, currentPath)
|
||||
return childPath != null ? childPath : currentPath
|
||||
}
|
||||
return currentPath
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
const found = dfs(item.children, currentPath)
|
||||
if (found != null) return found
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
return dfs(menus)
|
||||
}
|
||||
|
||||
// 增加三方登陆 update by 芋艿
|
||||
const whiteList = ['/login', '/social-login', '/auth-redirect', '/bind', '/register', '/oauthLogin/gitee']
|
||||
|
||||
@@ -17,7 +49,7 @@ router.beforeEach((to, from, next) => {
|
||||
to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
|
||||
/* has token*/
|
||||
if (to.path === '/login') {
|
||||
next({ path: '/' })
|
||||
next({ path: store.getters.defaultPath || '/' })
|
||||
NProgress.done()
|
||||
} else {
|
||||
if (store.getters.roles.length === 0) {
|
||||
@@ -31,7 +63,13 @@ router.beforeEach((to, from, next) => {
|
||||
store.dispatch('GenerateRoutes', userInfo.menus).then(accessRoutes => {
|
||||
// 根据 roles 权限生成可访问的路由表
|
||||
router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
||||
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
||||
const defaultPath = findDefaultPathFromMenus(userInfo.menus) || '/'
|
||||
store.commit('permission/SET_DEFAULT_PATH', defaultPath)
|
||||
if (to.path === '/' || to.matched.length === 0) {
|
||||
next({ path: defaultPath, replace: true })
|
||||
} else {
|
||||
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
||||
}
|
||||
})
|
||||
}).catch(err => {
|
||||
store.dispatch('LogOut').then(() => {
|
||||
@@ -40,7 +78,12 @@ router.beforeEach((to, from, next) => {
|
||||
})
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
if (to.path === '/') {
|
||||
const defaultPath = store.getters.defaultPath || '/'
|
||||
next({ path: defaultPath, replace: true })
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user