refactor: 登录校验失败重新获取验证码
Former-commit-id: 0bb7cf394bd24bf59e8c9e71016533893cbea472
This commit is contained in:
@@ -105,6 +105,26 @@ import { LoginData } from '@/api/auth/types';
|
|||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const route = useRoute();
|
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 loginFormRef = ref(ElForm);
|
||||||
|
|
||||||
const loginData = ref<LoginData>({
|
const loginData = ref<LoginData>({
|
||||||
@@ -114,16 +134,14 @@ const loginData = ref<LoginData>({
|
|||||||
|
|
||||||
const loginRules = {
|
const loginRules = {
|
||||||
username: [{ required: true, trigger: 'blur' }],
|
username: [{ required: true, trigger: 'blur' }],
|
||||||
password: [{ required: true, trigger: 'blur', validator: validatePassword }],
|
password: [{ required: true, trigger: 'blur', validator: passwordValidator }],
|
||||||
verifyCode: [{ required: true, trigger: 'blur' }]
|
verifyCode: [{ required: true, trigger: 'blur' }]
|
||||||
};
|
};
|
||||||
|
|
||||||
const passwordVisible = ref(false);
|
/**
|
||||||
const captchaBase64 = ref();
|
* 密码校验器
|
||||||
|
*/
|
||||||
const loading = ref(false);
|
function passwordValidator(rule: any, value: any, callback: any) {
|
||||||
|
|
||||||
function validatePassword(rule: any, value: any, callback: any) {
|
|
||||||
if (value.length < 6) {
|
if (value.length < 6) {
|
||||||
callback(new Error('The password can not be less than 6 digits'));
|
callback(new Error('The password can not be less than 6 digits'));
|
||||||
} else {
|
} else {
|
||||||
@@ -131,16 +149,16 @@ function validatePassword(rule: any, value: any, callback: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否大写锁定
|
/**
|
||||||
const isCapslock = ref(false);
|
* 检查输入大小写状态
|
||||||
|
*/
|
||||||
function checkCapslock(e: any) {
|
function checkCapslock(e: any) {
|
||||||
const { key } = e;
|
const { key } = e;
|
||||||
isCapslock.value = key && key.length === 1 && key >= 'A' && key <= 'Z';
|
isCapslock.value = key && key.length === 1 && key >= 'A' && key <= 'Z';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码
|
* 获取验证码
|
||||||
*/
|
*/
|
||||||
function getCaptcha() {
|
function getCaptcha() {
|
||||||
getCaptchaApi().then(({ data }) => {
|
getCaptchaApi().then(({ data }) => {
|
||||||
@@ -176,9 +194,12 @@ function handleLogin() {
|
|||||||
|
|
||||||
router.push({ path: redirect, query: otherQueryParams });
|
router.push({ path: redirect, query: otherQueryParams });
|
||||||
})
|
})
|
||||||
|
.catch(() => {
|
||||||
|
// 验证失败,重新生成验证码
|
||||||
|
getCaptcha();
|
||||||
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
getCaptcha();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -190,18 +211,6 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.captcha {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
|
|
||||||
img {
|
|
||||||
height: 48px;
|
|
||||||
width: 120px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.login-container {
|
.login-container {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -214,6 +223,18 @@ onMounted(() => {
|
|||||||
padding: 160px 35px 0;
|
padding: 160px 35px 0;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
.captcha {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
|
||||||
|
img {
|
||||||
|
height: 48px;
|
||||||
|
width: 120px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user