import React from 'react'; import Avatar from '@material-ui/core/Avatar'; import Button from '@material-ui/core/Button'; import CssBaseline from '@material-ui/core/CssBaseline'; import TextField from '@material-ui/core/TextField'; import Typography from '@material-ui/core/Typography'; import Container from '@material-ui/core/Container'; import {withStyles} from '@material-ui/core/styles'; import LogoSrc from './logo.jpg'; import {withRouter} from "react-router-dom"; import Modal from '@material-ui/core/Modal'; import Backdrop from '@material-ui/core/Backdrop'; import Fade from '@material-ui/core/Fade'; const useStyles = theme => ({ paper: { marginTop: theme.spacing(8), display: 'flex', flexDirection: 'column', alignItems: 'center', '& > *': { marginTop: theme.spacing(2), }, }, avatar: { width: '120px', height: '120px', margin: theme.spacing(1), backgroundColor: theme.palette.secondary.main, }, form: { width: '100%', // Fix IE 11 issue. marginTop: theme.spacing(1), }, submit: { margin: theme.spacing(3, 0, 2), }, modalPaper: { backgroundColor: theme.palette.background.paper, border: '2px solid #000', boxShadow: theme.shadows[5], padding: theme.spacing(2, 4, 3), }, modal: { display: 'flex', alignItems: 'center', justifyContent: 'center', }, }); class Login extends React.Component { constructor(props) { super(props); this.state = {open: false}; this.login = this.login.bind(this); this.handleOpenModal = this.handleOpenModal.bind(this); this.handleCloseModal = this.handleCloseModal.bind(this); } handleOpenModal() { this.setState({open: true}); } handleCloseModal() { this.setState({open: false}); } login(event) { event.preventDefault(); const username = event.target['username'].value; const password = event.target['password'].value; fetch('/login', { method: 'Post', body: JSON.stringify({ username, password }) }) .then(response => response.json()) .then(json => { if (json.result === 'success') { this.props.history.push('/register'); } else { this.handleOpenModal(); } }); } render() { return (
{"logo"} 请登录

登录失败

请检查用户名和密码后重试

); } } export default withRouter(withStyles(useStyles)(Login));