Browse Source

修复退出后浏览器按钮回退的问题

zhangliang2 2 years ago
parent
commit
64a2f18124
1 changed files with 27 additions and 2 deletions
  1. 27 2
      src/views/login.vue

+ 27 - 2
src/views/login.vue

@@ -91,7 +91,8 @@ export default {
                             if (toExpiresTime < 5*60 * 1000) {
                                 this.getRefreshToken()
                             }else{
-                                this.$router.push({ path: "/mainPage" });
+                                this.getUserInfo();
+                                // this.$router.push({ path: "/mainPage" });
                             }
                             
                         } else {
@@ -119,17 +120,41 @@ export default {
                     localStorage.setItem("refreshToken", refreshToken);
                     localStorage.setItem("expiresTime", expiresTime);
 
-                    this.$router.push({ path: "/mainPage" });
+                    this.getUserInfo();
+                    // this.$router.push({ path: "/mainPage" });
                     
                 } else {
                     this.$message.error(res.message || "获取refresh_token失败");
                 }
             });
         },
+        getUserInfo() {
+            this.$axios({
+                method: "POST",
+                url: this.$api.common.getCurrentUserInfo,
+                data: {},
+            }).then((res) => {
+                if (res.code == 200 && res.info) {
+                    this.$store.commit("getUserId", res.info.id);
+                    this.$store.commit("getUsername", res.info.username);
+                    this.$store.commit("getRoleCode", res.info.roleCode);
+                    this.$store.commit("getUseType", res.info.useType);
+
+                    this.$router.push({ path: "/mainPage" });
+                } else {
+                    this.$message.error(res.message || "获取用户信息失败");
+                }
+            });
+        },
     },
 
     mounted() {
         localStorage.clear();
+
+        this.$store.commit("getUserId", "");
+        this.$store.commit("getUsername", "");
+        this.$store.commit("getRoleCode", "");
+        this.$store.commit("getUseType","");
     },
 
     beforeRouteLeave (to, from, next) {