Browse Source

登录记录上次页面

suhanqian 1 year ago
parent
commit
cfbcc430eb
4 changed files with 18 additions and 2 deletions
  1. 5 0
      src/router/index.js
  2. 2 0
      src/store/index.js
  3. 4 0
      src/utils/request.js
  4. 7 2
      src/views/pages/login.vue

+ 5 - 0
src/router/index.js

@@ -47,6 +47,11 @@ const router = new Router({
 })
 
 router.beforeEach((to, from, next) => {
+  if(to.path != "/login") {
+    localStorage.setItem('pathCopy',to.path)
+    // store.state.pathCopyshow = true
+    // store.state.pathCopy = to.path
+  }
   // 截取路由中token进行处理
   // filterToken(to, from, next)
   // console.log(to)

+ 2 - 0
src/store/index.js

@@ -12,6 +12,8 @@ export default new Vuex.Store({
     navbarLayoutType: 'colorful',
     // 侧边栏, 布局皮肤, default(白色) / dark(黑色)
     sidebarLayoutSkin: 'dark',
+    pathCopy:'',
+    pathCopyshow:false,
     // 侧边栏, 折叠状态
     sidebarFold: false,
     // 侧边栏, 菜单

+ 4 - 0
src/utils/request.js

@@ -53,6 +53,10 @@ http.interceptors.request.use(config => {
  */
 http.interceptors.response.use(response => {
   if (response.data.code === 401 || response.data.code === 402 || response.data.code === 403 || response.data.code === 10001) {
+    if(localStorage.getItem('pathCopy')) {
+      localStorage.setItem('pathCopyshow',true)
+      // store.state.pathCopy = to.path
+    }
     clearLoginInfo()
     router.replace({ name: 'login' })
     return Promise.reject(response.data.msg)

+ 7 - 2
src/views/pages/login.vue

@@ -177,8 +177,13 @@ export default {
               return this.$message.error(res.msg)
             }
           }).catch(() => {})
-          
-          this.$router.replace({ name: 'home' })
+          if(localStorage.getItem('pathCopyshow') && localStorage.getItem('pathCopy')) {
+            this.$router.push(localStorage.getItem('pathCopy'))
+          }
+          else{
+            this.$router.replace({ name: 'home' })
+          }
+          // this.$router.replace({ name: 'home' })
         }).catch(() => {})
       })
     }, 1000, { 'leading': true, 'trailing': false })