update
This commit is contained in:
@@ -59,13 +59,13 @@ const routes = [
|
||||
redirect: '/admin',
|
||||
name: '/settings',
|
||||
component: settings,
|
||||
meta:{Authorization:true},
|
||||
|
||||
children: [
|
||||
{
|
||||
path: '/admin',
|
||||
name: '/admin',
|
||||
component: personalHomePage,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
@@ -73,28 +73,28 @@ const routes = [
|
||||
name: '/system',
|
||||
redirect: '/appearance',
|
||||
component: systemSettings,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
children:[
|
||||
{
|
||||
path: '/appearance',
|
||||
name: '/appearance',
|
||||
component: appearanceSettings,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
path: '/information',
|
||||
name: '/information',
|
||||
component: informationSettings,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
path: '/function',
|
||||
name: '/function',
|
||||
component: functionSettings,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
}
|
||||
]
|
||||
@@ -103,7 +103,7 @@ const routes = [
|
||||
path: '/website',
|
||||
name: '/website',
|
||||
component: websiteManage,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
},
|
||||
|
||||
@@ -112,21 +112,21 @@ const routes = [
|
||||
name: '/onSite',
|
||||
redirect:'/baseSettings',
|
||||
component: onSiteSetting,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
children:[
|
||||
{
|
||||
path: '/baseSettings',
|
||||
name: '/baseSettings',
|
||||
component: baseSettings,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
path: '/importExport',
|
||||
name: '/importExport',
|
||||
component: importExport,
|
||||
meta:{Authorization:true},
|
||||
|
||||
|
||||
},
|
||||
]
|
||||
@@ -148,7 +148,8 @@ const routes = [
|
||||
path: '/:pathMatch(.*)',
|
||||
redirect: '/404',
|
||||
hidden: true
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
]
|
||||
@@ -158,39 +159,22 @@ const router = new VueRouter({
|
||||
routes
|
||||
})
|
||||
// // 导航守卫:使用 router.beforeEach 注册一个全局前置守卫,判断用户是否登陆
|
||||
// router.beforeEach((to, from, next) => {
|
||||
// if (to.path === '/home') {
|
||||
// next();
|
||||
// } else {
|
||||
// let token = localStorage.getItem('Authorization');
|
||||
// if (token === null || token === '') {
|
||||
// next('/home');
|
||||
// } else {
|
||||
// next();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// 全局路由构造函数,判断是否登录和要跳转到页面
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.matched.some(m => m.meta.requiresAuth)) { // 需要登录
|
||||
if(window.localStorage.Authorization && window.localStorage.isLogin === '1'){
|
||||
next()
|
||||
} else if (to.path !== '/home') {
|
||||
let token = localStorage.getItem('Authorization');
|
||||
if (token === 'null' || token === '' || token === undefined){
|
||||
next({path: '/home'})
|
||||
// Toast({ message: '检测到您还未登录,请登录后操作!', duration: 1500 })
|
||||
Vue.prototype.$notify.error({
|
||||
if (to.path === '/home') {
|
||||
next();
|
||||
} else {
|
||||
let token = localStorage.getItem('Authorization');
|
||||
if (token === null || token === '' || token === undefined) {
|
||||
next('/home');
|
||||
Vue.prototype.$notify.error({
|
||||
title: '权限不够',
|
||||
message: "请先登录!",
|
||||
offset: 0
|
||||
});
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
next();
|
||||
}
|
||||
} else { // 不需要登录
|
||||
next()
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
export default router
|
||||
|
Reference in New Issue
Block a user