浏览代码

账号密码登录验证码

seimin 1 年之前
父节点
当前提交
9491c5a5b4
共有 2 个文件被更改,包括 62 次插入20 次删除
  1. 1 0
      src/main.js
  2. 61 20
      src/views/Login.vue

+ 1 - 0
src/main.js

@@ -19,6 +19,7 @@ axios.defaults.baseURL = protocolName + "//" + domainName;
19
 axios.defaults.headers["Content-Type"] = "application/json;charset=UTF-8";
19
 axios.defaults.headers["Content-Type"] = "application/json;charset=UTF-8";
20
 
20
 
21
 Vue.prototype.$http = axios;
21
 Vue.prototype.$http = axios;
22
+Vue.prototype.$baseURL = protocolName + "//" + domainName;
22
 Vue.config.productionTip = false;
23
 Vue.config.productionTip = false;
23
 // http request拦截器 添加一个请求拦截器
24
 // http request拦截器 添加一个请求拦截器
24
 axios.interceptors.request.use(
25
 axios.interceptors.request.use(

+ 61 - 20
src/views/Login.vue

@@ -8,20 +8,17 @@
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 />
22
-      <cube-button @click="zlogin()" style="background: #005395"
23
-        >登录</cube-button
24
-      >
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>
21
+      <cube-button @click="zlogin()" style="background: #005395">登录</cube-button>
25
     </div>
22
     </div>
26
   </div>
23
   </div>
27
 </template>
24
 </template>
@@ -36,12 +33,13 @@ import {
36
 // 注意事项:个人微信需要关注微工作台,否则会导致没有userId(userId为openID)登录失败
33
 // 注意事项:个人微信需要关注微工作台,否则会导致没有userId(userId为openID)登录失败
37
 import { decode } from "js-base64";
34
 import { decode } from "js-base64";
38
 import LoadIng from "./../views/loading.vue";
35
 import LoadIng from "./../views/loading.vue";
39
-import http from "../request/http";
40
 export default {
36
 export default {
41
   data() {
37
   data() {
42
     return {
38
     return {
43
       zhanghao: "",
39
       zhanghao: "",
44
       mima: "",
40
       mima: "",
41
+      captcha: "",
42
+      verificationCodeImg: "",
45
       requesterLgoinType: "",
43
       requesterLgoinType: "",
46
       isSSo: true // 是否单点登录
44
       isSSo: true // 是否单点登录
47
     };
45
     };
@@ -50,6 +48,10 @@ export default {
50
     LoadIng
48
     LoadIng
51
   },
49
   },
52
   methods: {
50
   methods: {
51
+    // 获取验证码
52
+    getVerificationCodeImg(){
53
+      this.verificationCodeImg = `${this.$baseURL}/service/auth/getCaptcha?` + Date.now();
54
+    },
53
     // 获取版本配置(报修主题:报修人/报修科室)
55
     // 获取版本配置(报修主题:报修人/报修科室)
54
     getConfig() {
56
     getConfig() {
55
       this.$http
57
       this.$http
@@ -94,6 +96,7 @@ export default {
94
             this.getCode();
96
             this.getCode();
95
           } else if (this.requesterLgoinType == "web") {
97
           } else if (this.requesterLgoinType == "web") {
96
             // this.$router.push({ path: "/login" });
98
             // this.$router.push({ path: "/login" });
99
+            this.getVerificationCodeImg();
97
           }
100
           }
98
         }
101
         }
99
       });
102
       });
@@ -121,10 +124,37 @@ export default {
121
           .split("=")[1];
124
           .split("=")[1];
122
         ssoStr = decode(decodeURIComponent(ssoStr));
125
         ssoStr = decode(decodeURIComponent(ssoStr));
123
         ssoJson = JSON.parse(ssoStr);
126
         ssoJson = JSON.parse(ssoStr);
127
+      }else if(!this.zhanghao || !this.zhanghao.trim()){
128
+          that.$createDialog({
129
+              type: "alert",
130
+              title: "提示",
131
+              content: "请输入用户名",
132
+              icon: "cubeic-wrong",
133
+              color: "red"
134
+            }).show();
135
+          return;
136
+      }else if(!this.mima || !this.mima.trim()){
137
+          that.$createDialog({
138
+              type: "alert",
139
+              title: "提示",
140
+              content: "请输入密码",
141
+              icon: "cubeic-wrong",
142
+              color: "red"
143
+            }).show();
144
+          return;
145
+      }else if(!this.captcha || !this.captcha.trim()){
146
+          that.$createDialog({
147
+              type: "alert",
148
+              title: "提示",
149
+              content: "请输入验证码",
150
+              icon: "cubeic-wrong",
151
+              color: "red"
152
+            }).show();
153
+          return;
124
       }
154
       }
125
       var postData = this.isSSo
155
       var postData = this.isSSo
126
         ? { username: ssoJson.a, password: ssoJson.u, t: false }
156
         ? { username: ssoJson.a, password: ssoJson.u, t: false }
127
-        : { username: this.zhanghao, password: this.mima };
157
+        : { username: this.zhanghao, password: this.mima, captcha: this.captcha };
128
       postData = {
158
       postData = {
129
         k: this.encryptByEnAESLogin(JSON.stringify(postData))
159
         k: this.encryptByEnAESLogin(JSON.stringify(postData))
130
       };
160
       };
@@ -137,16 +167,24 @@ export default {
137
             JSON.stringify(res.data.data.requester)
167
             JSON.stringify(res.data.data.requester)
138
           );
168
           );
139
           this.getConfig();
169
           this.getConfig();
170
+        } else if(res.data && res.data.state == 403){
171
+          // 403代表验证码校验失败
172
+          that.$createDialog({
173
+              type: "alert",
174
+              title: "提示",
175
+              content: "验证码错误",
176
+              icon: "cubeic-wrong",
177
+              color: "red"
178
+            }).show();
179
+            this.getVerificationCodeImg();
140
         } else {
180
         } else {
141
-          that
142
-            .$createDialog({
181
+          that.$createDialog({
143
               type: "alert",
182
               type: "alert",
144
               title: "系统错误",
183
               title: "系统错误",
145
               content: "请稍后再试",
184
               content: "请稍后再试",
146
               icon: "cubeic-wrong",
185
               icon: "cubeic-wrong",
147
               color: "red"
186
               color: "red"
148
-            })
149
-            .show();
187
+            }).show();
150
         }
188
         }
151
       });
189
       });
152
     },
190
     },
@@ -239,6 +277,9 @@ export default {
239
 </script>
277
 </script>
240
 
278
 
241
 <style scoped>
279
 <style scoped>
280
+.login_input{
281
+  margin-bottom: 0.2rem;
282
+}
242
 .color {
283
 .color {
243
   color: red;
284
   color: red;
244
   font-size: 1rem;
285
   font-size: 1rem;