user5 пре 2 година
родитељ
комит
732d932620
2 измењених фајлова са 44 додато и 3 уклоњено
  1. 7 0
      src/api/auth/loginService.js
  2. 37 3
      src/views/sys/login/components/login-form.vue

+ 7 - 0
src/api/auth/loginService.js

@@ -21,4 +21,11 @@ export default {
 			method: "get",
 		});
 	},
+	getLoginCodeNumber: function (userName) {
+		return request({
+			url: prefix + "/user/getLoginCodeNumber",
+			method: "get",
+			params: { userName: userName },
+		})
+	}
 };

+ 37 - 3
src/views/sys/login/components/login-form.vue

@@ -56,6 +56,7 @@
 					placeholder="请输入账号"
 					clearable
 					v-model="inputForm.username"
+					@blur="getLoginCodeNumber($event.target.value)"
 				></el-input>
 			</el-form-item>
 			<el-form-item prop="password">
@@ -68,7 +69,7 @@
 				></el-input>
 			</el-form-item>
 
-			<el-row :gutter="10">
+			<el-row :gutter="10" v-if="inputForm.isShow">
 				<el-col :span="16">
 					<el-form-item prop="code">
 						<el-input
@@ -114,6 +115,7 @@ export default {
 			logo: "",
 			productName: "",
 			loading: false,
+			isShow: false,
 			captchaImg: "",
 			inputForm: {
 				username: "admin",
@@ -162,7 +164,10 @@ export default {
 		this.$store.commit("clearIframeList");
 	},
 	mounted() {
-		this.getCaptcha();
+		// this.getCaptcha();
+		if (this.inputForm.username) {
+			this.getLoginCodeNumber(this.inputForm.username)
+		}
 	},
 	computed: {
 		appName() {
@@ -230,7 +235,7 @@ export default {
 						})
 						.catch(() => {
 							this.loading = false;
-							this.getCaptcha();
+							this.getLoginErrorMethod();
 						});
 				}
 			});
@@ -249,6 +254,35 @@ export default {
 				this.inputForm.uuid = data.uuid;
 			});
 		},
+		//登陆失败时访问的方法
+		getLoginErrorMethod() {
+			loginService.getCode().then((data) => {
+				this.captchaImg = "data:image/gif;base64," + data.codeImg;
+				this.inputForm.uuid = data.uuid;
+			});
+			if (this.inputForm.username) {
+				loginService.getLoginCodeNumber(this.inputForm.username).then((data) => {
+					if (data.redisLoginNumber >= data.loginNumber) {
+						this.inputForm.isShow = true
+					} else {
+						this.inputForm.isShow = false
+					}
+				})
+			}
+		},
+		// 获取验证码
+		getLoginCodeNumber(username) {
+			loginService.getLoginCodeNumber(username).then((data) => {
+				if (data.redisLoginNumber >= data.loginNumber) {
+					if (!this.inputForm.isShow) {
+						this.getCaptcha()
+						this.inputForm.isShow = true
+					}
+				} else {
+					this.inputForm.isShow = false
+				}
+			})
+		},
 		// 切换语言
 		changeLanguage(language) {
 			this.$TOOL.data.set("APP_LANG", language);