import React, {Component} from 'react'; import {Button, Card, Checkbox, Form, Input, Modal, Typography} from "antd"; import './Login.css' import request from "../common/request"; import {message} from "antd/es"; import {withRouter} from "react-router-dom"; import {LockOutlined, OneToOneOutlined, UserOutlined} from '@ant-design/icons'; import Particles from "react-tsparticles"; import Background from '../images/bg.png' import {setToken} from "../utils/utils"; const {Title} = Typography; class LoginForm extends Component { formRef = React.createRef(); totpInputRef = React.createRef(); state = { inLogin: false, height: window.innerHeight, width: window.innerWidth, loginAccount: undefined, totpModalVisible: false, confirmLoading: false }; componentDidMount() { window.addEventListener('resize', () => { this.setState({ height: window.innerHeight, width: window.innerWidth }) }); } handleSubmit = async params => { this.setState({ inLogin: true }); try { let result = await request.post('/login', params); if (result.code === 0) { // 进行双因子认证 this.setState({ loginAccount: params, totpModalVisible: true }) this.totpInputRef.current.focus(); return; } if (result.code !== 1) { throw new Error(result.message); } // 跳转登录 sessionStorage.removeItem('current'); sessionStorage.removeItem('openKeys'); setToken(result['data']); // this.props.history.push(); window.location.href = "/" } catch (e) { message.error(e.message); } finally { this.setState({ inLogin: false }); } }; handleOk = async (values) => { this.setState({ confirmLoading: true }) let loginAccount = this.state.loginAccount; loginAccount['totp'] = values['totp']; try { let result = await request.post('/loginWithTotp', loginAccount); if (result['code'] !== 1) { message.error(result['message']); return; } // 跳转登录 sessionStorage.removeItem('current'); sessionStorage.removeItem('openKeys'); setToken(result['data']); // this.props.history.push(); window.location.href = "/" } catch (e) { message.error(e.message); } finally { this.setState({ confirmLoading: false }); } } handleCancel = () => { this.setState({ totpModalVisible: false }) } render() { return (