| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 | import React from 'react';import { Form, Icon, Input, Button, Checkbox, Spin, message } from 'antd';import './login.less';import ajax from 'jquery/src/ajax/xhr.js'import $ from 'jquery/src/ajax';import ForgetPw from './forgetPw.jsx';const FormItem = Form.Item;const LoginForm = Form.create()(React.createClass({    getInitialState() {        return {            loading: false        };    },    handleSubmit(e) {        e.preventDefault();        this.props.form.validateFields((err, values) => {            if (!err) {                this.props.spinState(true);                $.ajax({                    method: "POST",                    dataType: "json",                    url: globalConfig.context + "/signin",                    data: {                        "mobile": values.phone,                        "password": values.password,                        "type": this.props.loginProp,                        "remember": values.remember                    }                }).done(function (res) {                    if (!res.error.length) {                        let data = res.data;                        if (data && data.requestURI) {                            let path = globalConfig.context + data.requestURI                            if (data.queryString) {                                path += '?' + data.queryString;                            }                            if (window.location.hash) {                                path += window.location.hash;                            }                            window.location.href = path;                        } else {                            window.location.href = globalConfig.context + "/user/account/index.html";                        }                    } else {                        message.warning(res.error[0].message);                    }                }.bind(this)).always(function () {                    this.props.spinState(false);                }.bind(this));            }        });    },    render() {        const { getFieldDecorator } = this.props.form;        return (            <Form onSubmit={this.handleSubmit} className="login-form">                <FormItem>                    {getFieldDecorator('phone', {                        rules: [{ required: true, message: '请输入手机号!' }],                    })(                        <Input addonBefore={<Icon type="user" />} placeholder="手机号" />                        )}                </FormItem>                <FormItem>                    {getFieldDecorator('password', {                        rules: [{ required: true, message: '请输入密码!' }],                    })(                        <Input addonBefore={<Icon type="lock" />} type="password" placeholder="密码" />                        )}                </FormItem>                <FormItem>                    {getFieldDecorator('remember', {                        valuePropName: 'checked',                        initialValue: false,                    })(                        <Checkbox>记住我</Checkbox>                        )}                    <ForgetPw theType={this.props.loginProp} />                    <Button type="primary" htmlType="submit" className="login-form-button">                        登录                    </Button>                </FormItem>            </Form>        );    },}));export default LoginForm;
 |