Browse Source

账号密码登录验证码

seimin 1 year ago
parent
commit
9491c5a5b4
2 changed files with 62 additions and 20 deletions
  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 19
 axios.defaults.headers["Content-Type"] = "application/json;charset=UTF-8";
20 20
 
21 21
 Vue.prototype.$http = axios;
22
+Vue.prototype.$baseURL = protocolName + "//" + domainName;
22 23
 Vue.config.productionTip = false;
23 24
 // http request拦截器 添加一个请求拦截器
24 25
 axios.interceptors.request.use(

+ 61 - 20
src/views/Login.vue

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