From 63cc944f83aeb59c101273162bebe5c2570458e7 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Sat, 25 Mar 2023 09:28:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=99=BB=E5=BD=95=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=A4=B1=E8=B4=A5=E9=87=8D=E6=96=B0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 0bb7cf394bd24bf59e8c9e71016533893cbea472 --- src/views/login/index.vue | 69 +++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 15d1d5aa..205e1e2f 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -105,6 +105,26 @@ import { LoginData } from '@/api/auth/types'; const userStore = useUserStore(); const route = useRoute(); +/** + * 按钮loading + */ +const loading = ref(false); +/** + * 是否大写锁定 + */ +const isCapslock = ref(false); +/** + * 密码是否可见 + */ +const passwordVisible = ref(false); +/** + * 验证码图片Base64字符串 + */ +const captchaBase64 = ref(); + +/** + * 登录表单引用 + */ const loginFormRef = ref(ElForm); const loginData = ref({ @@ -114,16 +134,14 @@ const loginData = ref({ const loginRules = { username: [{ required: true, trigger: 'blur' }], - password: [{ required: true, trigger: 'blur', validator: validatePassword }], + password: [{ required: true, trigger: 'blur', validator: passwordValidator }], verifyCode: [{ required: true, trigger: 'blur' }] }; -const passwordVisible = ref(false); -const captchaBase64 = ref(); - -const loading = ref(false); - -function validatePassword(rule: any, value: any, callback: any) { +/** + * 密码校验器 + */ +function passwordValidator(rule: any, value: any, callback: any) { if (value.length < 6) { callback(new Error('The password can not be less than 6 digits')); } else { @@ -131,16 +149,16 @@ function validatePassword(rule: any, value: any, callback: any) { } } -// 是否大写锁定 -const isCapslock = ref(false); - +/** + * 检查输入大小写状态 + */ function checkCapslock(e: any) { const { key } = e; isCapslock.value = key && key.length === 1 && key >= 'A' && key <= 'Z'; } /** - * 验证码 + * 获取验证码 */ function getCaptcha() { getCaptchaApi().then(({ data }) => { @@ -176,9 +194,12 @@ function handleLogin() { router.push({ path: redirect, query: otherQueryParams }); }) + .catch(() => { + // 验证失败,重新生成验证码 + getCaptcha(); + }) .finally(() => { loading.value = false; - getCaptcha(); }); } }); @@ -190,18 +211,6 @@ onMounted(() => {