|  | @ -3,13 +3,13 @@ import store from '@/store' | 
		
	
		
			
				|  |  | import Config from '@/settings' |  |  | import Config from '@/settings' | 
		
	
		
			
				|  |  | import NProgress from 'nprogress' // progress bar
 |  |  | import NProgress from 'nprogress' // progress bar
 | 
		
	
		
			
				|  |  | import 'nprogress/nprogress.css' // progress bar style
 |  |  | import 'nprogress/nprogress.css' // progress bar style
 | 
		
	
		
			
				|  |  | // import { getToken } from '@/utils/auth' // getToken from cookie
 |  |  |  | 
		
	
		
			
				|  |  |  |  |  | import { getToken } from '@/utils/auth' // getToken from cookie
 | 
		
	
		
			
				|  |  | import { buildMenus } from '@/api/system/menu' |  |  | import { buildMenus } from '@/api/system/menu' | 
		
	
		
			
				|  |  | import { filterAsyncRouter } from '@/store/modules/permission' |  |  | import { filterAsyncRouter } from '@/store/modules/permission' | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | NProgress.configure({ showSpinner: false }) // NProgress Configuration
 |  |  | NProgress.configure({ showSpinner: false }) // NProgress Configuration
 | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | // const whiteList = ['/login', '/forgetPassword'] // no redirect whitelist
 |  |  |  | 
		
	
		
			
				|  |  |  |  |  | const whiteList = ['/login', '/forgetPassword'] // no redirect whitelist
 | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | router.beforeEach((to, from, next) => { |  |  | router.beforeEach((to, from, next) => { | 
		
	
		
			
				|  |  |   if (to.meta.title) { |  |  |   if (to.meta.title) { | 
		
	
	
		
			
				|  | @ -17,49 +17,51 @@ router.beforeEach((to, from, next) => { | 
		
	
		
			
				|  |  |   } |  |  |   } | 
		
	
		
			
				|  |  |   // 加载效果
 |  |  |   // 加载效果
 | 
		
	
		
			
				|  |  |   NProgress.start() |  |  |   NProgress.start() | 
		
	
		
			
				|  |  |  |  |  |   // next()
 | 
		
	
		
			
				|  |  |  |  |  |   // NProgress.done()
 | 
		
	
		
			
				|  |  |  |  |  |   if (getToken()) { | 
		
	
		
			
				|  |  |  |  |  |     // 已登录且要跳转的页面是登录页
 | 
		
	
		
			
				|  |  |  |  |  |     if (to.path === '/login') { | 
		
	
		
			
				|  |  |  |  |  |       next({ path: '/' }) | 
		
	
		
			
				|  |  |  |  |  |       NProgress.done() | 
		
	
		
			
				|  |  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |  |       if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
 | 
		
	
		
			
				|  |  |  |  |  |         store.dispatch('GetInfo').then(() => { // 拉取user_info
 | 
		
	
		
			
				|  |  |  |  |  |           // 动态路由,拉取菜单
 | 
		
	
		
			
				|  |  |  |  |  |           loadMenus(next, to) | 
		
	
		
			
				|  |  |  |  |  |         }).catch(() => { | 
		
	
		
			
				|  |  |  |  |  |           console.log('logOut') | 
		
	
		
			
				|  |  |  |  |  |           store.dispatch('LogOut').then(() => { | 
		
	
		
			
				|  |  |  |  |  |             location.reload() // 为了重新实例化vue-router对象 避免bug
 | 
		
	
		
			
				|  |  |  |  |  |           }) | 
		
	
		
			
				|  |  |  |  |  |         }) | 
		
	
		
			
				|  |  |  |  |  |         // 登录时未拉取 菜单,在此处拉取
 | 
		
	
		
			
				|  |  |  |  |  |       } else if (store.getters.loadMenus) { | 
		
	
		
			
				|  |  |  |  |  |         // 修改成false,防止死循环
 | 
		
	
		
			
				|  |  |  |  |  |         store.dispatch('updateLoadMenus') | 
		
	
		
			
				|  |  |  |  |  |         loadMenus(next, to) | 
		
	
		
			
				|  |  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |  |         next() | 
		
	
		
			
				|  |  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  |   } else { | 
		
	
		
			
				|  |  |  |  |  |     /* has no token*/ | 
		
	
		
			
				|  |  |  |  |  |     if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
 | 
		
	
		
			
				|  |  |       next() |  |  |       next() | 
		
	
		
			
				|  |  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |  |       console.log('efdlsdkadjas;dkasdk') | 
		
	
		
			
				|  |  |  |  |  |       next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
 | 
		
	
		
			
				|  |  |       NProgress.done() |  |  |       NProgress.done() | 
		
	
		
			
				|  |  | //   if (getToken()) {
 |  |  |  | 
		
	
		
			
				|  |  | //     // 已登录且要跳转的页面是登录页
 |  |  |  | 
		
	
		
			
				|  |  | //     if (to.path === '/login') {
 |  |  |  | 
		
	
		
			
				|  |  | //       next({ path: '/' })
 |  |  |  | 
		
	
		
			
				|  |  | //       NProgress.done()
 |  |  |  | 
		
	
		
			
				|  |  | //     } else {
 |  |  |  | 
		
	
		
			
				|  |  | //       if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
 |  |  |  | 
		
	
		
			
				|  |  | //         store.dispatch('GetInfo').then(() => { // 拉取user_info
 |  |  |  | 
		
	
		
			
				|  |  | //           // 动态路由,拉取菜单
 |  |  |  | 
		
	
		
			
				|  |  | //           loadMenus(next, to)
 |  |  |  | 
		
	
		
			
				|  |  | //         }).catch(() => {
 |  |  |  | 
		
	
		
			
				|  |  | //           store.dispatch('LogOut').then(() => {
 |  |  |  | 
		
	
		
			
				|  |  | //             location.reload() // 为了重新实例化vue-router对象 避免bug
 |  |  |  | 
		
	
		
			
				|  |  | //           })
 |  |  |  | 
		
	
		
			
				|  |  | //         })
 |  |  |  | 
		
	
		
			
				|  |  | //         // 登录时未拉取 菜单,在此处拉取
 |  |  |  | 
		
	
		
			
				|  |  | //       } else if (store.getters.loadMenus) {
 |  |  |  | 
		
	
		
			
				|  |  | //         // 修改成false,防止死循环
 |  |  |  | 
		
	
		
			
				|  |  | //         store.dispatch('updateLoadMenus')
 |  |  |  | 
		
	
		
			
				|  |  | //         loadMenus(next, to)
 |  |  |  | 
		
	
		
			
				|  |  | //       } else {
 |  |  |  | 
		
	
		
			
				|  |  | //         next()
 |  |  |  | 
		
	
		
			
				|  |  | //       }
 |  |  |  | 
		
	
		
			
				|  |  | //     }
 |  |  |  | 
		
	
		
			
				|  |  | //   } else {
 |  |  |  | 
		
	
		
			
				|  |  | //     /* has no token*/
 |  |  |  | 
		
	
		
			
				|  |  | //     if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
 |  |  |  | 
		
	
		
			
				|  |  | //       next()
 |  |  |  | 
		
	
		
			
				|  |  | //     } else {
 |  |  |  | 
		
	
		
			
				|  |  | //       next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
 |  |  |  | 
		
	
		
			
				|  |  | //       NProgress.done()
 |  |  |  | 
		
	
		
			
				|  |  | //     }
 |  |  |  | 
		
	
		
			
				|  |  | //   }
 |  |  |  | 
		
	
		
			
				|  |  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  |   } | 
		
	
		
			
				|  |  | }) |  |  | }) | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  | export const loadMenus = (next, to) => { |  |  | export const loadMenus = (next, to) => { | 
		
	
		
			
				|  |  |   buildMenus().then(res => { |  |  |   buildMenus().then(res => { | 
		
	
		
			
				|  |  |     const sdata = JSON.parse(JSON.stringify(res)) |  |  |     const sdata = JSON.parse(JSON.stringify(res)) | 
		
	
		
			
				|  |  |     const rdata = JSON.parse(JSON.stringify(res)) |  |  |     const rdata = JSON.parse(JSON.stringify(res)) | 
		
	
		
			
				|  |  |     const sidebarRoutes = filterAsyncRouter(sdata) |  |  |  | 
		
	
		
			
				|  |  |     const rewriteRoutes = filterAsyncRouter(rdata, true) |  |  |  | 
		
	
		
			
				|  |  |  |  |  |     const sidebarRoutes = filterAsyncRouter(sdata.data) | 
		
	
		
			
				|  |  |  |  |  |     const rewriteRoutes = filterAsyncRouter(rdata.data, true) | 
		
	
		
			
				|  |  |     rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true }) |  |  |     rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true }) | 
		
	
		
			
				|  |  | 
 |  |  | 
 | 
		
	
		
			
				|  |  |     store.dispatch('GenerateRoutes', rewriteRoutes).then(() => { // 存储路由
 |  |  |     store.dispatch('GenerateRoutes', rewriteRoutes).then(() => { // 存储路由
 | 
		
	
	
		
			
				|  | 
 |