增加没有分配菜单的拦截功能
This commit is contained in:
@@ -3,7 +3,7 @@ import store from './store'
|
|||||||
import { Message } from 'element-ui'
|
import { Message } from 'element-ui'
|
||||||
import NProgress from 'nprogress'
|
import NProgress from 'nprogress'
|
||||||
import 'nprogress/nprogress.css'
|
import 'nprogress/nprogress.css'
|
||||||
import { getAccessToken } from '@/utils/auth'
|
import { getAccessToken, removeToken } from '@/utils/auth'
|
||||||
import { isRelogin } from '@/utils/request'
|
import { isRelogin } from '@/utils/request'
|
||||||
|
|
||||||
NProgress.configure({ showSpinner: false })
|
NProgress.configure({ showSpinner: false })
|
||||||
@@ -64,13 +64,25 @@ router.beforeEach((to, from, next) => {
|
|||||||
} else {
|
} else {
|
||||||
if (store.getters.roles.length === 0) {
|
if (store.getters.roles.length === 0) {
|
||||||
isRelogin.show = true
|
isRelogin.show = true
|
||||||
// 获取字典数据 add by 芋艿
|
|
||||||
store.dispatch('dict/loadDictDatas')
|
|
||||||
// 获取部门权限
|
|
||||||
store.dispatch('GetLevel')
|
|
||||||
// 判断当前用户是否已拉取完 user_info 信息
|
// 判断当前用户是否已拉取完 user_info 信息
|
||||||
store.dispatch('GetInfo').then(userInfo => {
|
store.dispatch('GetInfo').then(userInfo => {
|
||||||
isRelogin.show = false
|
isRelogin.show = false
|
||||||
|
// 菜单为空时,清理登录信息、取消跳转,不调用后续接口
|
||||||
|
if (!userInfo.menus || userInfo.menus.length === 0) {
|
||||||
|
store.dispatch('LogOut').then(() => {
|
||||||
|
Message.error('当前用户没有菜单权限,请联系管理员添加')
|
||||||
|
next({ path: '/login', query: { menu_error: Date.now() }, replace: true })
|
||||||
|
}).catch(() => {
|
||||||
|
removeToken()
|
||||||
|
Message.error('当前用户没有菜单权限,请联系管理员添加')
|
||||||
|
next({ path: '/login', query: { menu_error: Date.now() }, replace: true })
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 获取字典数据 add by 芋艿
|
||||||
|
store.dispatch('dict/loadDictDatas')
|
||||||
|
// 获取部门权限
|
||||||
|
store.dispatch('GetLevel')
|
||||||
// 触发 GenerateRoutes 事件时,将 menus 菜单树传递进去
|
// 触发 GenerateRoutes 事件时,将 menus 菜单树传递进去
|
||||||
store.dispatch('GenerateRoutes', userInfo.menus).then(accessRoutes => {
|
store.dispatch('GenerateRoutes', userInfo.menus).then(accessRoutes => {
|
||||||
// 根据 roles 权限生成可访问的路由表
|
// 根据 roles 权限生成可访问的路由表
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const permission = {
|
|||||||
addRoutes: [],
|
addRoutes: [],
|
||||||
sidebarRouters: [], // 左侧边菜单的路由,被 Sidebar/index.vue 使用
|
sidebarRouters: [], // 左侧边菜单的路由,被 Sidebar/index.vue 使用
|
||||||
topbarRouters: [], // 顶部菜单的路由,被 TopNav/index.vue 使用
|
topbarRouters: [], // 顶部菜单的路由,被 TopNav/index.vue 使用
|
||||||
defaultPath: '/', // 登录后默认跳转路径(由菜单 jumpFlag===1 决定)
|
defaultPath: '/'
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_DEFAULT_PATH: (state, path) => {
|
SET_DEFAULT_PATH: (state, path) => {
|
||||||
|
|||||||
@@ -246,6 +246,11 @@ export default {
|
|||||||
: undefined;
|
: undefined;
|
||||||
this.getCookie();
|
this.getCookie();
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
'$route.query.menu_error'() {
|
||||||
|
this.loading = false;
|
||||||
|
},
|
||||||
|
},
|
||||||
destroyed() {
|
destroyed() {
|
||||||
document.body.style['min-height'] = 'unset';
|
document.body.style['min-height'] = 'unset';
|
||||||
},
|
},
|
||||||
@@ -293,7 +298,9 @@ export default {
|
|||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(this.redirect, this.$route.query.redirect, 'this.redirect');
|
console.log(this.redirect, this.$route.query.redirect, 'this.redirect');
|
||||||
this.$router.push({ path: this.redirect || '/' }).catch(() => { });
|
this.$router.push({ path: this.redirect || '/' }).catch(() => {
|
||||||
|
this.loading = false;
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user