adminLogin.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { Input, Button, Checkbox, message, Spin, Icon } from 'antd';
  4. import './adminLogin.less';
  5. import ajax from 'jquery/src/ajax/xhr.js'
  6. import $ from 'jquery/src/ajax';
  7. var Login = React.createClass({
  8. getInitialState() {
  9. return {
  10. user: '',
  11. password: '',
  12. checked: '',
  13. loading: false
  14. };
  15. },
  16. handleSubmit() {
  17. if (this.state.user === "" || this.state.password === "") {
  18. message.warning('账号或者密码不能为空!');
  19. } else {
  20. this.setState({
  21. loading: true
  22. });
  23. // debugger
  24. $.ajax({
  25. method: "POST",
  26. dataType: "json",
  27. crossDomain: false,
  28. url: globalConfig.context + "/managesignin",
  29. data: {
  30. mobile: this.state.user,
  31. password: this.state.password,
  32. remeber: false
  33. }
  34. }).done(function (data) {
  35. if (!data.error.length) {
  36. window.location.href = globalConfig.context + "/admin/index.html";
  37. } else {
  38. message.warning(data.error[0].message);
  39. }
  40. }.bind(this)).always(function () {
  41. this.setState({
  42. loading: false
  43. });
  44. }.bind(this));
  45. };
  46. },
  47. keyboard(event) {
  48. if (event.keyCode == 13) {
  49. this.handleSubmit()
  50. }
  51. },
  52. getUser(event) {
  53. this.setState({ user: event.target.value });
  54. },
  55. getPassword(event) {
  56. this.setState({ password: event.target.value });
  57. },
  58. onChange(event) {
  59. this.setState({ checked: event.target.checked });
  60. },
  61. render() {
  62. return (
  63. <div className="login-box">
  64. <Spin spinning={this.state.loading} className='spin-box'>
  65. <div className="user-box">
  66. <Input onChange={this.getUser}
  67. onKeyDown={this.keyboard} placeholder="账号" value={this.state.user}
  68. addonBefore={<Icon type="user" />} />
  69. </div>
  70. <div className="pw-box">
  71. <Input onChange={this.getPassword}
  72. onKeyDown={this.keyboard} type="password" placeholder="密码" value={this.state.password}
  73. addonBefore={<Icon type="lock" />}
  74. />
  75. </div>
  76. <Button type="primary" onClick={this.handleSubmit}>登录</Button>
  77. </Spin>
  78. </div>
  79. );
  80. }
  81. });
  82. export default Login;