index.js 2.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
import React from 'react';
import { connect } from 'dva';
import router from 'umi/router';
import store from '@/utils/store';
import { Input, Icon, Button, message } from 'antd';
import config from '@/config';
import styles from './index.less';

@connect()
class Login extends React.Component {
  state = {
    username: '',
    password: '',
  };

  localOnChangeUserName = e => {
    this.setState({ username: e.target.value });
  };

  localOnChangePassWord = e => {
    this.setState({ password: e.target.value });
  };

  login = () => {
    const { username, password } = this.state;
    const { dispatch } = this.props;
    dispatch({
      type: 'login/login',
      payload: { userName: username, password },
    }).then(({ code, data }) => {
      if (code === 'sys.success') {
        const { token, userId } = data;
        // message.success("η™»ε½•ζˆεŠŸ");
        store.set('token', token);
        store.set('userId', userId);
        router.push(config.home || '/profile/message');
      }
    });
  };

  render() {
    return (
      <div className={styles.root}>
        <div className={styles.container}>
          <div className={styles.box}>
            <div className={styles.title}>KIM3.0 εΉ³ε°δΈšεŠ‘ζžΆζž„</div>
            <Input
              className={styles.username}
              onChange={this.localOnChangeUserName}
              prefix={<Icon type="user" />}
              placeholder="θ―·θΎ“ε…₯账号"
            />
            <Input
              className={styles.password}
              onChange={this.localOnChangePassWord}
              type="password"
              prefix={<Icon type="lock" />}
              placeholder="θ―·θΎ“ε…₯密码"
              onPressEnter={this.login}
            />
            <Button className={styles.submit} type="primary" onClick={this.login}>
              登录
            </Button>
          </div>
          {/* <div className={styles.more}>
            <div className={styles.info} />
            <div className={styles.rights}>
              <span>copyright</span>
              <span>2019 KIM3.0ζŠ€ζœ―δΈ­ε°ιƒ¨ε‡Ίε“</span>
            </div>
          </div> */}
        </div>

        <div className={styles.line} />
      </div>
    );
  }
}

export default Login;