|
| 1 | +import { Button, Form, Icon, Input } from 'antd'; |
| 2 | +import { FormComponentProps } from 'antd/lib/form'; |
| 3 | +import { connect } from 'dva'; |
1 | 4 | import React, { PureComponent } from 'react'; |
| 5 | +import { EmailRxp } from '../../utils/constant'; |
2 | 6 | import styles from './Login.module.scss'; |
3 | 7 |
|
4 | | -export default class Login extends PureComponent { |
| 8 | +interface FormProps extends FormComponentProps { |
| 9 | + email: string; |
| 10 | + password: string; |
| 11 | +} |
| 12 | + |
| 13 | +interface DvaProps { |
| 14 | + loading: boolean; |
| 15 | + login: (params: any) => void; |
| 16 | +} |
| 17 | + |
| 18 | +interface InternalProps extends DvaProps { |
| 19 | + form: any; |
| 20 | +} |
| 21 | + |
| 22 | +export class Login extends PureComponent<InternalProps> { |
| 23 | + |
| 24 | + public onSubmit = () => { |
| 25 | + const { login, form } = this.props; |
| 26 | + const { validateFields } = form; |
| 27 | + |
| 28 | + validateFields((err: any, values: any) => { |
| 29 | + if (!err) { |
| 30 | + login(values); |
| 31 | + } |
| 32 | + }); |
| 33 | + } |
5 | 34 |
|
6 | 35 | public render() { |
| 36 | + const color = 'rgba(0,0,0,.25)'; |
| 37 | + const { form, loading } = this.props; |
| 38 | + const { getFieldDecorator } = form; |
| 39 | + |
7 | 40 | return ( |
8 | 41 | <div className={styles.login}> |
9 | | - Login |
| 42 | + <svg className="Header__svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1337.97 684.43"> |
| 43 | + <path |
| 44 | + className="Header__shape bigSquare" fill="#16d5d1" |
| 45 | + d="M546.519 349.271l86.383-56.098 56.097 86.383-86.383 56.098z" |
| 46 | + /> |
| 47 | + <path |
| 48 | + className="Header__shape triangle" |
| 49 | + fill="none" stroke="#ff4676" strokeWidth="8" |
| 50 | + d="M372.15 462.17L321 434.58l-4.88 56.16z" |
| 51 | + /> |
| 52 | + <circle |
| 53 | + className="Header__shape bigCircle" |
| 54 | + fill="#ff4676" cx="1076.52" cy="262.17" r="59" |
| 55 | + /> |
| 56 | + <path |
| 57 | + className="Header__shape littleSquare" fill="#ffe430" |
| 58 | + d="M285.523 262.61l12.372-53.59 53.59 12.372-12.372 53.59z" |
| 59 | + /> |
| 60 | + <circle |
| 61 | + className="Header__shape hoop" fill="none" stroke="#ffe430" |
| 62 | + strokeWidth="13" cx="905.52" cy="447.17" r="45" |
| 63 | + /> |
| 64 | + <circle |
| 65 | + className="Header__shape littleCircle" |
| 66 | + fill="#0f1c70" cx="1036.52" cy="203.17" r="27" |
| 67 | + /> |
| 68 | + </svg> |
| 69 | + <Form style={{ width: 320 }} onSubmit={this.onSubmit}> |
| 70 | + <Form.Item> |
| 71 | + {getFieldDecorator('email', { |
| 72 | + rules: [ |
| 73 | + { required: true, message: 'Please input email!' }, |
| 74 | + { pattern: EmailRxp, message: 'Please input right email!' }, |
| 75 | + ], |
| 76 | + })( |
| 77 | + <Input |
| 78 | + prefix={<Icon type="inbox" style={{ color }} />} |
| 79 | + placeholder="Email" |
| 80 | + /> |
| 81 | + )} |
| 82 | + </Form.Item> |
| 83 | + <Form.Item> |
| 84 | + {getFieldDecorator('password', { |
| 85 | + rules: [ |
| 86 | + { required: true, message: 'Please input password!' }, |
| 87 | + ], |
| 88 | + })( |
| 89 | + <Input |
| 90 | + type="password" |
| 91 | + prefix={<Icon type="key" style={{ color }} />} |
| 92 | + placeholder="Password" |
| 93 | + /> |
| 94 | + )} |
| 95 | + </Form.Item> |
| 96 | + <Form.Item> |
| 97 | + <Button block type="primary" htmlType="submit" loading={loading}> |
| 98 | + 登录 |
| 99 | + </Button> |
| 100 | + </Form.Item> |
| 101 | + </Form> |
10 | 102 | </div> |
11 | 103 | ); |
12 | 104 | } |
13 | 105 | } |
| 106 | + |
| 107 | +const CreateLogin = Form.create<FormProps>()(Login); |
| 108 | + |
| 109 | +const mapStateToProps = ({ global, loading }: any) => { |
| 110 | + return { |
| 111 | + loading: loading.effects['global/login'], |
| 112 | + }; |
| 113 | +}; |
| 114 | + |
| 115 | +const mapDispatchToProps = (dispatch: any, ownProps: any) => { |
| 116 | + return { |
| 117 | + login: (params: object) => { |
| 118 | + dispatch({ |
| 119 | + type: 'global/login', |
| 120 | + payload: params, |
| 121 | + }); |
| 122 | + }, |
| 123 | + }; |
| 124 | +}; |
| 125 | + |
| 126 | +export default connect(mapStateToProps, mapDispatchToProps)(CreateLogin); |
0 commit comments