Browse Source

修复重复登录。保存用户名。

Michael Wang 6 years ago
parent
commit
304128ceab
2 changed files with 33 additions and 9 deletions
  1. 2 2
      public/index.html
  2. 31 7
      src/views/login.vue

+ 2 - 2
public/index.html

@@ -12,7 +12,6 @@
       // 按Ctrl+Shift+U,放开U,在一秒内再按Ctrl+Shift+P,可以调出开发者工具
       let firstStepKey = false
       document.addEventListener("keydown", function (e) {
-        console.log(e);
         if (e.ctrlKey && e.shiftKey && e.code === 'KeyU') {
           firstStepKey = true;
           setTimeout(() => {
@@ -37,7 +36,8 @@
 
 <body>
   <noscript>
-    <strong>We're sorry but examcloud-web-photo-upload doesn't work properly without JavaScript enabled. Please enable it
+    <strong>We're sorry but examcloud-web-photo-upload doesn't work properly without JavaScript enabled. Please enable
+      it
       to continue.</strong>
   </noscript>
   <div id="app"></div>

+ 31 - 7
src/views/login.vue

@@ -5,15 +5,15 @@
         <div>环境: {{server}}</div>
       </div>
       <div class="username">
-        <input class="comminput" @keyup.enter="login()" type="text" ref="name" id="accountValue" v-model="loginInfo.accountValue" placeholder="账号" />
+        <input class="comminput" @keyup.enter="login" type="text" ref="name" id="accountValue" v-model="loginInfo.accountValue" placeholder="账号" />
       </div>
       <div class="password">
-        <input class="comminput" @keyup.enter="login()" type="password" id="password" v-model="loginInfo.password" placeholder="密码" />
+        <input class="comminput" @keyup.enter="login" type="password" id="password" v-model="loginInfo.password" placeholder="密码" />
       </div>
       <div class="domain">
-        <input class="comminput" @keyup.enter="login()" type="text" id="domain" v-model="loginInfo.domain" placeholder="机构域名" />
+        <input class="comminput" @keyup.enter="login" type="text" id="domain" v-model="loginInfo.domain" placeholder="机构域名" />
       </div>
-      <input type="button" value="登 录" class="btn comminput" @click="login()" />
+      <input type="button" value="登 录" class="btn comminput" @click="login" />
       <div class="errorInfo">{{errorInfo}}</div>
     </div>
   </div>
@@ -35,6 +35,30 @@ export default {
       }
     };
   },
+  beforeRouteEnter(from, to, next) {
+    next(vm => {
+      if (localStorage.getItem("accountValue")) {
+        vm.loginInfo = {
+          ...vm.loginInfo,
+          ...{ accountValue: localStorage.getItem("accountValue") }
+        };
+      }
+      if (localStorage.getItem("domain")) {
+        vm.loginInfo = {
+          ...vm.loginInfo,
+          ...{ domain: localStorage.getItem("domain") }
+        };
+      }
+    });
+  },
+  beforeDestroy() {
+    if (this.loginInfo.accountValue) {
+      localStorage.setItem("accountValue", this.loginInfo.accountValue);
+    }
+    if (this.loginInfo.domain) {
+      localStorage.setItem("domain", this.loginInfo.domain);
+    }
+  },
   methods: {
     checkAccountValue() {
       this.errorInfo = "";
@@ -80,16 +104,16 @@ export default {
       this.$http
         .post("/api/ecs_core/auth/login", this.loginInfo)
         .then(response => {
+          this.pending = false;
           var user = response.data;
           localStorage.setItem("user_token", user.userToken);
           localStorage.setItem("rootOrgId", user.rootOrgId);
           localStorage.setItem("userName", user.displayName);
           this.$router.replace({ path: "/index" });
-          this.pending = false;
         })
-        .catch(response => {
-          this.errorInfo += response.body.desc;
+        .catch(error => {
           this.pending = false;
+          this.errorInfo += error.response.data.desc;
         });
     }
   },