import React, { Component } from 'react'; import { connect } from 'dva'; import { routerRedux, Link } from 'dva/router'; import { Form, Input, Tabs, Button, Icon, Checkbox, Row, Col, Alert } from 'antd'; import styles from './Login.less'; const FormItem = Form.Item; const TabPane = Tabs.TabPane; @connect(state => ({ login: state.login, })) @Form.create() export default class Login extends Component { state = { count: 0, type: 'account', } componentWillReceiveProps(nextProps) { if (nextProps.login.status === 'ok') { this.props.dispatch(routerRedux.push('/')); } } componentWillUnmount() { clearInterval(this.interval); } onSwitch = (key) => { this.setState({ type: key, }); } onGetCaptcha = () => { let count = 59; this.setState({ count }); this.interval = setInterval(() => { count -= 1; this.setState({ count }); if (count === 0) { clearInterval(this.interval); } }, 1000); } handleSubmit = (e) => { e.preventDefault(); const { type } = this.state; this.props.form.validateFields({ force: true }, (err, values) => { if (!err) { this.props.dispatch({ type: `login/${type}Submit`, payload: values, }); } } ); } msg = (message) => { return (); } render() { const { form, login } = this.props; const { getFieldDecorator } = form; const { count, type } = this.state; return (
{ login.status === 'error' && login.type === 'account' && login.submitting === false && this.msg('账户或密码错误') } {getFieldDecorator('userName', { rules: [{ required: type === 'account', message: '请输入账户名!', }], })( } placeholder="admin" /> )} {getFieldDecorator('password', { rules: [{ required: type === 'account', message: '请输入密码!', }], })( } type="password" placeholder="888888" /> )} { login.status === 'error' && login.type === 'mobile' && login.submitting === false && this.msg('验证码错误') } {getFieldDecorator('mobile', { rules: [{ required: type === 'mobile', message: '请输入手机号!', }, { pattern: /^1\d{10}$/, message: '手机号格式错误!', }], })( } placeholder="手机号" /> )} {getFieldDecorator('captcha', { rules: [{ required: type === 'mobile', message: '请输入验证码!', }], })( } placeholder="验证码" /> )} {getFieldDecorator('remember', { valuePropName: 'checked', initialValue: true, })( 自动登录 )} 忘记密码
其他登录方式 {/* 需要加到 Icon 中 */} 注册账户
); } }