Bladeren bron

账号密码登录验证码

seimin 1 jaar geleden
bovenliggende
commit
4fbc9888d7
2 gewijzigde bestanden met toevoegingen van 59 en 12 verwijderingen
  1. 1 0
      src/main.js
  2. 58 12
      src/views/Login.vue

+ 1 - 0
src/main.js

@@ -21,6 +21,7 @@ axios.defaults.baseURL = protocolName + "//" + domainName;
21 21
 Vue.prototype.$http = axios;
22 22
 Vue.config.productionTip = false;
23 23
 Vue.prototype.$host = protocolName + "//" + domainName;
24
+Vue.prototype.$baseURL = protocolName + "//" + domainName;
24 25
 //因项目众多,前端为了加以区分,所以用域名加以判断,后期有更好的方式可以自行修改
25 26
 // 中南财大
26 27
 Vue.prototype.isZncd = document.domain === 'itsm.zuel.edu.cn';

+ 58 - 12
src/views/Login.vue

@@ -8,17 +8,16 @@
8 8
       运维管理平台
9 9
     </h2>
10 10
     <div v-if="requesterLgoinType == 'web'" style="width: 5rem">
11
-      <cube-input
12
-        v-model="zhanghao"
13
-        placeholder="您的账号为学工号"
14
-      ></cube-input>
15
-      <br />
16
-      <cube-input
17
-        v-model="mima"
18
-        type="password"
19
-        placeholder="您的初始密码为学工号后四位"
20
-      ></cube-input>
21
-      <br />
11
+      <div class="login_input">
12
+        <cube-input v-model="zhanghao" placeholder="您的账号为学工号"></cube-input>
13
+      </div>
14
+      <div class="login_input">
15
+        <cube-input v-model="mima" type="password" placeholder="您的初始密码为学工号后四位"></cube-input>
16
+      </div>
17
+      <div class="login_input" style="display: flex;">
18
+        <cube-input v-model="captcha" placeholder="请输入验证码" style="width: 50%;margin: 0 1%;"></cube-input>
19
+        <img style="width: 50%;margin: 0 1%;" :src="verificationCodeImg" @click="getVerificationCodeImg">
20
+      </div>
22 21
       <cube-button @click="zlogin()" style="background: #005395"
23 22
         >登录</cube-button
24 23
       >
@@ -41,6 +40,8 @@ export default {
41 40
     return {
42 41
       zhanghao: "",
43 42
       mima: "",
43
+      captcha: "",
44
+      verificationCodeImg: "",
44 45
       requesterLgoinType: "",
45 46
       isSSo: true, // 是否单点登录
46 47
     };
@@ -49,6 +50,10 @@ export default {
49 50
     LoadIng,
50 51
   },
51 52
   methods: {
53
+    // 获取验证码
54
+    getVerificationCodeImg(){
55
+      this.verificationCodeImg = `${this.$baseURL}/service/auth/getCaptcha?` + Date.now();
56
+    },
52 57
     // 登陆
53 58
     login() {
54 59
       var that = this;
@@ -201,6 +206,7 @@ export default {
201 206
             this.getCode();
202 207
           } else if (this.requesterLgoinType == "web") {
203 208
             // this.$router.push({ path: "/login" });
209
+            this.getVerificationCodeImg();
204 210
           }
205 211
         }
206 212
       });
@@ -225,10 +231,37 @@ export default {
225 231
         ssoStr = location.search.replace("?", "").split("&")[0].split("=")[1];
226 232
         ssoStr = decode(decodeURIComponent(ssoStr));
227 233
         ssoJson = JSON.parse(ssoStr);
234
+      }else if(!this.zhanghao || !this.zhanghao.trim()){
235
+          that.$createDialog({
236
+              type: "alert",
237
+              title: "提示",
238
+              content: "请输入用户名",
239
+              icon: "cubeic-wrong",
240
+              color: "red"
241
+            }).show();
242
+          return;
243
+      }else if(!this.mima || !this.mima.trim()){
244
+          that.$createDialog({
245
+              type: "alert",
246
+              title: "提示",
247
+              content: "请输入密码",
248
+              icon: "cubeic-wrong",
249
+              color: "red"
250
+            }).show();
251
+          return;
252
+      }else if(!this.captcha || !this.captcha.trim()){
253
+          that.$createDialog({
254
+              type: "alert",
255
+              title: "提示",
256
+              content: "请输入验证码",
257
+              icon: "cubeic-wrong",
258
+              color: "red"
259
+            }).show();
260
+          return;
228 261
       }
229 262
       var postData = this.isSSo
230 263
         ? { username: ssoJson.a, password: ssoJson.u, t: false }
231
-        : { username: this.zhanghao, password: this.mima };
264
+        : { username: this.zhanghao, password: this.mima, captcha: this.captcha };
232 265
       postData = {
233 266
         k: this.encryptByEnAESLogin(JSON.stringify(postData))
234 267
       };
@@ -245,6 +278,16 @@ export default {
245 278
             JSON.stringify(res.data.data.requester)
246 279
           );
247 280
           this.getConfig();
281
+        } else if(res.data && res.data.state == 403){
282
+          // 403代表验证码校验失败
283
+          that.$createDialog({
284
+              type: "alert",
285
+              title: "提示",
286
+              content: "验证码错误",
287
+              icon: "cubeic-wrong",
288
+              color: "red"
289
+            }).show();
290
+            this.getVerificationCodeImg();
248 291
         } else {
249 292
           that
250 293
             .$createDialog({
@@ -283,6 +326,9 @@ export default {
283 326
 </script>
284 327
 
285 328
 <style scoped>
329
+.login_input{
330
+  margin-bottom: 0.2rem;
331
+}
286 332
 .color {
287 333
   color: red;
288 334
   font-size: 1rem;