Browse Source

刷新的时候上次路由的保存

zhulizhen1111 4 years ago
parent
commit
6546f2417a
4 changed files with 36 additions and 16 deletions
  1. 9 3
      src/router/index.js
  2. 1 1
      src/store/index.js
  3. 26 0
      src/views/auth/index.vue
  4. 0 12
      src/views/strategy/index.vue

+ 9 - 3
src/router/index.js

@@ -9,6 +9,7 @@ const Audit = () => import('@/views/audit/index')
 const DoBusiness = () => import('@/views/doBusiness/index')
 const Evaluate = () => import('@/views/evaluate/index')
 const EvTwoLevelMenu = () => import('@/views/evaluate/evTwoLevelMenu')
+const Auth = () =>import('@/views/auth/index')
 
 import store from '../store'
 import { query } from '../utils/query'
@@ -24,6 +25,11 @@ const router = new Router({
       component: Main
     },
     {
+      path: '/auth',
+      name: 'auth',
+      component: Auth
+    },
+    {
       path: '/strategy',
       name: 'strategy',
       component: Strategy
@@ -79,11 +85,11 @@ router.beforeEach(async (to, from, next) => {
     }
     next()
   } else {
+    let lastRoute = { path: to.path, params: to.params, query: to.query }
+    store.commit('setLastRoute', lastRoute)
     let ssoServer = 'http://sso.sagacloud.cn'
-    let redirectUrl = window.location.protocol + '//' + window.location.host + '/strategy'
+    let redirectUrl = window.location.protocol + '//' + window.location.host + '/auth'
     window.location.href = `${ssoServer}/login?redirectUrl=${redirectUrl}`
-    let lastRoute = { path: to.path, params: to.params, query: to.query }
-    sessionStorage.setItem('lastRoute',JSON.stringify(lastRoute))
   }
 })
 

+ 1 - 1
src/store/index.js

@@ -63,7 +63,7 @@ const store = new Vuex.Store({
         localStorage.setItem('token', token)
       } else {
         let ssoServer = 'http://sso.sagacloud.cn'
-        let redirectUrl = window.location.protocol + '//' + window.location.host + '/strategy'
+        let redirectUrl = window.location.protocol + '//' + window.location.host + '/auth'
         window.location.href = `${ssoServer}/login?redirectUrl=${redirectUrl}`
       }
     }

+ 26 - 0
src/views/auth/index.vue

@@ -0,0 +1,26 @@
+<template>
+  <h4>请稍等</h4>
+</template>
+
+<script>
+export default {
+    data(){
+        return{
+
+        }
+    },
+    created(){
+        let lastRoute = this.$store.getters['lastRoute'].path.split('/')[1]
+        console.log(lastRoute)
+        if (lastRoute != 'auth') {
+            this.$router.replace(lastRoute)
+        } else {
+            this.$router.replace('/strategy')
+        } 
+    },
+}
+</script>
+
+<style>
+
+</style>

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

@@ -138,18 +138,6 @@ export default {
         // },1500)
         // this.getQuickData();
         this.getChiller()
-    },
-    created(){
-        if(sessionStorage.getItem('lastRoute')){
-             let lastRoute = JSON.parse(sessionStorage.getItem('lastRoute'))
-            let lastPath = lastRoute.path.split('/')[1]
-            if(lastPath){
-                this.$router.replace(`/${lastPath}`)
-            }else{
-                this.$router.replace('/strategy')
-            }
-        }
-       
     }
 }
 </script>