From 622037ee98712c53aa85d9e64a781c103f5a9f16 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Sun, 22 Aug 2021 12:28:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=A2=9E=E5=8A=A0=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=BB=B6=E8=BF=9F=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/auth.ts | 27 ++++++++++-------- src/layouts/index.less | 2 +- src/pages/crontab/logModal.tsx | 6 +++- src/pages/login/index.tsx | 51 ++++++++++++++++++++++++++++------ 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/back/services/auth.ts b/back/services/auth.ts index ac8fba81..a2a47cd9 100644 --- a/back/services/auth.ts +++ b/back/services/auth.ts @@ -58,17 +58,6 @@ export default class AuthService { ); return { code: 200, data: { token, lastip, lastaddr, lastlogon } }; } else { - if ( - retries > 2 && - Date.now() - lastlogon < Math.pow(3, retries) * 1000 - ) { - return { - code: 400, - message: `失败次数过多,请${Math.round( - (Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000, - )}秒后重试`, - }; - } fs.writeFileSync( config.authConfigFile, JSON.stringify({ @@ -76,9 +65,23 @@ export default class AuthService { retries: retries + 1, lastlogon: timestamp, ip, - address, + lastaddr: address, }), ); + if ( + retries > 2 && + Date.now() - lastlogon < Math.pow(3, retries) * 1000 + ) { + return { + code: 410, + message: `失败次数过多,请${Math.round( + (Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000, + )}秒后重试`, + data: Math.round( + (Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000, + ), + }; + } return { code: 400, message: config.authError }; } } else { diff --git a/src/layouts/index.less b/src/layouts/index.less index 0df79f86..c6b3735c 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -241,7 +241,7 @@ input:-webkit-autofill:active { } } -.ant-message .ant-statistic { +.inline-countdown.ant-statistic { display: inline-block; .ant-statistic-content { font-size: 14px; diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index b33faca4..9ed12e03 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -57,7 +57,11 @@ const CronLogModal = ({ content: ( 系统将在 - + 秒后自动刷新 ), diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 5c754e1f..d9cc7143 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -1,14 +1,28 @@ -import React, { Fragment, useEffect } from 'react'; -import { Button, Row, Input, Form, message, notification } from 'antd'; +import React, { Fragment, useEffect, useState } from 'react'; +import { + Button, + Row, + Input, + Form, + message, + notification, + Statistic, +} from 'antd'; import config from '@/utils/config'; import { history, Link } from 'umi'; import styles from './index.less'; import { request } from '@/utils/http'; const FormItem = Form.Item; +const { Countdown } = Statistic; const Login = () => { + const [loading, setLoading] = useState(false); + const [waitTime, setWaitTime] = useState(); + const handleOk = (values: any) => { + setLoading(true); + setWaitTime(null); request .post(`${config.apiPrefix}login`, { data: { @@ -36,12 +50,17 @@ const Login = () => { history.push('/crontab'); } else if (data.code === 100) { message.warn(data.message); + } else if (data.code === 410) { + message.error(data.message); + setWaitTime(data.data); } else { message.error(data.message); } + setLoading(false); }) .catch(function (error) { console.log(error); + setLoading(false); }); }; @@ -82,13 +101,27 @@ const Login = () => { - + {waitTime ? ( + + ) : ( + + )}