提交 916ad887 编写于 作者: Cano1997's avatar Cano1997

update: 登录页面、修改密码添加验证码功能

上级 55ba6a57
/* eslint-disable no-plusplus */
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import { defineComponent, PropType, reactive, ref } from 'vue'; import { defineComponent, PropType, reactive, Ref, ref } from 'vue';
import { useNamespace } from '@ibiz-template/vue-util'; import { useNamespace } from '@ibiz-template/vue-util';
import './forget-password.scss'; import './forget-password.scss';
...@@ -98,11 +99,35 @@ export const ForgetPassword = defineComponent({ ...@@ -98,11 +99,35 @@ export const ForgetPassword = defineComponent({
const loading = ref(false); const loading = ref(false);
const timer: Ref<ReturnType<typeof setInterval> | null> = ref(null);
const countdown = ref(0);
const standCountdown = () => {
countdown.value = 60;
timer.value = setInterval(() => {
if (countdown.value > 1) {
countdown.value--;
} else if (timer.value) {
countdown.value--;
clearInterval(timer.value);
timer.value = null;
}
}, 1000);
};
const sendVerificationCode = () => { const sendVerificationCode = () => {
const { loginName } = userData; const { loginName } = userData;
if (!loginName) {
ibiz.notification.warning({
title: '请先输入账号',
});
return;
}
ibiz.net ibiz.net
.post(`/v7/forgetPwd/sendVerificationCode/${loginName}`, {}) .post(`/v7/forgetPwd/sendVerificationCode/${loginName}`, {})
.then((res: IData) => { .then((res: IData) => {
standCountdown();
if (res.ok) { if (res.ok) {
ibiz.notification.success({ ibiz.notification.success({
title: '获取验证码成功', title: '获取验证码成功',
...@@ -114,6 +139,7 @@ export const ForgetPassword = defineComponent({ ...@@ -114,6 +139,7 @@ export const ForgetPassword = defineComponent({
} }
}) })
.catch((err: IData) => { .catch((err: IData) => {
standCountdown();
ibiz.notification.error({ ibiz.notification.error({
title: (err as IData).response?.data?.message || '获取验证码失败', title: (err as IData).response?.data?.message || '获取验证码失败',
}); });
...@@ -196,7 +222,15 @@ export const ForgetPassword = defineComponent({ ...@@ -196,7 +222,15 @@ export const ForgetPassword = defineComponent({
}} }}
placeholder='请输入验证码' placeholder='请输入验证码'
></i-input> ></i-input>
<i-button on-click={sendVerificationCode}>获取验证码</i-button> <i-button
class={ns.is('disabled', !!timer.value)}
disabled={!!timer.value}
on-click={sendVerificationCode}
>
{countdown.value > 0
? `${countdown.value}秒后重发`
: '获取验证码'}
</i-button>
</i-form-item> </i-form-item>
<i-form-item prop='newPwd'> <i-form-item prop='newPwd'>
<i-input <i-input
......
...@@ -5,6 +5,29 @@ ...@@ -5,6 +5,29 @@
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
background: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%); background: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%);
@include e(verification) {
.ivu-form-item-content {
display: flex;
}
.ivu-form-item-content .ivu-btn.ivu-btn-default {
margin-left: 20px;
margin-top: 0;
}
.ivu-input-type-number {
height: 40px;
line-height: 40px;
.ivu-input {
-moz-appearance: textfield;
height: 40px;
&::-webkit-outer-spin-button,
&::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
}
}
}
} }
@media screen and (max-width: 720px) { @media screen and (max-width: 720px) {
...@@ -105,6 +128,12 @@ ...@@ -105,6 +128,12 @@
background: #337ecc; background: #337ecc;
border-color: #337ecc; border-color: #337ecc;
} }
&.is-disabled {
background-color: #E5E8EC;
border-color: #E5E8EC;
color: #B3BBC6;
}
} }
.ivu-input-wrapper-large { .ivu-input-wrapper-large {
...@@ -121,15 +150,15 @@ ...@@ -121,15 +150,15 @@
.ivu-form { .ivu-form {
position: relative; position: relative;
&>.ivu-btn { & > .ivu-btn {
position: absolute; position: absolute;
right: 0; right: 0;
bottom: 44px; bottom: 44px;
color: getCssVar(color, primary); color: getCssVar(color, primary);
box-shadow: none; box-shadow: none;
} }
&>.ivu-btn:hover { & > .ivu-btn:hover {
background-color: transparent background-color: transparent;
} }
} }
} }
/* eslint-disable no-plusplus */
import { CoreConst } from '@ibiz-template/core'; import { CoreConst } from '@ibiz-template/core';
import { import {
defineComponent, defineComponent,
getCurrentInstance, getCurrentInstance,
onMounted, onMounted,
reactive, reactive,
Ref,
ref, ref,
} from 'vue'; } from 'vue';
import { clearCookie, setCookie } from 'qx-util'; import { clearCookie, setCookie } from 'qx-util';
...@@ -14,6 +16,7 @@ import './app-login-extend.scss'; ...@@ -14,6 +16,7 @@ import './app-login-extend.scss';
interface LoginData { interface LoginData {
username: string; username: string;
password: string; password: string;
verificationCode: string;
} }
const rules = { const rules = {
...@@ -37,6 +40,13 @@ const rules = { ...@@ -37,6 +40,13 @@ const rules = {
trigger: 'blur', trigger: 'blur',
}, },
], ],
verificationCode: [
{
required: true,
message: '请输入验证码',
trigger: 'blur',
},
],
}; };
export default defineComponent({ export default defineComponent({
...@@ -46,6 +56,7 @@ export default defineComponent({ ...@@ -46,6 +56,7 @@ export default defineComponent({
const loginData = reactive<LoginData>({ const loginData = reactive<LoginData>({
username: '', username: '',
password: '', password: '',
verificationCode: '',
}); });
const formRef = ref<IData | null>(null); const formRef = ref<IData | null>(null);
...@@ -57,6 +68,10 @@ export default defineComponent({ ...@@ -57,6 +68,10 @@ export default defineComponent({
ibiz.appData = undefined; ibiz.appData = undefined;
ibiz.orgData = undefined; ibiz.orgData = undefined;
const timer: Ref<ReturnType<typeof setInterval> | null> = ref(null);
const countdown = ref(0);
onMounted(() => { onMounted(() => {
setTimeout(() => { setTimeout(() => {
const el = document.querySelector('.app-loading-x') as HTMLDivElement; const el = document.querySelector('.app-loading-x') as HTMLDivElement;
...@@ -78,7 +93,11 @@ export default defineComponent({ ...@@ -78,7 +93,11 @@ export default defineComponent({
if ((ibiz.env as IData).enableSM3) { if ((ibiz.env as IData).enableSM3) {
password = ibiz.util.text.sm3(password).toUpperCase(); password = ibiz.util.text.sm3(password).toUpperCase();
} }
const res = await ibiz.auth.v7login(loginData.username, password); const res = await ibiz.net.post('/v7/loginPwd', {
loginname: loginData.username,
password,
verificationcode: loginData.verificationCode,
});
if (res.ok) { if (res.ok) {
const { data } = res; const { data } = res;
if (data && data.token) { if (data && data.token) {
...@@ -121,6 +140,49 @@ export default defineComponent({ ...@@ -121,6 +140,49 @@ export default defineComponent({
await modal.onWillDismiss(); await modal.onWillDismiss();
}; };
const standCountdown = () => {
countdown.value = 60;
timer.value = setInterval(() => {
if (countdown.value > 1) {
countdown.value--;
} else if (timer.value) {
countdown.value--;
clearInterval(timer.value);
timer.value = null;
}
}, 1000);
};
const sendVerificationCode = () => {
const { username } = loginData;
if (!username) {
ibiz.notification.warning({
title: '请先输入账号',
});
return;
}
ibiz.net
.post(`/v7/loginPwd/sendVerificationCode/${username}`, {})
.then((res: IData) => {
standCountdown();
if (res.ok) {
ibiz.notification.success({
title: '获取验证码成功',
});
} else {
ibiz.notification.error({
title: res.data?.message || '获取验证码失败',
});
}
})
.catch((err: IData) => {
standCountdown();
ibiz.notification.error({
title: (err as IData).response?.data?.message || '获取验证码失败',
});
});
};
return () => ( return () => (
<div class={ns.b()}> <div class={ns.b()}>
<div class={ns.b('box')}> <div class={ns.b('box')}>
...@@ -165,6 +227,29 @@ export default defineComponent({ ...@@ -165,6 +227,29 @@ export default defineComponent({
<i-icon type='ios-unlock' slot='prefix'></i-icon> <i-icon type='ios-unlock' slot='prefix'></i-icon>
</i-input> </i-input>
</i-form-item> </i-form-item>
<i-form-item
prop='verificationCode'
class={ns.e('verification')}
>
<i-input
type='number'
value={loginData.verificationCode}
on-on-change={(evt: InputEvent) => {
const { value } = evt.target as HTMLInputElement;
loginData.verificationCode = value;
}}
placeholder='请输入验证码'
></i-input>
<i-button
class={ns.is('disabled', !!timer.value)}
disabled={!!timer.value}
on-click={sendVerificationCode}
>
{countdown.value > 0
? `${countdown.value}秒后重发`
: '获取验证码'}
</i-button>
</i-form-item>
<i-button type='text' on-click={onForget}> <i-button type='text' on-click={onForget}>
忘记密码 忘记密码
</i-button> </i-button>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册