浏览代码

账号密码登录验证码

seimin 1 年之前
父节点
当前提交
4fbc9888d7
共有 2 个文件被更改,包括 59 次插入12 次删除
  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
 Vue.prototype.$http = axios;
21
 Vue.prototype.$http = axios;
22
 Vue.config.productionTip = false;
22
 Vue.config.productionTip = false;
23
 Vue.prototype.$host = protocolName + "//" + domainName;
23
 Vue.prototype.$host = protocolName + "//" + domainName;
24
+Vue.prototype.$baseURL = protocolName + "//" + domainName;
24
 //因项目众多,前端为了加以区分,所以用域名加以判断,后期有更好的方式可以自行修改
25
 //因项目众多,前端为了加以区分,所以用域名加以判断,后期有更好的方式可以自行修改
25
 // 中南财大
26
 // 中南财大
26
 Vue.prototype.isZncd = document.domain === 'itsm.zuel.edu.cn';
27
 Vue.prototype.isZncd = document.domain === 'itsm.zuel.edu.cn';

+ 58 - 12
src/views/Login.vue

@@ -8,17 +8,16 @@
8
       运维管理平台
8
       运维管理平台
9
     </h2>
9
     </h2>
10
     <div v-if="requesterLgoinType == 'web'" style="width: 5rem">
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
       <cube-button @click="zlogin()" style="background: #005395"
21
       <cube-button @click="zlogin()" style="background: #005395"
23
         >登录</cube-button
22
         >登录</cube-button
24
       >
23
       >
@@ -41,6 +40,8 @@ export default {
41
     return {
40
     return {
42
       zhanghao: "",
41
       zhanghao: "",
43
       mima: "",
42
       mima: "",
43
+      captcha: "",
44
+      verificationCodeImg: "",
44
       requesterLgoinType: "",
45
       requesterLgoinType: "",
45
       isSSo: true, // 是否单点登录
46
       isSSo: true, // 是否单点登录
46
     };
47
     };
@@ -49,6 +50,10 @@ export default {
49
     LoadIng,
50
     LoadIng,
50
   },
51
   },
51
   methods: {
52
   methods: {
53
+    // 获取验证码
54
+    getVerificationCodeImg(){
55
+      this.verificationCodeImg = `${this.$baseURL}/service/auth/getCaptcha?` + Date.now();
56
+    },
52
     // 登陆
57
     // 登陆
53
     login() {
58
     login() {
54
       var that = this;
59
       var that = this;
@@ -201,6 +206,7 @@ export default {
201
             this.getCode();
206
             this.getCode();
202
           } else if (this.requesterLgoinType == "web") {
207
           } else if (this.requesterLgoinType == "web") {
203
             // this.$router.push({ path: "/login" });
208
             // this.$router.push({ path: "/login" });
209
+            this.getVerificationCodeImg();
204
           }
210
           }
205
         }
211
         }
206
       });
212
       });
@@ -225,10 +231,37 @@ export default {
225
         ssoStr = location.search.replace("?", "").split("&")[0].split("=")[1];
231
         ssoStr = location.search.replace("?", "").split("&")[0].split("=")[1];
226
         ssoStr = decode(decodeURIComponent(ssoStr));
232
         ssoStr = decode(decodeURIComponent(ssoStr));
227
         ssoJson = JSON.parse(ssoStr);
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
       var postData = this.isSSo
262
       var postData = this.isSSo
230
         ? { username: ssoJson.a, password: ssoJson.u, t: false }
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
       postData = {
265
       postData = {
233
         k: this.encryptByEnAESLogin(JSON.stringify(postData))
266
         k: this.encryptByEnAESLogin(JSON.stringify(postData))
234
       };
267
       };
@@ -245,6 +278,16 @@ export default {
245
             JSON.stringify(res.data.data.requester)
278
             JSON.stringify(res.data.data.requester)
246
           );
279
           );
247
           this.getConfig();
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
         } else {
291
         } else {
249
           that
292
           that
250
             .$createDialog({
293
             .$createDialog({
@@ -283,6 +326,9 @@ export default {
283
 </script>
326
 </script>
284
 
327
 
285
 <style scoped>
328
 <style scoped>
329
+.login_input{
330
+  margin-bottom: 0.2rem;
331
+}
286
 .color {
332
 .color {
287
   color: red;
333
   color: red;
288
   font-size: 1rem;
334
   font-size: 1rem;