页面权限

This commit is contained in:
2026-03-09 15:02:09 +08:00
parent ef230b3836
commit 418c29095b
55 changed files with 391 additions and 150 deletions

View File

@@ -56,19 +56,22 @@ router.beforeEach((to, from, next) => {
isRelogin.show = true
// 获取字典数据 add by 芋艿
store.dispatch('dict/loadDictDatas')
// 获取部门权限
store.dispatch('GetLevel')
// 判断当前用户是否已拉取完 user_info 信息
store.dispatch('GetInfo').then(userInfo => {
isRelogin.show = false
// 触发 GenerateRoutes 事件时,将 menus 菜单树传递进去
store.dispatch('GenerateRoutes', userInfo.menus).then(accessRoutes => {
store.dispatch('GenerateRoutes', userInfo.menus).then(accessRoutes => {
// 根据 roles 权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表
const defaultPath = findDefaultPathFromMenus(userInfo.menus) || '/'
store.commit('permission/SET_DEFAULT_PATH', defaultPath)
if (to.path === '/' || to.matched.length === 0) {
// 仅当目标为根路径 '/' 时跳默认页;否则保持当前路径(含刷新场景),避免刷新被误判为“未匹配”而跳到默认页
if (to.path === '/') {
next({ path: defaultPath, replace: true })
} else {
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成,当前页刷新时保留 to 的路径
}
})
}).catch(err => {