Jelajahi Sumber

fix: logout

double 5 tahun lalu
induk
melakukan
2e574fc562
2 mengubah file dengan 12 tambahan dan 17 penghapusan
  1. 5 2
      src/layout/components/Navbar.vue
  2. 7 15
      src/store/modules/user.js

+ 5 - 2
src/layout/components/Navbar.vue

@@ -71,8 +71,11 @@ export default {
     },
     async logout() {
       await this.$store.dispatch('user/logout')
-      logoutUrl(this.$route.fullPath, { $router: this.$router })
-      // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
+      if (window.Domain.auth_mode === 1) {
+        logoutUrl(this.$route.fullPath, { $router: this.$router })
+      } else {
+        this.$router.push(`/login?redirect=${this.$route.fullPath}`)
+      }
     }
   }
 }

+ 7 - 15
src/store/modules/user.js

@@ -73,26 +73,18 @@ const actions = {
   // user logout
   logout({ commit, state, dispatch }) {
     return new Promise((resolve, reject) => {
-      if (window.Domain.auth_mode === 1) {
+      sysUser.logout(state.token).then(() => {
         commit('SET_TOKEN', '')
         commit('SET_ROLES', [])
         removeToken()
         resetRouter()
+        // reset visited views and cached views
+        // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
+        dispatch('tagsView/delAllViews', null, { root: true })
         resolve()
-      } else {
-        sysUser.logout(state.token).then(() => {
-          commit('SET_TOKEN', '')
-          commit('SET_ROLES', [])
-          removeToken()
-          resetRouter()
-          // reset visited views and cached views
-          // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
-          dispatch('tagsView/delAllViews', null, { root: true })
-          resolve()
-        }).catch(error => {
-          reject(error)
-        })
-      }
+      }).catch(error => {
+        reject(error)
+      })
     })
   },