|
@@ -14,6 +14,7 @@ VueRouter.prototype.replace = function replace(location) {
|
|
|
// 公共页面
|
|
|
import main from '@views/main'
|
|
|
import error404 from '@views/404'
|
|
|
+import login from '@views/login'
|
|
|
|
|
|
// 子路由
|
|
|
import yRouter from '@router/ylf';
|
|
@@ -47,6 +48,14 @@ const routes = [
|
|
|
name: 'error404',
|
|
|
component: error404,
|
|
|
},
|
|
|
+ {
|
|
|
+ path: '/login', // 页面不存在的情况下会跳到404页面
|
|
|
+ meta: {
|
|
|
+ requireAuth: true, // 添加该字段,表示进入这个路由是需要登录的 /进路由勾子函数beforeEach
|
|
|
+ },
|
|
|
+ name: 'login',
|
|
|
+ component: login,
|
|
|
+ }
|
|
|
// { // 健康评价报告 - 临时 /部署单页面
|
|
|
// path:'/healthAssessmentDetailed2',
|
|
|
// component: r => require.ensure([], () => r(require('@views/healthManagement/healthAssessmentDetailed')), 'healthManagement')
|
|
@@ -63,30 +72,27 @@ const router = new VueRouter({
|
|
|
* 路由的钩子函数,处理是否登录的判断
|
|
|
* **/
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
- // 路由地址不存在的处理办法
|
|
|
+ // 路由地址不存在的处理办法
|
|
|
+
|
|
|
+ if (to.matched.some(m => m.meta.requireAuth)) { // 需要登录
|
|
|
+ // if(window.localStorage.token && window.localStorage.isLogin === '1'){
|
|
|
+ // next()
|
|
|
+ // } else
|
|
|
+ if (to.path !== '/login') {
|
|
|
+ let token = window.localStorage.token;
|
|
|
+ if (token === 'null' || token === '' || token === undefined){
|
|
|
+ next()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ next()
|
|
|
+ }
|
|
|
+ } else { // 不需要登录
|
|
|
+ next()
|
|
|
+ }
|
|
|
if (to.matched.length === 0) { // 如果未匹配到路由
|
|
|
// sessionStorage.removeItem("btrh_sxsd_locationHref");
|
|
|
next('/404') // 如果上级也未匹配到路由则跳转登录页面,如果上级能匹配到则转上级路由
|
|
|
}
|
|
|
-
|
|
|
- if (to.matched.some(r => r.meta.requireAuth)) {
|
|
|
-
|
|
|
- let userinfo = JSON.parse(sessionStorage.getItem("btrh_sxsd_userinfo"));
|
|
|
- userinfo = "";
|
|
|
- if(userinfo !== null){
|
|
|
- // if(to.path !== "/"){
|
|
|
- // // 判断当前菜单是否有权限打开,如果无权限,自动退出
|
|
|
- // routerCheck(userinfo.roleId, to.path, next);
|
|
|
- // }else{
|
|
|
- // next();
|
|
|
- // }
|
|
|
- next();
|
|
|
- return;
|
|
|
- }
|
|
|
- next("/login");
|
|
|
- } else {
|
|
|
- next();
|
|
|
- }
|
|
|
})
|
|
|
|
|
|
export default router
|