提交 0affb4b9 编写于 作者: Cano1997's avatar Cano1997

update: 添加验证码倒计时

上级 eea30cd9
/* 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
......
...@@ -128,6 +128,12 @@ ...@@ -128,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 {
......
/* 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';
...@@ -66,6 +68,10 @@ export default defineComponent({ ...@@ -66,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;
...@@ -134,6 +140,19 @@ export default defineComponent({ ...@@ -134,6 +140,19 @@ 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 sendVerificationCode = () => {
const { username } = loginData; const { username } = loginData;
if (!username) { if (!username) {
...@@ -145,6 +164,7 @@ export default defineComponent({ ...@@ -145,6 +164,7 @@ export default defineComponent({
ibiz.net ibiz.net
.post(`/v7/loginPwd/sendVerificationCode/${username}`, {}) .post(`/v7/loginPwd/sendVerificationCode/${username}`, {})
.then((res: IData) => { .then((res: IData) => {
standCountdown();
if (res.ok) { if (res.ok) {
ibiz.notification.success({ ibiz.notification.success({
title: '获取验证码成功', title: '获取验证码成功',
...@@ -156,6 +176,7 @@ export default defineComponent({ ...@@ -156,6 +176,7 @@ export default 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 || '获取验证码失败',
}); });
...@@ -219,8 +240,14 @@ export default defineComponent({ ...@@ -219,8 +240,14 @@ export default defineComponent({
}} }}
placeholder='请输入验证码' placeholder='请输入验证码'
></i-input> ></i-input>
<i-button on-click={sendVerificationCode}> <i-button
获取验证码 class={ns.is('disabled', !!timer.value)}
disabled={!!timer.value}
on-click={sendVerificationCode}
>
{countdown.value > 0
? `${countdown.value}秒后重发`
: '获取验证码'}
</i-button> </i-button>
</i-form-item> </i-form-item>
<i-button type='text' on-click={onForget}> <i-button type='text' on-click={onForget}>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册