ソースを参照

解决退出后点击浏览器回退按钮又登录的问题

zhangliang2 2 年 前
コミット
e56b1eaad3

+ 11 - 4
src/axios/filter.js

@@ -1,6 +1,7 @@
 import axios from 'axios'
 import VueAxios from 'vue-axios'
 import Vue from 'vue'
+import router from '../router'
 import ElementUI, {
     Loading
 } from 'element-ui';
@@ -85,8 +86,11 @@ axios.interceptors.response.use(function (response) {
             ElementUI.MessageBox.alert('用户信息过期,请重新登陆', '提示', {
                 confirmButtonText: '确定',
                 callback: action => {
-                    let loginUrl = window.location.origin + '/login'
-                    window.location.href = loginUrl
+                    // let loginUrl = window.location.origin + '/login'
+                    // window.location.href = loginUrl
+                    router.push({
+                        path: "/login"
+                    })
                 }
             })
             setTimeout(() => {
@@ -148,8 +152,11 @@ instance.interceptors.response.use(function (response) {
             ElementUI.MessageBox.alert('用户信息过期,请重新登陆', '提示', {
                 confirmButtonText: '确定',
                 callback: action => {
-                    let loginUrl = window.location.origin + '/login'
-                    window.location.href = loginUrl
+                    // let loginUrl = window.location.origin + '/login'
+                    // window.location.href = loginUrl
+                    router.push({
+                        path: "/login"
+                    })
                 }
             })
             setTimeout(() => {

+ 8 - 4
src/router/algorithmsLibrary.js

@@ -3,7 +3,8 @@ export default [{
         name: "algorithmsLibraryList",
         meta: {
             tabname: "算法库列表",
-            menuKind: "algorithmsLibrary"
+            menuKind: "algorithmsLibrary",
+            login: true
         },
         component: () => import("@/views/algorithmsLibrary/algorithmsLibraryList")
     },
@@ -12,7 +13,8 @@ export default [{
         name: "gitAlgorithms",
         meta: {
             tabname: "仓库算法",
-            menuKind: "algorithmsLibrary"
+            menuKind: "algorithmsLibrary",
+            login: true
         },
         component: () => import("@/views/algorithmsLibrary/gitAlgorithms")
     },
@@ -21,7 +23,8 @@ export default [{
         name: "exportAlgorithms",
         meta: {
             tabname: "导入算法",
-            menuKind: "algorithmsLibrary"
+            menuKind: "algorithmsLibrary",
+            login: true
         },
         component: () => import("@/views/algorithmsLibrary/exportAlgorithms")
     },
@@ -30,7 +33,8 @@ export default [{
         name: "algorithmsPlatformList",
         meta: {
             tabname: "平台算法",
-            menuKind: "algorithmsLibrary"
+            menuKind: "algorithmsLibrary",
+            login: true
         },
         component: () => import("@/views/algorithmsLibrary/algorithmsPlatformList")
     },

+ 19 - 9
src/router/filter.js

@@ -9,8 +9,6 @@ Router.prototype.push = function push(location) {
 
 
 router.beforeEach((to, from, next) => {
-    console.log(from);
-    console.log(to);
     if (to.fullPath === '/' || to.name === '*') {
         let {
             code,
@@ -27,18 +25,30 @@ router.beforeEach((to, from, next) => {
                 replace: true
             });
         } else {
-            next({
-                path: "/mainPage",
-                replace: true
-            });
+            if (to.meta.login) {
+                if (localStorage.getItem('Authorization')) {
+                    next({
+                        path: "/mainPage",
+                    });
+                } else {
+                    next({
+                        path: "/login",
+                    });
+                }
+            } else {
+                next({
+                    path: "/mainPage",
+                });
+            }
         }
     } else {
-        if (from.path === '/login' || from.name === 'login') {
+        if (to.meta.login) {
             if (localStorage.getItem('Authorization')) {
                 next();
             } else {
-                next(false);
-                // return false
+                next({
+                    path: "/login",
+                });
             }
         } else {
             next();

+ 16 - 9
src/router/index.js

@@ -27,16 +27,18 @@ const routes = [{
       {
         path: "/mainPage",
         name: "mainPage",
-        // meta: {
-        //   tabname: "首页"
-        // },
+        meta: {
+          // tabname: "首页"
+          login: true
+        },
         component: () => import("@/views/mainPage.vue")
       },
       {
         path: "/modelLibrary",
         name: "modelLibrary",
         meta: {
-          tabname: "模型库"
+          tabname: "模型库",
+          login: true
         },
         component: () => import("@/views/modelLibrary/index"),
         redirect: '/index',
@@ -46,7 +48,8 @@ const routes = [{
         path: "/algorithmsLibrary",
         name: "algorithmsLibrary",
         meta: {
-          tabname: "算法库"
+          tabname: "算法库",
+          login: true
         },
         component: () => import("@/views/algorithmsLibrary/index"),
         redirect: '/index',
@@ -56,7 +59,8 @@ const routes = [{
         path: "/sceneLibrary",
         name: "sceneLibrary",
         meta: {
-          tabname: "场景库"
+          tabname: "场景库",
+          login: true
         },
         component: () => import("@/views/sceneLibrary/index"),
         redirect: '/index',
@@ -66,7 +70,8 @@ const routes = [{
         path: "/workManagement",
         name: "workManagement",
         meta: {
-          tabname: "工作管理"
+          tabname: "工作管理",
+          login: true
         },
         component: () => import("@/views/workManagement/index"),
         redirect: '/index',
@@ -76,7 +81,8 @@ const routes = [{
         path: "/systemManagement",
         name: "systemManagement",
         meta: {
-          tabname: "系统管理"
+          tabname: "系统管理",
+          login: true
         },
         component: () => import("@/views/systemManagement/index"),
         redirect: '/index',
@@ -86,7 +92,8 @@ const routes = [{
         path: "/personalInformation",
         name: "personalInformation",
         meta: {
-          tabname: "个人信息"
+          tabname: "个人信息",
+          login: true
         },
         component: () => import("@/views/personalInformation/personalInformation"),
         // redirect: '/index',

+ 8 - 4
src/router/modelLibrary.js

@@ -3,7 +3,8 @@ export default [{
         name: "vehicleConfigurationList",
         meta: {
             tabname: "车辆配置列表",
-            menuKind: "modelLibrary"
+            menuKind: "modelLibrary",
+            login: true
         },
         component: () => import("@/views/modelLibrary/vehicleConfigurationList")
     },
@@ -12,7 +13,8 @@ export default [{
         name: "vehicleConfigurationDetail",
         meta: {
             tabname: "车辆配置详情",
-            menuKind: "modelLibrary"
+            menuKind: "modelLibrary",
+            login: true
         },
         component: () => import("@/views/modelLibrary/vehicleConfigurationDetail")
     },
@@ -21,7 +23,8 @@ export default [{
         name: "sensorModel",
         meta: {
             tabname: "传感器模型",
-            menuKind: "modelLibrary"
+            menuKind: "modelLibrary",
+            login: true
         },
         component: () => import("@/views/modelLibrary/sensorModel")
     },
@@ -30,7 +33,8 @@ export default [{
         name: "vehicleModel",
         meta: {
             tabname: "车辆模型",
-            menuKind: "modelLibrary"
+            menuKind: "modelLibrary",
+            login: true
         },
         component: () => import("@/views/modelLibrary/vehicleModel")
     },

+ 2 - 1
src/router/personalInformation.js

@@ -3,7 +3,8 @@ export default [{
     name: "personalInformation",
     meta: {            
         tabname: "个人信息",
-        menuKind: "personalInformation"
+        menuKind: "personalInformation",
+        login: true
     },        
     component: () => import("@/views/personalInformation/personalInformation")
 }]      

+ 16 - 8
src/router/sceneLibrary.js

@@ -3,7 +3,8 @@ export default [{
         name: "naturalDrivingScenarioList",
         meta: {
             tabname: "自然驾驶场景",
-            menuKind: "sceneLibrary"
+            menuKind: "sceneLibrary",
+            login: true
         },
         component: () => import("@/views/sceneLibrary/naturalDrivingScenarioList")
     },
@@ -12,7 +13,8 @@ export default [{
         name: "standardRegulationSimulationScenarioList",
         meta: {
             tabname: "标准法规仿真场景",
-            menuKind: "sceneLibrary"
+            menuKind: "sceneLibrary",
+            login: true
         },
         component: () => import("@/views/sceneLibrary/standardRegulationSimulationScenarioList")
     },
@@ -21,7 +23,8 @@ export default [{
         name: "trafficAccidentSimulationScenarioList",
         meta: {
             tabname: "交通事故仿真场景",
-            menuKind: "sceneLibrary"
+            menuKind: "sceneLibrary",
+            login: true
         },
         component: () => import("@/views/sceneLibrary/trafficAccidentSimulationScenarioList")
     },
@@ -30,7 +33,8 @@ export default [{
         name: "generalizationScenarioList",
         meta: {
             tabname: "泛化场景模板",
-            menuKind: "sceneLibrary"
+            menuKind: "sceneLibrary",
+            login: true
         },
         component: () => import("@/views/sceneLibrary/generalizationScenarioList")
     },
@@ -39,7 +43,8 @@ export default [{
         name: "scenarioTestPackageManagementList",
         meta: {
             tabname: "场景测试包管理",
-            menuKind: "sceneLibrary"
+            menuKind: "sceneLibrary",
+            login: true
         },
         component: () => import("@/views/sceneLibrary/scenarioTestPackageManagementList")
     },
@@ -48,7 +53,8 @@ export default [{
         name: "scenePacketList",
         meta: {
             tabname: "场景数据包",
-            menuKind: "sceneLibrary"
+            menuKind: "sceneLibrary",
+            login: true
         },
         component: () => import("@/views/sceneLibrary/scenePacketList")
     },
@@ -57,7 +63,8 @@ export default [{
         name: "gradingRulesList",
         meta: {
             tabname: "评分规则列表",
-            menuKind: "sceneLibrary"
+            menuKind: "sceneLibrary",
+            login: true
         },
         component: () => import("@/views/sceneLibrary/gradingRulesList")
     },
@@ -66,7 +73,8 @@ export default [{
         name: "gradingRule",
         meta: {
             tabname: "评分规则",
-            menuKind: "sceneLibrary"
+            menuKind: "sceneLibrary",
+            login: true
         },
         component: () => import("@/views/sceneLibrary/gradingRule")
     },

+ 41 - 21
src/router/systemManagement.js

@@ -3,7 +3,8 @@ export default [{
         name: "accountManagement",
         meta: {
             tabname: "账户管理",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/accountManagement")
     },
@@ -12,7 +13,8 @@ export default [{
         name: "addAccount",
         meta: {
             tabname: "新增账户",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/addAccount")
     },
@@ -21,7 +23,8 @@ export default [{
         name: "editAccount",
         meta: {
             tabname: "编辑账户",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/editAccount")
     },
@@ -30,7 +33,8 @@ export default [{
         name: "paramenterManagement",
         meta: {
             tabname: "参数管理",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/parameterManagement")
     },
@@ -39,7 +43,8 @@ export default [{
         name: "parameterDetail",
         meta: {
             tabname: "编辑参数配置",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/parameterDetail")
     },
@@ -48,7 +53,8 @@ export default [{
         name: "clusteringManagement",
         meta: {
             tabname: "集群管理",
-            menuKind: "sysyemManagement"
+            menuKind: "sysyemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/clusteringManagement")
     },
@@ -57,7 +63,8 @@ export default [{
         name: "clusteringDetail",
         meta: {
             tabname: "编辑集群配置",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/clusteringDetail")
     },
@@ -66,7 +73,8 @@ export default [{
         name: "sceneLibraryManagement",
         meta: {
             tabname: "场景库管理",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/sceneLibraryManagement/sceneLibraryManagement")
     },
@@ -75,7 +83,8 @@ export default [{
         name: "scenePacketListManagement",
         meta: {
             tabname: "场景包管理",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/scenePacketListManagement/index")
     },
@@ -84,7 +93,8 @@ export default [{
         name: "scenePacketDetail",
         meta: {
             tabname: "场景包详情",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/scenePacketListManagement/detail")
     },
@@ -93,7 +103,8 @@ export default [{
         name: "scenePacketDistributionList",
         meta: {
             tabname: "场景包分配",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/scenePacketDistributionList")
     },
@@ -102,7 +113,8 @@ export default [{
         name: "scenePacketDistributionDetail",
         meta: {
             tabname: "场景包分配详情",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/scenePacketDistributionDetail")
     },
@@ -111,7 +123,8 @@ export default [{
         name: "sceneUploadList",
         meta: {
             tabname: "场景上传",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/sceneUploadList")
     },
@@ -120,7 +133,8 @@ export default [{
         name: "vehicleModelManagement",
         meta: {
             tabname: "车辆设置列表",
-            menuKind: "vehicleModelManagement"
+            menuKind: "vehicleModelManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/vehicleModelManagement")
     },
@@ -129,7 +143,8 @@ export default [{
         name: "vehicleModelDetail",
         meta: {
             tabname: "车辆设置详情",
-            menuKind: "vehicleModelDetail"
+            menuKind: "vehicleModelDetail",
+            login: true
         },
         component: () => import("@/views/systemManagement/vehicleModelDetail")
     },
@@ -138,7 +153,8 @@ export default [{
         name: "reportTemplateManagement",
         meta: {
             tabname: "报告模板管理",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/reportTemplateManagement")
     },
@@ -146,7 +162,7 @@ export default [{
         path: "/reportTemplateDetail",
         name: "reportTemplateDetail",
         meta: {
-
+            login: true
         },
         component: () => import("@/views/systemManagement/reportTemplateDetail")
     },
@@ -155,7 +171,8 @@ export default [{
         name: "loginLogManagement",
         meta: {
             tabname: "登录日志",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/loginLogManagement")
     },
@@ -164,7 +181,8 @@ export default [{
         name: "handleLogManagement",
         meta: {
             tabname: "操作日志",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/handleLogManagement")
     },
@@ -173,7 +191,8 @@ export default [{
         name: "systemLogManagement",
         meta: {
             tabname: "系统日志",
-            menuKind: "systemManagement"
+            menuKind: "systemManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/systemLogManagement")
     }
@@ -183,7 +202,8 @@ export default [{
         name: "dictManagement",
         meta: {
             tabname: "日志管理",
-            menuKind: "dictManagement"
+            menuKind: "dictManagement",
+            login: true
         },
         component: () => import("@/views/systemManagement/dictManagement")
     }

+ 22 - 11
src/router/workManagement.js

@@ -3,7 +3,8 @@ export default [{
         name: "manualRunProjectList",
         meta: {
             tabname: "手动运行项目列表",
-            menuKind: "workManagement"
+            menuKind: "workManagement",
+            login: true
         },
         component: () => import("@/views/workManagement/manualRunProjectList"),
         children: [{
@@ -11,7 +12,8 @@ export default [{
             name: "projectInfo",
             meta: {
                 tabname: "项目详情",
-                menuKind: "workManagement"
+                menuKind: "workManagement",
+                login: true
             },
             component: () => import("@/views/workManagement/projectInfo"),
             children: [{
@@ -19,7 +21,8 @@ export default [{
                     name: "taskInfo",
                     meta: {
                         tabname: "任务详情",
-                        menuKind: "workManagement"
+                        menuKind: "workManagement",
+                        login: true
                     },
                     component: () => import("@/views/workManagement/taskInfo")
                 },
@@ -28,7 +31,8 @@ export default [{
                     name: "evaluationReport",
                     meta: {
                         tabname: "评价报告",
-                        menuKind: "workManagement"
+                        menuKind: "workManagement",
+                        login: true
                     },
                     component: () => import("@/views/workManagement/evaluationReport")
                 },
@@ -40,7 +44,8 @@ export default [{
         name: "manualRunProjectDetail",
         meta: {
             tabname: "手动运行项目",
-            menuKind: "workManagement"
+            menuKind: "workManagement",
+            login: true
         },
         component: () => import("@/views/workManagement/manualRunProjectDetail")
     },
@@ -49,7 +54,8 @@ export default [{
         name: "autoRunProjectList",
         meta: {
             tabname: "自动运行项目列表",
-            menuKind: "workManagement"
+            menuKind: "workManagement",
+            login: true
         },
         component: () => import("@/views/workManagement/autoRunProjectList"),
         children: [{
@@ -57,7 +63,8 @@ export default [{
             name: "autoRunSubProjectList",
             meta: {
                 tabname: "自动运行子项目列表",
-                menuKind: "workManagement"
+                menuKind: "workManagement",
+                login: true
             },
             component: () => import("@/views/workManagement/autoRunSubProjectList"),
             children: [{
@@ -65,7 +72,8 @@ export default [{
                 name: "projectInfo",
                 meta: {
                     tabname: "项目详情",
-                    menuKind: "workManagement"
+                    menuKind: "workManagement",
+                    login: true
                 },
                 component: () => import("@/views/workManagement/projectInfo"),
                 children: [{
@@ -73,7 +81,8 @@ export default [{
                         name: "taskInfo",
                         meta: {
                             tabname: "任务详情",
-                            menuKind: "workManagement"
+                            menuKind: "workManagement",
+                            login: true
                         },
                         component: () => import("@/views/workManagement/taskInfo")
                     },
@@ -82,7 +91,8 @@ export default [{
                         name: "evaluationReport",
                         meta: {
                             tabname: "评价报告",
-                            menuKind: "workManagement"
+                            menuKind: "workManagement",
+                            login: true
                         },
                         component: () => import("@/views/workManagement/evaluationReport")
                     },
@@ -95,7 +105,8 @@ export default [{
         name: "autoRunProjectDetail",
         meta: {
             tabname: "自动运行项目",
-            menuKind: "workManagement"
+            menuKind: "workManagement",
+            login: true
         },
         component: () => import("@/views/workManagement/autoRunProjectDetail")
     },

+ 9 - 0
src/views/login.vue

@@ -131,6 +131,15 @@ export default {
     mounted() {
         localStorage.clear();
     },
+
+    beforeRouteLeave (to, from, next) {
+        if (!localStorage.getItem('Authorization')) {
+            // alert(666)
+            return false;
+        }else {
+            next()
+        }
+    }
 };
 </script>
 

+ 6 - 3
src/views/page/breadCrumb.vue

@@ -69,8 +69,11 @@ export default {
             })
                 .then(() => {
                     localStorage.clear();
-                    let loginUrl = window.location.origin + "/login";
-                    window.location.href = loginUrl;
+                    // let loginUrl = window.location.origin + "/login";
+                    // window.location.href = loginUrl;
+                    this.$router.push({
+                        path: "/login",
+                    });
                 })
                 .catch(() => {});
         },
@@ -172,7 +175,7 @@ export default {
             font-size: 30px;
             cursor: pointer;
         }
-        
+
         .exit:hover {
             color: @themeColor;
         }

+ 5 - 2
src/views/page/pageMenu.vue

@@ -313,8 +313,11 @@ export default {
                 } else {
                     if (res.code == 400) {
                         //refreshToken请求返回400则跳回登录页
-                        let loginUrl = window.location.origin + "/login";
-                        window.location.href = loginUrl;
+                        // let loginUrl = window.location.origin + "/login";
+                        // window.location.href = loginUrl;
+                        this.$router.push({
+                            path: "/login",
+                        });
                     }
                 }
             });