update 路由隐藏
This commit is contained in:
@@ -29,7 +29,7 @@ export const pageRoutes = [
|
||||
meta: { title: '登录' },
|
||||
beforeEnter(to, from, next) {
|
||||
if (Cookies.get('token')) {
|
||||
Vue.prototype.$message({ message:'已经登录过了', type: 'error' })
|
||||
Vue.prototype.$message({ message: '已经登录过了', type: 'error' })
|
||||
next(false)
|
||||
} else {
|
||||
next()
|
||||
@@ -91,6 +91,7 @@ router.beforeEach((to, from, next) => {
|
||||
if (window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] || fnCurrentRouteIsPageRoute(to, pageRoutes)) {
|
||||
return next()
|
||||
}
|
||||
|
||||
// 获取字典列表, 添加并全局变量保存
|
||||
http.get(http.adornUrl('/sys/dict/type/all')).then(({ data: res }) => {
|
||||
if (res.code !== 0) {
|
||||
@@ -98,20 +99,15 @@ router.beforeEach((to, from, next) => {
|
||||
}
|
||||
window.SITE_CONFIG['dictList'] = res.data
|
||||
}).catch((err) => {
|
||||
// console.log("catch /sys/dict/type/all", err)
|
||||
})
|
||||
// 获取菜单列表, 添加并全局变量保存
|
||||
http.get(http.adornUrl('/sys/menu/nav')).then(({ data: res }) => {
|
||||
if (res.code !== 0) {
|
||||
Vue.prototype.$message.error(res.msg)
|
||||
return next({ name: 'login' })
|
||||
}
|
||||
console.log('menulist: ', res.data)
|
||||
/** axios 的拦截器已经拦截出错情况,此处只考虑正确情况即可 */
|
||||
window.SITE_CONFIG['menuList'] = res.data
|
||||
fnAddDynamicMenuRoutes(window.SITE_CONFIG['menuList'])
|
||||
next({ ...to, replace: true })
|
||||
}).catch((err) => {
|
||||
next({ name: 'login' })
|
||||
// Vue.prototype.$message.error(err)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -140,6 +136,7 @@ function fnCurrentRouteIsPageRoute(route, pageRoutes = []) {
|
||||
*/
|
||||
function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
|
||||
var temp = []
|
||||
|
||||
for (var i = 0; i < menuList.length; i++) {
|
||||
if (menuList[i].children && menuList[i].children.length >= 1) {
|
||||
temp = temp.concat(menuList[i].children)
|
||||
@@ -168,9 +165,11 @@ function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
|
||||
}
|
||||
routes.push(route)
|
||||
}
|
||||
|
||||
if (temp.length >= 1) {
|
||||
return fnAddDynamicMenuRoutes(temp, routes)
|
||||
}
|
||||
|
||||
// 添加路由
|
||||
router.addRoutes([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user