v1.6 版本发布 ,详情查看版本说明
This commit is contained in:
@@ -11,6 +11,9 @@ NProgress.configure({ showSpinner: false })// NProgress Configuration
|
||||
const whiteList = ['/login']// no redirect whitelist
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.meta.title) {
|
||||
document.title = to.meta.title + ' - eladmin'
|
||||
}
|
||||
NProgress.start() // start progress bar
|
||||
if (getToken()) {
|
||||
// 已登录且要跳转的页面是登录页
|
||||
@@ -20,20 +23,19 @@ router.beforeEach((to, from, next) => {
|
||||
} else {
|
||||
if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
|
||||
store.dispatch('GetInfo').then(res => { // 拉取user_info
|
||||
buildMenus().then(res => {
|
||||
const asyncRouter = filterAsyncRouter(res)
|
||||
asyncRouter.push({ path: '*', redirect: '/404', hidden: true })
|
||||
store.dispatch('GenerateRoutes', asyncRouter).then(() => { // 存储路由
|
||||
router.addRoutes(asyncRouter) // 动态添加可访问路由表
|
||||
next({ ...to, replace: true })// hack方法 确保addRoutes已完成
|
||||
})
|
||||
})
|
||||
// 动态路由,拉取菜单
|
||||
loadMenus(next, to)
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
store.dispatch('LogOut').then(() => {
|
||||
location.reload() // 为了重新实例化vue-router对象 避免bug
|
||||
})
|
||||
})
|
||||
// 登录时未拉取 菜单,在此处拉取
|
||||
} else if (store.getters.loadMenus) {
|
||||
// 修改成false,防止死循环
|
||||
store.dispatch('updateLoadMenus').then(res => {})
|
||||
loadMenus(next, to)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
@@ -49,6 +51,17 @@ router.beforeEach((to, from, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
export const loadMenus = (next, to) => {
|
||||
buildMenus().then(res => {
|
||||
const asyncRouter = filterAsyncRouter(res)
|
||||
asyncRouter.push({ path: '*', redirect: '/404', hidden: true })
|
||||
store.dispatch('GenerateRoutes', asyncRouter).then(() => { // 存储路由
|
||||
router.addRoutes(asyncRouter) // 动态添加可访问路由表
|
||||
next({ ...to, replace: true })// hack方法 确保addRoutes已完成
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
router.afterEach(() => {
|
||||
NProgress.done() // finish progress bar
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user