import React, { Component } from 'react'; import { connect } from 'dva'; import Link from 'umi/link'; import { Checkbox, Alert, Icon } from 'antd'; import Login from '@/components/Login'; import styles from './Login.less'; const { Tab, UserName, Password, Mobile, Captcha, Submit } = Login; @connect(({ login, loading }) => ({ login, submitting: loading.effects['login/login'], })) class LoginPage extends Component { state = { type: 'account', autoLogin: true, }; onTabChange = type => { this.setState({ type }); }; onGetCaptcha = () => new Promise((resolve, reject) => { this.loginForm.validateFields(['mobile'], {}, (err, values) => { if (err) { reject(err); } else { const { dispatch } = this.props; dispatch({ type: 'login/getCaptcha', payload: values.mobile, }) .then(resolve) .catch(reject); } }); }); handleSubmit = (err, values) => { const { type } = this.state; if (!err) { const { dispatch } = this.props; dispatch({ type: 'login/login', payload: { ...values, type, }, }); } }; changeAutoLogin = e => { this.setState({ autoLogin: e.target.checked, }); }; renderMessage = content => ( ); render() { const { login, submitting } = this.props; const { type, autoLogin } = this.state; return (
{ this.loginForm = form; }} > {login.status === 'error' && login.type === 'account' && !submitting && this.renderMessage('账户或密码错误(admin/888888)')} this.loginForm.validateFields(this.handleSubmit)} /> {login.status === 'error' && login.type === 'mobile' && !submitting && this.renderMessage('验证码错误')}
自动登录 忘记密码
登录
其他登录方式 注册账户
); } } export default LoginPage;