weicd
2024-01-04 eaf14dd28b5c95a08d433c6b6ccb5d2c0de2a2d4
eladmin-web-master/src/router/index.js
@@ -15,6 +15,7 @@
  if (to.meta.title) {
    document.title = to.meta.title + ' - ' + Config.title
  }
  console.log('to.path : ', to.path)
  NProgress.start()
  if (getToken()) {
    // 已登录且要跳转的页面是登录页
@@ -23,6 +24,7 @@
      NProgress.done()
    } else {
      if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
        console.log('1111111111111111111111111111111111111111111111111')
        store.dispatch('GetInfo').then(() => { // 拉取user_info
          // 动态路由,拉取菜单
          loadMenus(next, to)
@@ -33,10 +35,12 @@
        })
      // 登录时未拉取 菜单,在此处拉取
      } else if (store.getters.loadMenus) {
        console.log('222222222222222222222222222222222222222222222222222')
        // 修改成false,防止死循环
        store.dispatch('updateLoadMenus')
        loadMenus(next, to)
      } else {
        console.log('33333333333333333333333333333333333333333333333333')
        next()
      }
    }
@@ -52,6 +56,7 @@
})
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))
@@ -61,6 +66,7 @@
    store.dispatch('GenerateRoutes', rewriteRoutes).then(() => { // 存储路由
      router.addRoutes(rewriteRoutes) // 动态添加可访问路由表
      console.log('to.path2 : ', to.path)
      next({ ...to, replace: true })
    })
    store.dispatch('SetSidebarRouters', sidebarRoutes)