Browse Source

fix: 调整验证码校验

deploy-dev
xuziqiang 5 months ago
parent
commit
131913e52d
  1. 4
      lib/component/verify/verify.vue
  2. 49
      lib/saas/view/system/login.vue

4
lib/component/verify/verify.vue

@ -115,6 +115,10 @@
}
return imgCode;
};
defineExpose({
reload: handleDraw,
});
</script>
<style scoped>
.img-verify {

49
lib/saas/view/system/login.vue

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

Loading…
Cancel
Save