loginForm.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. "username": values.phone,
  25. "password": values.password,
  26. "type": 0,
  27. }
  28. }).done(function (res) {
  29. if (res.error && res.error.length) {
  30. message.warning(res.error[0].message);
  31. } else {
  32. let data = res.data;
  33. if (data && data.requestURI) {
  34. let path = globalConfig.context + data.requestURI
  35. if (data.queryString) {
  36. path += '?' + data.queryString;
  37. }
  38. if (window.location.hash) {
  39. path += window.location.hash;
  40. }
  41. window.location.href = path;
  42. } else {
  43. window.location.href = globalConfig.context + "/user/account/index.html";
  44. }
  45. }
  46. }.bind(this)).always(function () {
  47. this.props.spinState(false);
  48. }.bind(this));
  49. }
  50. });
  51. },
  52. render() {
  53. const { getFieldDecorator } = this.props.form;
  54. return (
  55. <Form onSubmit={this.handleSubmit} className="login-form">
  56. <FormItem>
  57. {getFieldDecorator('phone', {
  58. rules: [{ required: true, message: '请输入用户名!' }],
  59. })(
  60. <Input addonBefore={<Icon type="user" />} placeholder="手机号" />
  61. )}
  62. </FormItem>
  63. <FormItem>
  64. {getFieldDecorator('password', {
  65. rules: [{ required: true, message: '请输入密码!' }],
  66. })(
  67. <Input addonBefore={<Icon type="lock" />} type="password" placeholder="密码" />
  68. )}
  69. </FormItem>
  70. <FormItem>
  71. {getFieldDecorator('remember', {
  72. valuePropName: 'checked',
  73. initialValue: false,
  74. })(
  75. <Checkbox>记住我</Checkbox>
  76. )}
  77. <ForgetPw theType={this.props.loginProp} />
  78. <Button type="primary" htmlType="submit" className="login-form-button">
  79. 登录
  80. </Button>
  81. </FormItem>
  82. </Form>
  83. );
  84. },
  85. }));
  86. export default LoginForm;