import React, { Component } from 'react'; import { connect } from 'dva'; import { formatMessage, FormattedMessage } from 'umi-plugin-react/locale'; import Link from 'umi/link'; import { Checkbox, Alert, Icon } from 'antd'; import { Login } from 'ant-design-pro'; import styles from './style.less'; const { Tab, UserName, Password, Mobile, Captcha, Submit } = Login; @connect(({ BLOCK_NAME_CAMEL_CASE, loading }) => ({ BLOCK_NAME_CAMEL_CASE, submitting: loading.effects['BLOCK_NAME_CAMEL_CASE/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: 'BLOCK_NAME_CAMEL_CASE/getCaptcha', payload: values.mobile, }) .then(resolve) .catch(reject); } }); }); handleSubmit = (err, values) => { const { type } = this.state; if (!err) { const { dispatch } = this.props; dispatch({ type: 'BLOCK_NAME_CAMEL_CASE/login', payload: { ...values, type, }, }); } }; changeAutoLogin = e => { this.setState({ autoLogin: e.target.checked, }); }; renderMessage = content => ( ); render() { const { BLOCK_NAME_CAMEL_CASE, submitting } = this.props; const { status, type: loginType } = BLOCK_NAME_CAMEL_CASE; const { type, autoLogin } = this.state; return (
{ this.loginForm = form; }} > {status === 'error' && loginType === 'account' && !submitting && this.renderMessage( formatMessage({ id: 'BLOCK_NAME.login.message-invalid-credentials' }) )} this.loginForm.validateFields(this.handleSubmit)} /> {status === 'error' && loginType === 'mobile' && !submitting && this.renderMessage( formatMessage({ id: 'BLOCK_NAME.login.message-invalid-verification-code' }) )}
); } } export default LoginPage;