fix: 调整验证码校验
This commit is contained in:
@@ -115,6 +115,10 @@
|
|||||||
}
|
}
|
||||||
return imgCode;
|
return imgCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
reload: handleDraw,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.img-verify {
|
.img-verify {
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
</a-input-password>
|
</a-input-password>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item name="code" :rules="[{ validator }]">
|
<a-form-item name="code">
|
||||||
<!-- 验证码 -->
|
<!-- 验证码 -->
|
||||||
<a-input v-model:value="code" placeholder="验证码" class="loginInfo">
|
<a-input v-model:value="code" placeholder="验证码" class="loginInfo">
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
style="margin-right: 20px" />
|
style="margin-right: 20px" />
|
||||||
</template>
|
</template>
|
||||||
<template #addonAfter>
|
<template #addonAfter>
|
||||||
<ns-verify @get-code="onGetCode" />
|
<ns-verify @get-code="onGetCode" ref="verifyRef" />
|
||||||
</template>
|
</template>
|
||||||
</a-input>
|
</a-input>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
@@ -78,6 +78,7 @@
|
|||||||
import { authorizationService } from '/nerv-base/store/modules/authorization-service';
|
import { authorizationService } from '/nerv-base/store/modules/authorization-service';
|
||||||
import { Cookies } from '/nerv-lib/util/cookie';
|
import { Cookies } from '/nerv-lib/util/cookie';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { NsMessage } from '/nerv-lib/component';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'UserLogin',
|
name: 'UserLogin',
|
||||||
@@ -94,6 +95,7 @@
|
|||||||
const initUrl = ref('');
|
const initUrl = ref('');
|
||||||
const verifyCode = ref('');
|
const verifyCode = ref('');
|
||||||
const code = ref();
|
const code = ref();
|
||||||
|
const verifyRef = ref();
|
||||||
const isRemember = ref(false);
|
const isRemember = ref(false);
|
||||||
title.value = '账号登录';
|
title.value = '账号登录';
|
||||||
// title.value = appConfig.title ? appConfig.title : '账号登录';
|
// title.value = appConfig.title ? appConfig.title : '账号登录';
|
||||||
@@ -123,40 +125,19 @@
|
|||||||
const submit = (value): void => {
|
const submit = (value): void => {
|
||||||
console.log(value);
|
console.log(value);
|
||||||
|
|
||||||
// if (password.value === '') {
|
|
||||||
// errorMsg.value = '请输入密码';
|
|
||||||
// errorShow.value = true;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (userName.value === '') {
|
|
||||||
// errorMsg.value = '请输入账号';
|
|
||||||
// errorShow.value = true;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (!code.value) {
|
|
||||||
// // errorMsg.value = '请输入验证码';
|
|
||||||
// // errorShow.value = true;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (code.value.toLocaleLowerCase() !== verifyCode.value.toLocaleLowerCase()) {
|
|
||||||
// errorMsg.value = '请输入正确的验证码';
|
|
||||||
// errorShow.value = true;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
if (userName.value !== '' && password.value !== '') {
|
|
||||||
errorShow.value = false;
|
|
||||||
let data = JSON.stringify({
|
let data = JSON.stringify({
|
||||||
accountNo: userName.value.trim(),
|
accountNo: userName.value.trim(),
|
||||||
password: password.value.trim(),
|
password: password.value.trim(),
|
||||||
});
|
});
|
||||||
|
validator(null, value.code)
|
||||||
|
.then(() => {
|
||||||
// 记住密码
|
// 记住密码
|
||||||
rememberFunc(data);
|
rememberFunc(data);
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
async function logins() {
|
async function logins() {
|
||||||
try {
|
try {
|
||||||
const res = await configStore.userLogin(JSON.parse(data));
|
const res = await configStore.userLogin(JSON.parse(data));
|
||||||
|
verifyRef.value?.reload();
|
||||||
if (res.data?.token) {
|
if (res.data?.token) {
|
||||||
if (res.data?.token) {
|
if (res.data?.token) {
|
||||||
Cookies.set('nervsid', res.data?.token);
|
Cookies.set('nervsid', res.data?.token);
|
||||||
@@ -218,7 +199,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
logins();
|
logins();
|
||||||
|
})
|
||||||
|
.catch((flag) => {
|
||||||
|
if (flag) {
|
||||||
|
NsMessage.error('请输入正确的验证码');
|
||||||
|
verifyRef.value?.reload();
|
||||||
|
} else {
|
||||||
|
NsMessage.error('请输入验证码');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
const checkoutLogo = (): void => {
|
const checkoutLogo = (): void => {
|
||||||
logUrl.value = '';
|
logUrl.value = '';
|
||||||
@@ -232,10 +221,11 @@
|
|||||||
verifyCode.value = res;
|
verifyCode.value = res;
|
||||||
};
|
};
|
||||||
|
|
||||||
const validator = async (rule, value) => {
|
const validator = (rule, value) => {
|
||||||
if (!value) return Promise.reject('请输入验证码');
|
if (!value) return Promise.reject(false);
|
||||||
if (value?.toLocaleLowerCase() !== verifyCode.value.toLocaleLowerCase())
|
if (value?.toLocaleLowerCase() !== verifyCode.value.toLocaleLowerCase())
|
||||||
return Promise.reject('请输入正确的验证码');
|
return Promise.reject(true);
|
||||||
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
validator,
|
validator,
|
||||||
@@ -258,6 +248,7 @@
|
|||||||
errorShow,
|
errorShow,
|
||||||
configStore,
|
configStore,
|
||||||
isRemember,
|
isRemember,
|
||||||
|
verifyRef,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
Reference in New Issue
Block a user