mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
登录增加错误延迟提醒
This commit is contained in:
parent
54bb13aad0
commit
622037ee98
|
@ -58,17 +58,6 @@ export default class AuthService {
|
||||||
);
|
);
|
||||||
return { code: 200, data: { token, lastip, lastaddr, lastlogon } };
|
return { code: 200, data: { token, lastip, lastaddr, lastlogon } };
|
||||||
} else {
|
} 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(
|
fs.writeFileSync(
|
||||||
config.authConfigFile,
|
config.authConfigFile,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
@ -76,9 +65,23 @@ export default class AuthService {
|
||||||
retries: retries + 1,
|
retries: retries + 1,
|
||||||
lastlogon: timestamp,
|
lastlogon: timestamp,
|
||||||
ip,
|
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 };
|
return { code: 400, message: config.authError };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -241,7 +241,7 @@ input:-webkit-autofill:active {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ant-message .ant-statistic {
|
.inline-countdown.ant-statistic {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
.ant-statistic-content {
|
.ant-statistic-content {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
|
|
@ -57,7 +57,11 @@ const CronLogModal = ({
|
||||||
content: (
|
content: (
|
||||||
<span>
|
<span>
|
||||||
系统将在
|
系统将在
|
||||||
<Countdown format="ss" value={Date.now() + 1000 * 10} />
|
<Countdown
|
||||||
|
className="inline-countdown"
|
||||||
|
format="ss"
|
||||||
|
value={Date.now() + 1000 * 10}
|
||||||
|
/>
|
||||||
秒后自动刷新
|
秒后自动刷新
|
||||||
</span>
|
</span>
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,14 +1,28 @@
|
||||||
import React, { Fragment, useEffect } from 'react';
|
import React, { Fragment, useEffect, useState } from 'react';
|
||||||
import { Button, Row, Input, Form, message, notification } from 'antd';
|
import {
|
||||||
|
Button,
|
||||||
|
Row,
|
||||||
|
Input,
|
||||||
|
Form,
|
||||||
|
message,
|
||||||
|
notification,
|
||||||
|
Statistic,
|
||||||
|
} from 'antd';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { history, Link } from 'umi';
|
import { history, Link } from 'umi';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
|
|
||||||
const FormItem = Form.Item;
|
const FormItem = Form.Item;
|
||||||
|
const { Countdown } = Statistic;
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [waitTime, setWaitTime] = useState<any>();
|
||||||
|
|
||||||
const handleOk = (values: any) => {
|
const handleOk = (values: any) => {
|
||||||
|
setLoading(true);
|
||||||
|
setWaitTime(null);
|
||||||
request
|
request
|
||||||
.post(`${config.apiPrefix}login`, {
|
.post(`${config.apiPrefix}login`, {
|
||||||
data: {
|
data: {
|
||||||
|
@ -36,12 +50,17 @@ const Login = () => {
|
||||||
history.push('/crontab');
|
history.push('/crontab');
|
||||||
} else if (data.code === 100) {
|
} else if (data.code === 100) {
|
||||||
message.warn(data.message);
|
message.warn(data.message);
|
||||||
|
} else if (data.code === 410) {
|
||||||
|
message.error(data.message);
|
||||||
|
setWaitTime(data.data);
|
||||||
} else {
|
} else {
|
||||||
message.error(data.message);
|
message.error(data.message);
|
||||||
}
|
}
|
||||||
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -82,13 +101,27 @@ const Login = () => {
|
||||||
<Input type="password" placeholder="密码" />
|
<Input type="password" placeholder="密码" />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<Row>
|
<Row>
|
||||||
|
{waitTime ? (
|
||||||
|
<Button type="primary" style={{ width: '100%' }} disabled>
|
||||||
|
请
|
||||||
|
<Countdown
|
||||||
|
valueStyle={{ color: 'rgba(232, 230, 227, 0.25)' }}
|
||||||
|
className="inline-countdown"
|
||||||
|
format="ss"
|
||||||
|
value={Date.now() + 1000 * waitTime}
|
||||||
|
/>
|
||||||
|
秒后重试
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
htmlType="submit"
|
htmlType="submit"
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
|
loading={loading}
|
||||||
>
|
>
|
||||||
登录
|
登录
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user