Selaa lähdekoodia

页面越权访问修改刷新就退出的BUG

xusl 1 vuosi sitten
vanhempi
commit
c9896db760
1 muutettua tiedostoa jossa 42 lisäystä ja 28 poistoa
  1. 42 28
      ui/src/permission.js

+ 42 - 28
ui/src/permission.js

@@ -24,37 +24,51 @@ router.beforeEach(async (to, from, next) => {
       next({ path: '/dashboard' })
       NProgress.done()
     } else {
-      if (to.matched.length === 0) {
-        Message({
-          message: '越权访问页面不存在!',
-          type: 'error',
-          duration: 5 * 1000
-        })
-        let sysTime2;
-        let lk2;
-        await service.get('/sysPolicyController/getLicenseKey').then((res) => {
-          sysTime2 = res.data.sysTime
-          lk2 = res.data.lk
-        }).catch((error) => {
-        })
-        const searchParams2 = {
-          sysTime: sysTime2,
-          lk: lk2,
-          accessUrl: window.location.href
-        }
-        // 保存越权访问
-        await service.post('/sysPolicyController/brokenAccessControl', searchParams2).then((res) => {
-          removeToken()
-          next('/404') // 判断此跳转路由的来源路由是否存在,存在的情况跳转到来源路由,否则跳转到404页面
-        }).catch((error) => {
-          this.$message.error('越权访问记录出错' + error)
-        })
-        // next('/dashboard')
-
-      }
       // 登录成功时将路由置空
       if (store.getters.permission_routes.length==0) {
         await store.dispatch('GenerateRoutes').then(accessRoutes => {
+          if (to.path!='/dashboard'){
+            let ff = false
+            accessRoutes.map((item)=>{
+              if (item.children){
+                let fpath = item.path
+                let Litem = item.children
+                Litem.map((Citem)=>{
+                  if (fpath+'/'+Citem.path==to.path){
+                    ff = true
+                  }
+                })
+              }
+            })
+
+            if (!ff){
+              Message({
+                  message: '越权访问页面不存在!',
+                  type: 'error',
+                  duration: 5 * 1000
+              })
+              let sysTime2;
+              let lk2;
+              service.get('/sysPolicyController/getLicenseKey').then((res) => {
+                sysTime2 = res.data.sysTime
+                lk2 = res.data.lk
+              }).catch((error) => {
+              })
+              const searchParams2 = {
+                sysTime: sysTime2,
+                lk: lk2,
+                accessUrl: window.location.href
+              }
+              // 保存越权访问
+              service.post('/sysPolicyController/brokenAccessControl', searchParams2).then((res) => {
+                removeToken()
+                next('/404') // 判断此跳转路由的来源路由是否存在,存在的情况跳转到来源路由,否则跳转到404页面
+              }).catch((error) => {
+                this.$message.error('越权访问记录出错' + error)
+              })
+            }
+          }
+
           // 根据roles权限生成可访问的路由表
           router.addRoutes(accessRoutes) // 动态添加可访问路由表
           next({ ...to, replace: true }) // hack方法 确保addRoutes已完成