import React, { PureComponent as Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { Form, Button, Input, Icon, message, Radio } from 'antd'; import { loginActions, loginLdapActions } from '../../reducer/modules/user'; import { withRouter } from 'react-router'; const FormItem = Form.Item; const RadioGroup = Radio.Group; import './Login.scss'; const formItemStyle = { marginBottom: '.16rem' }; const changeHeight = { height: '.42rem' }; @connect( state => { return { loginData: state.user, isLDAP: state.user.isLDAP }; }, { loginActions, loginLdapActions } ) @withRouter class Login extends Component { constructor(props) { super(props); this.state = { loginType: 'ldap' }; } static propTypes = { form: PropTypes.object, history: PropTypes.object, loginActions: PropTypes.func, loginLdapActions: PropTypes.func, isLDAP: PropTypes.bool }; handleSubmit = e => { e.preventDefault(); const form = this.props.form; form.validateFields((err, values) => { if (!err) { if (this.props.isLDAP && this.state.loginType === 'ldap') { this.props.loginLdapActions(values).then(res => { if (res.payload.data.errcode == 0) { this.props.history.replace('/group'); message.success('登录成功! '); } }); } else { this.props.loginActions(values).then(res => { if (res.payload.data.errcode == 0) { this.props.history.replace('/group'); message.success('登录成功! '); } }); } } }); }; componentDidMount() { //Qsso.attach('qsso-login','/api/user/login_by_token') console.log('isLDAP', this.props.isLDAP); } handleFormLayoutChange = e => { this.setState({ loginType: e.target.value }); }; render() { const { getFieldDecorator } = this.props.form; const { isLDAP } = this.props; const emailRule = this.state.loginType === 'ldap' ? {} : { required: true, message: '请输入正确的email!', pattern: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,})+$/ }; return (
); } } const LoginForm = Form.create()(Login); export default LoginForm;