| | |
| | | if (to.meta.title) { |
| | | document.title = to.meta.title + ' - ' + Config.title |
| | | } |
| | | console.log('to.path : ', to.path) |
| | | NProgress.start() |
| | | if (getToken()) { |
| | | // 已登录且要跳转的页面是登录页 |
| | |
| | | NProgress.done() |
| | | } else { |
| | | if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息 |
| | | console.log('1111111111111111111111111111111111111111111111111') |
| | | store.dispatch('GetInfo').then(() => { // 拉取user_info |
| | | // 动态路由,拉取菜单 |
| | | loadMenus(next, to) |
| | |
| | | }) |
| | | // 登录时未拉取 菜单,在此处拉取 |
| | | } else if (store.getters.loadMenus) { |
| | | console.log('222222222222222222222222222222222222222222222222222') |
| | | // 修改成false,防止死循环 |
| | | store.dispatch('updateLoadMenus') |
| | | loadMenus(next, to) |
| | | } else { |
| | | console.log('33333333333333333333333333333333333333333333333333') |
| | | next() |
| | | } |
| | | } |
| | |
| | | }) |
| | | |
| | | export const loadMenus = (next, to) => { |
| | | console.log('44444444444444444444444444444444444444444444') |
| | | buildMenus().then(res => { |
| | | const sdata = JSON.parse(JSON.stringify(res)) |
| | | const rdata = JSON.parse(JSON.stringify(res)) |
| | |
| | | |
| | | store.dispatch('GenerateRoutes', rewriteRoutes).then(() => { // 存储路由 |
| | | router.addRoutes(rewriteRoutes) // 动态添加可访问路由表 |
| | | console.log('to.path2 : ', to.path) |
| | | next({ ...to, replace: true }) |
| | | }) |
| | | store.dispatch('SetSidebarRouters', sidebarRoutes) |