Przeglądaj źródła

修改登录时候上一次是哪个页面登录之后就跳转到哪个页面

zhuliu 1 rok temu
rodzic
commit
1436ce1d2e
2 zmienionych plików z 19 dodań i 1 usunięć
  1. 7 1
      src/router/index.js
  2. 12 0
      src/views/login/index.vue

+ 7 - 1
src/router/index.js

@@ -610,7 +610,13 @@ router.beforeEach((to, from, next) => {
         if (to.meta.title) {
           document.title = to.meta.title;
         }
-        next({ name: 'Login', params: { redirect: to.fullPath } })
+        if(to.matched && to.matched.length>0){
+          var path = to.path
+          if(to.matched.findIndex(item=>{ return item.path == path}) !=-1){
+            localStorage.setItem('redirectUrl',JSON.stringify(to))
+          }
+        }
+        next({ name: 'Login' })
         break
       default:
         if (to.meta.title) {

+ 12 - 0
src/views/login/index.vue

@@ -257,9 +257,21 @@ export default {
             this.getPermissionList()
             this.btnLoading = false
           this.$message.success('登录成功')
+          var redirectUrl = localStorage.getItem('redirectUrl')
+          if(redirectUrl){
+            redirectUrl = JSON.parse(redirectUrl)
+            localStorage.removeItem('redirectUrl')
+            this.$router.push({
+              path:redirectUrl.path,
+              query:redirectUrl.query,
+              params:redirectUrl.params
+            })
+          }else{
             this.$router.push({
               path: '/home'
             })
+          }
+            
             
       }).catch(error => {
         this.getCode()