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,102 +125,89 @@
|
|||||||
const submit = (value): void => {
|
const submit = (value): void => {
|
||||||
console.log(value);
|
console.log(value);
|
||||||
|
|
||||||
// if (password.value === '') {
|
let data = JSON.stringify({
|
||||||
// errorMsg.value = '请输入密码';
|
accountNo: userName.value.trim(),
|
||||||
// errorShow.value = true;
|
password: password.value.trim(),
|
||||||
// return;
|
});
|
||||||
// }
|
validator(null, value.code)
|
||||||
// if (userName.value === '') {
|
.then(() => {
|
||||||
// errorMsg.value = '请输入账号';
|
// 记住密码
|
||||||
// errorShow.value = true;
|
rememberFunc(data);
|
||||||
// return;
|
loading.value = true;
|
||||||
// }
|
async function logins() {
|
||||||
// if (!code.value) {
|
try {
|
||||||
// // errorMsg.value = '请输入验证码';
|
const res = await configStore.userLogin(JSON.parse(data));
|
||||||
// // errorShow.value = true;
|
verifyRef.value?.reload();
|
||||||
// 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(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// 记住密码
|
|
||||||
rememberFunc(data);
|
|
||||||
loading.value = true;
|
|
||||||
async function logins() {
|
|
||||||
try {
|
|
||||||
const res = await configStore.userLogin(JSON.parse(data));
|
|
||||||
|
|
||||||
if (res.data?.token) {
|
|
||||||
if (res.data?.token) {
|
if (res.data?.token) {
|
||||||
Cookies.set('nervsid', res.data?.token);
|
if (res.data?.token) {
|
||||||
}
|
Cookies.set('nervsid', res.data?.token);
|
||||||
const info = await configStore.userInfo();
|
|
||||||
info.data
|
|
||||||
? window.sessionStorage.setItem('userInfo', JSON.stringify(info.data))
|
|
||||||
: '';
|
|
||||||
loading.value = false;
|
|
||||||
if (configStore.enablePermissions) {
|
|
||||||
const res = await configStore.userResource(info);
|
|
||||||
res?.data.sort((a, b) => {
|
|
||||||
return a.sort - b.sort;
|
|
||||||
});
|
|
||||||
console.log(res.data);
|
|
||||||
|
|
||||||
if (configStore.customApplication) {
|
|
||||||
await useAuthorization.initMenuResource();
|
|
||||||
}
|
}
|
||||||
|
const info = await configStore.userInfo();
|
||||||
initUrl.value = '';
|
info.data
|
||||||
const dealInitUrl = (item) => {
|
? window.sessionStorage.setItem('userInfo', JSON.stringify(info.data))
|
||||||
if (item.type === 'menus' && item.menus && item.menus?.length !== 0) {
|
: '';
|
||||||
dealInitUrl(item.menus[0]);
|
loading.value = false;
|
||||||
} else {
|
if (configStore.enablePermissions) {
|
||||||
if (item.type === 'noChildrenMenu') {
|
const res = await configStore.userResource(info);
|
||||||
initUrl.value = configStore.resourceName
|
res?.data.sort((a, b) => {
|
||||||
? item.code.replace(configStore.resourceName, '')
|
return a.sort - b.sort;
|
||||||
: item.code;
|
});
|
||||||
}
|
console.log(res.data);
|
||||||
}
|
|
||||||
};
|
if (configStore.customApplication) {
|
||||||
if (configStore.resourceName) {
|
await useAuthorization.initMenuResource();
|
||||||
const initResource = [];
|
}
|
||||||
res.data.forEach((item) => {
|
|
||||||
if (item.code.includes(configStore.resourceName)) {
|
initUrl.value = '';
|
||||||
initResource.push(item);
|
const dealInitUrl = (item) => {
|
||||||
}
|
if (item.type === 'menus' && item.menus && item.menus?.length !== 0) {
|
||||||
|
dealInitUrl(item.menus[0]);
|
||||||
|
} else {
|
||||||
|
if (item.type === 'noChildrenMenu') {
|
||||||
|
initUrl.value = configStore.resourceName
|
||||||
|
? item.code.replace(configStore.resourceName, '')
|
||||||
|
: item.code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (configStore.resourceName) {
|
||||||
|
const initResource = [];
|
||||||
|
res.data.forEach((item) => {
|
||||||
|
if (item.code.includes(configStore.resourceName)) {
|
||||||
|
initResource.push(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dealInitUrl(initResource[0]);
|
||||||
|
} else {
|
||||||
|
dealInitUrl(res.data[0]);
|
||||||
|
}
|
||||||
|
// dealInitUrl(res.data[0]);
|
||||||
|
useAuthorization.updateUserResource(res.data);
|
||||||
|
const initRouterList = useAuthorization.getInitRouterList;
|
||||||
|
|
||||||
|
router.push({
|
||||||
|
name: initRouterList.length === 0 ? 'error403' : res.data[0]['code'],
|
||||||
});
|
});
|
||||||
dealInitUrl(initResource[0]);
|
|
||||||
} else {
|
} else {
|
||||||
dealInitUrl(res.data[0]);
|
router.replace({ name: 'root' });
|
||||||
}
|
}
|
||||||
// dealInitUrl(res.data[0]);
|
|
||||||
useAuthorization.updateUserResource(res.data);
|
|
||||||
const initRouterList = useAuthorization.getInitRouterList;
|
|
||||||
|
|
||||||
router.push({
|
|
||||||
name: initRouterList.length === 0 ? 'error403' : res.data[0]['code'],
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
router.replace({ name: 'root' });
|
|
||||||
}
|
}
|
||||||
}
|
} catch (err) {
|
||||||
} catch (err) {
|
console.log(err);
|
||||||
console.log(err);
|
|
||||||
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
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