loginForm.jsx 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from 'react';
  2. import { Form, Icon, Input, Button, Checkbox, Spin, message } from 'antd';
  3. import './login.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. import ForgetPw from './forgetPw.jsx';
  7. const FormItem = Form.Item;
  8. const LoginForm = Form.create()(React.createClass({
  9. getInitialState() {
  10. return {
  11. loading: false
  12. };
  13. },
  14. handleSubmit(e) {
  15. e.preventDefault();
  16. this.props.form.validateFields((err, values) => {
  17. if (!err) {
  18. this.props.spinState(true);
  19. $.ajax({
  20. method: "POST",
  21. dataType: "json",
  22. url: globalConfig.context + "/signin",
  23. data: {
  24. "mobile": values.phone,
  25. "password": values.password,
  26. "type": this.props.loginProp,
  27. "remember": values.remember
  28. }
  29. }).done(function (res) {
  30. if (!res.error.length) {
  31. let data = res.data;
  32. if (data && data.requestURI) {
  33. let path = globalConfig.context + data.requestURI
  34. if (data.queryString) {
  35. path += '?' + data.queryString;
  36. }
  37. if (window.location.hash) {
  38. path += window.location.hash;
  39. }
  40. window.location.href = path;
  41. } else {
  42. window.location.href = globalConfig.context + "/user/account/index.html";
  43. }
  44. } else {
  45. message.warning(res.error[0].message);
  46. }
  47. }.bind(this)).always(function () {
  48. this.props.spinState(false);
  49. }.bind(this));
  50. }
  51. });
  52. },
  53. render() {
  54. const { getFieldDecorator } = this.props.form;
  55. return (
  56. <Form onSubmit={this.handleSubmit} className="login-form">
  57. <FormItem>
  58. {getFieldDecorator('phone', {
  59. rules: [{ required: true, message: '请输入手机号!' }],
  60. })(
  61. <Input addonBefore={<Icon type="user" />} placeholder="手机号" />
  62. )}
  63. </FormItem>
  64. <FormItem>
  65. {getFieldDecorator('password', {
  66. rules: [{ required: true, message: '请输入密码!' }],
  67. })(
  68. <Input addonBefore={<Icon type="lock" />} type="password" placeholder="密码" />
  69. )}
  70. </FormItem>
  71. <FormItem>
  72. {getFieldDecorator('remember', {
  73. valuePropName: 'checked',
  74. initialValue: false,
  75. })(
  76. <Checkbox>记住我</Checkbox>
  77. )}
  78. <ForgetPw theType={this.props.loginProp} />
  79. <Button type="primary" htmlType="submit" className="login-form-button">
  80. 登录
  81. </Button>
  82. </FormItem>
  83. </Form>
  84. );
  85. },
  86. }));
  87. export default LoginForm;