import React, { Component } from 'react'; import { connect } from 'dva'; import { routerRedux, Link } from 'dva/router'; import { Form, Input, Button, Select, Row, Col, Popover, Progress } from 'antd'; import styles from './Register.less'; const FormItem = Form.Item; const { Option } = Select; const InputGroup = Input.Group; const passwordStatusMap = { ok:
强度:强
, pass:强度:中
, pool:强度:太短
, }; const passwordProgressMap = { ok: 'success', pass: 'normal', pool: 'exception', }; @connect(state => ({ register: state.register, })) @Form.create() export default class Register extends Component { state = { count: 0, confirmDirty: false, visible: false, help: '', } componentWillReceiveProps(nextProps) { if (nextProps.register.status === 'ok') { this.props.dispatch(routerRedux.push('/user/register-result')); } } componentWillUnmount() { clearInterval(this.interval); } onGetCaptcha = () => { let count = 59; this.setState({ count }); this.interval = setInterval(() => { count -= 1; this.setState({ count }); if (count === 0) { clearInterval(this.interval); } }, 1000); } getPasswordStatus = () => { const { form } = this.props; const value = form.getFieldValue('password'); if (value && value.length > 9) { return 'ok'; } if (value && value.length > 5) { return 'pass'; } return 'pool'; } handleSubmit = (e) => { e.preventDefault(); this.props.form.validateFields({ force: true }, (err, values) => { if (!err) { this.props.dispatch({ type: 'register/submit', payload: values, }); } } ); } handleConfirmBlur = (e) => { const { value } = e.target; this.setState({ confirmDirty: this.state.confirmDirty || !!value }); } checkConfirm = (rule, value, callback) => { const { form } = this.props; if (value && value !== form.getFieldValue('password')) { callback('两次输入的密码不匹配!'); } else { callback(); } } checkPassword = (rule, value, callback) => { if (!value) { this.setState({ help: '请输入密码!', visible: !!value, }); callback('error'); } else { this.setState({ help: '', }); if (!this.state.visible) { this.setState({ visible: !!value, }); } if (value.length < 6) { callback('error'); } else { const { form } = this.props; if (value && this.state.confirmDirty) { form.validateFields(['confirm'], { force: true }); } callback(); } } } renderPasswordProgress = () => { const { form } = this.props; const value = form.getFieldValue('password'); const passwordStatus = this.getPasswordStatus(); return value && value.length ?