|
|
@@ -132,18 +132,21 @@ const router = new Router({
|
|
|
{
|
|
|
path: '/index',
|
|
|
name: '首页',
|
|
|
+ meta: { requiresAuth: true },
|
|
|
component: () => import('@/pages/index/index')
|
|
|
},
|
|
|
|
|
|
{
|
|
|
path: '/login',
|
|
|
name: '登录页',
|
|
|
+ meta: { requiresAuth: true },
|
|
|
component: () => import('@/pages/login')
|
|
|
},
|
|
|
|
|
|
{
|
|
|
path: '/403',
|
|
|
name: '403',
|
|
|
+ meta: { requiresAuth: true },
|
|
|
component: () => import('@/pages/exception/403'),
|
|
|
},
|
|
|
|
|
|
@@ -160,16 +163,24 @@ router.beforeEach(async (to, from, next) => {
|
|
|
// let token = getToken()
|
|
|
// let userName = sessionStorage.getItem('user')
|
|
|
// let userName = Cookies.get('user')
|
|
|
+
|
|
|
+ // if (to.path != from.path) {
|
|
|
+ // // next({ path: '/index' })
|
|
|
+ // } else {
|
|
|
+ // next()
|
|
|
+ // }
|
|
|
+
|
|
|
await store.dispatch('setting/getUserLogin')
|
|
|
|
|
|
|
|
|
let userInfo = store.state.setting.userInfo
|
|
|
+ console.log(to)
|
|
|
// let token = Cookies.get('Authorization')
|
|
|
|
|
|
- if (to.matched.some(record => record.meta.requiresAuth)) {
|
|
|
-
|
|
|
- next()
|
|
|
- return
|
|
|
+ if (!to.matched.some(record => record.meta.requiresAuth)) {
|
|
|
+ next("/index")
|
|
|
+ // next()
|
|
|
+ // return
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -203,7 +214,7 @@ router.beforeEach(async (to, from, next) => {
|
|
|
window.location.href = process.env.VUE_APP_BASE_URL + "/#/login"
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ // if (to.meta.requiresAuth)
|
|
|
if (hasRoles) {
|
|
|
// console.log(13)
|
|
|
addDynamicMenuAndRoutes(menuData, to, next)
|
|
|
@@ -216,6 +227,18 @@ router.beforeEach(async (to, from, next) => {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ // const requiresAuth =router.getRoutes().some(record => record.meta.requiresAuth);
|
|
|
+ // router.getRoutes().forEach((v) => {
|
|
|
+
|
|
|
+ // if (to.path === v.path) {
|
|
|
+ // // next({ to, replace: true })
|
|
|
+ // return
|
|
|
+ // } else {
|
|
|
+ // // next("/index")
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -305,7 +328,8 @@ function addDynamicRoutes(menuList = [],) {
|
|
|
name: menuList[i].name,
|
|
|
meta: {
|
|
|
icon: menuList[i].icon,
|
|
|
- index: menuList[i].id
|
|
|
+ index: menuList[i].id,
|
|
|
+
|
|
|
},
|
|
|
component: PageView,
|
|
|
|
|
|
@@ -319,7 +343,8 @@ function addDynamicRoutes(menuList = [],) {
|
|
|
name: menuList[i].name,
|
|
|
meta: {
|
|
|
icon: menuList[i].icon,
|
|
|
- index: menuList[i].id
|
|
|
+ index: menuList[i].id,
|
|
|
+
|
|
|
},
|
|
|
children: []
|
|
|
})
|
|
|
@@ -335,7 +360,8 @@ function addDynamicRoutes(menuList = [],) {
|
|
|
mulu = {
|
|
|
path: menuList[i].url,
|
|
|
name: menuList[i].name,
|
|
|
- // meta: { invisible: menuList[i].name == '团队管理' ? false : true },
|
|
|
+ meta: { requiresAuth: true },
|
|
|
+
|
|
|
// hidden: true,
|
|
|
component: resolve => require([`@/` + `pages/${parentPath}/${url}`], resolve),
|
|
|
|