Przeglądaj źródła

路由错误时,重定向404页面

ming 3 lat temu
rodzic
commit
6c157c4618

+ 0 - 2
src/api/systemManage/userManage.js

@@ -38,8 +38,6 @@ export function userUpdate(params) {
     })
 }
 
-
-
 // 角色-回显
 export function authRole(params, userId) {
     return request({

+ 100 - 98
src/router/index.js

@@ -2,32 +2,34 @@ import { createRouter, createWebHashHistory } from 'vue-router'
 import Layout from '@/layout'
 
 export const constantRoutes = [{
-    path: '/login',
-    component: () =>
-        import('@/views/login'),
-    hidden: true,
-},
-{
-    path: '/403',
-    name: '403',
-    component: () =>
-        import('@/views/403'),
-    hidden: true,
-},
-{
-    path: '/404',
-    name: '404',
-    component: () =>
-        import('@/views/404'),
-    hidden: true,
-},
-{
-    path: '/401',
-    name: '401',
-    component: () =>
-        import('@/views/401'),
-    hidden: true,
-},
+        path: '/login',
+        component: () =>
+            import ('@/views/login'),
+        hidden: true,
+    },
+    {
+        path: '/403',
+        name: '403',
+        component: () =>
+            import ('@/views/403'),
+        hidden: true,
+    },
+
+    {
+        path: '/401',
+        name: '401',
+        component: () =>
+            import ('@/views/401'),
+        hidden: true,
+    },
+    {
+        path: '/404',
+        name: '404',
+        component: () =>
+            import ('@/views/404'),
+        hidden: true,
+    },
+    // { path: '*', redirect: '/404', hidden: true }
 ]
 export const asyncRoutes = [
 
@@ -79,8 +81,8 @@ export const asyncRoutes = [
             },
             path: '/alarmManage/index',
             component: () =>
-                import('@/views/alarmManage/index'),
-        },]
+                import ('@/views/alarmManage/index'),
+        }, ]
     },
     // {
     //     path: '/alarmManage',
@@ -118,7 +120,7 @@ export const asyncRoutes = [
             },
             path: '/siteManage',
             component: () =>
-                import('@/views/siteManage/index'),
+                import ('@/views/siteManage/index'),
             hidden: true
         }]
     },
@@ -138,7 +140,7 @@ export const asyncRoutes = [
             },
             path: '/stationManage',
             component: () =>
-                import('@/views/stationManage/index'),
+                import ('@/views/stationManage/index'),
             hidden: true
         }]
     },
@@ -166,7 +168,7 @@ export const asyncRoutes = [
             },
             path: '/deviceManage',
             component: () =>
-                import('@/views/deviceManage/powerEquip'),
+                import ('@/views/deviceManage/powerEquip'),
             hidden: true
         }]
     },
@@ -209,38 +211,38 @@ export const asyncRoutes = [
         component: Layout,
         redirect: '/dataManage/sameAnalysis/index',
         children: [{
-            meta: { icon: 'sameAnalysis', title: '同比分析报表', },
-            path: 'sameAnalysis',
-            component: () =>
-                import('@/views/dataManage/sameAnalysis/index'),
-        },
-        {
-            meta: { icon: 'chainAnalysis', title: '环比分析报表', },
-            path: 'chainAnalysis',
-            component: () =>
-                import('@/views/dataManage/chainAnalysis/index'),
-        },
-        // {
-        //     meta: { icon: 'handOpera', title: '手动抄表', },
-        //     title: 'index-layout.menu.dataManage.handOpera',
-        //     path: 'handOpera',
-        //     component: () =>
-        //         import ('@/views/dataManage/handOpera/index.vue'),
-        // },
-        {
-            meta: { icon: 'energyReport', title: '用能月报', },
-            title: 'index-layout.menu.dataManage.energyReport',
-            path: 'energyReport',
-            component: () =>
-                import('@/views/dataManage/energyReport/index'),
-        },
-        {
-            meta: { icon: 'demandAnalysis', title: '需量分析', },
-            title: 'index-layout.menu.dataManage.demandAnalysis',
-            path: 'demandAnalysis',
-            component: () =>
-                import('@/views/dataManage/demandAnalysis/index'),
-        },
+                meta: { icon: 'sameAnalysis', title: '同比分析报表', },
+                path: 'sameAnalysis',
+                component: () =>
+                    import ('@/views/dataManage/sameAnalysis/index'),
+            },
+            {
+                meta: { icon: 'chainAnalysis', title: '环比分析报表', },
+                path: 'chainAnalysis',
+                component: () =>
+                    import ('@/views/dataManage/chainAnalysis/index'),
+            },
+            // {
+            //     meta: { icon: 'handOpera', title: '手动抄表', },
+            //     title: 'index-layout.menu.dataManage.handOpera',
+            //     path: 'handOpera',
+            //     component: () =>
+            //         import ('@/views/dataManage/handOpera/index.vue'),
+            // },
+            {
+                meta: { icon: 'energyReport', title: '用能月报', },
+                title: 'index-layout.menu.dataManage.energyReport',
+                path: 'energyReport',
+                component: () =>
+                    import ('@/views/dataManage/energyReport/index'),
+            },
+            {
+                meta: { icon: 'demandAnalysis', title: '需量分析', },
+                title: 'index-layout.menu.dataManage.demandAnalysis',
+                path: 'demandAnalysis',
+                component: () =>
+                    import ('@/views/dataManage/demandAnalysis/index'),
+            },
             // {
             //     meta: { icon: 'consumConfig', title: '能耗分析配置', },
             //     title: 'index-layout.menu.dataManage.consumConfig',
@@ -264,29 +266,29 @@ export const asyncRoutes = [
         component: Layout,
         redirect: '/powerQuality/harmonicReport/index',
         children: [{
-            meta: { icon: 'harmonicReport', title: '谐波报表', },
-            path: 'harmonicReport',
-            component: () =>
-                import('@/views/powerQuality/harmonicReport/index'),
-        },
-        {
-            meta: { icon: 'realTimeMonitoring', title: '实时监测' },
-            path: 'realTimeMonitoring',
-            component: () =>
-                import('@/views/powerQuality/realTimeMonitoring/index'),
-        },
-        {
-            meta: { icon: 'asseReport', title: '评估报告', },
-            path: 'asseReport',
-            component: () =>
-                import('@/views/powerQuality/asseReport/index'),
-        },
-        {
-            meta: { icon: 'unbalanceAnalysis', title: '三相不平衡分析', },
-            path: 'unbalanceAnalysis',
-            component: () =>
-                import('@/views/powerQuality/unbalanceAnalysis/index'),
-        },
+                meta: { icon: 'harmonicReport', title: '谐波报表', },
+                path: 'harmonicReport',
+                component: () =>
+                    import ('@/views/powerQuality/harmonicReport/index'),
+            },
+            {
+                meta: { icon: 'realTimeMonitoring', title: '实时监测' },
+                path: 'realTimeMonitoring',
+                component: () =>
+                    import ('@/views/powerQuality/realTimeMonitoring/index'),
+            },
+            {
+                meta: { icon: 'asseReport', title: '评估报告', },
+                path: 'asseReport',
+                component: () =>
+                    import ('@/views/powerQuality/asseReport/index'),
+            },
+            {
+                meta: { icon: 'unbalanceAnalysis', title: '三相不平衡分析', },
+                path: 'unbalanceAnalysis',
+                component: () =>
+                    import ('@/views/powerQuality/unbalanceAnalysis/index'),
+            },
 
         ]
     },
@@ -327,7 +329,7 @@ export const asyncRoutes = [
             meta: { title: '计划停电', icon: 'planOutage', },
             path: '/planOutage',
             component: () =>
-                import('@/views/planOutage/index'),
+                import ('@/views/planOutage/index'),
             hidden: true
         }],
     },
@@ -437,17 +439,17 @@ export const asyncRoutes = [
         component: Layout,
         redirect: '/systemManage/userManage/index',
         children: [{
-            meta: { title: '用户管理', icon: 'userManage', },
-            path: 'userManage',
-            component: () =>
-                import('@/views/systemManage/userManage/index'),
-        },
-        {
-            meta: { title: '权限管理', icon: 'rolePermission', },
-            path: 'rolePermission',
-            component: () =>
-                import('@/views/systemManage/rolePermission/index'),
-        },
+                meta: { title: '用户管理', icon: 'userManage', },
+                path: 'userManage',
+                component: () =>
+                    import ('@/views/systemManage/userManage/index'),
+            },
+            {
+                meta: { title: '权限管理', icon: 'rolePermission', },
+                path: 'rolePermission',
+                component: () =>
+                    import ('@/views/systemManage/rolePermission/index'),
+            },
         ]
     },
 

+ 4 - 4
src/store/modules/routes.js

@@ -81,10 +81,10 @@ const actions = {
             }]
         }, )
 
-
-
-        if (data[data.length - 1].path !== '*')
-            data.push({ path: '/*', redirect: '/404', hidden: true })
+        // if (data[data.length - 1].path !== '*')
+        //     data.push({ path: '/*', redirect: '/404', hidden: true })
+        console.log('data')
+        console.log(data)
         const asyncRoutes = convertRouter(data)
         const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
         commit('setRoutes', finallyRoutes)

+ 7 - 1
src/utils/request.js

@@ -26,12 +26,18 @@ let loadingInstance
 const handleCode = (code, msg) => {
     switch (code) {
         case '401':
+            // var flag = true;
+            // if (flag) {
+            //     flag = false
+            //     message.error(msg + '  ,请重新登录...' || '登录失效')
+            // }
+
             // message.error(msg || '登录失效')
             // message.error(msg + '  ,请重新登录...' || '登录失效')
-            router.replace({ path: "/login" });
             // setTimeout(() => {
             //     router.replace({ path: "/login" });
             // }, 3000)
+            router.replace({ path: "/login" });
             store.dispatch('user/resetAll').catch(() => {})
             break
         case '403':

+ 5 - 0
src/vab/plugins/permissions.js

@@ -13,6 +13,8 @@ import {
 } from '@/config'
 
 router.beforeEach(async(to, from, next) => {
+    console.log('to.matched')
+    console.log(to.matched)
     let hasToken = store.getters['user/accessToken']
 
     if (!loginInterception) hasToken = true
@@ -21,6 +23,9 @@ router.beforeEach(async(to, from, next) => {
         if (to.path === '/login') {
             next({ path: '/' })
         } else {
+            if (to.matched.length === 0) {
+                next('/404') // 判断此跳转路由的来源路由是否存在,存在的情况跳转到来源路由,否则跳转到404页面
+            }
             const hasRoles =
                 store.getters['acl/admin'] ||
                 store.getters['acl/role'].length > 0 ||