adminLogin.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. $.ajax({
  24. method: "POST",
  25. dataType: "json",
  26. crossDomain: false,
  27. url: globalConfig.context + "/adminLogin",
  28. data: {
  29. account: this.state.user,
  30. password: this.state.password,
  31. }
  32. })
  33. .done(
  34. function(data) {
  35. if (!data.error.length) {
  36. window.location.href =
  37. globalConfig.context + "/admin/index";
  38. } else {
  39. message.warning(data.error[0].message);
  40. }
  41. }.bind(this)
  42. )
  43. .always(
  44. function() {
  45. this.setState({
  46. loading: false
  47. });
  48. }.bind(this)
  49. );
  50. };
  51. },
  52. keyboard(event) {
  53. if (event.keyCode == 13) {
  54. this.handleSubmit()
  55. }
  56. },
  57. getUser(event) {
  58. this.setState({ user: event.target.value });
  59. },
  60. getPassword(event) {
  61. this.setState({ password: event.target.value });
  62. },
  63. onChange(event) {
  64. this.setState({ checked: event.target.checked });
  65. },
  66. render() {
  67. return (
  68. <div className="login-box">
  69. <Spin spinning={this.state.loading} className='spin-box'>
  70. <div className="user-box">
  71. <Input onChange={this.getUser}
  72. onKeyDown={this.keyboard} placeholder="账号" value={this.state.user}
  73. addonBefore={<Icon type="user" />} />
  74. </div>
  75. <div className="pw-box">
  76. <Input onChange={this.getPassword}
  77. onKeyDown={this.keyboard} type="password" placeholder="密码" value={this.state.password}
  78. addonBefore={<Icon type="lock" />}
  79. />
  80. </div>
  81. <Button type="primary" onClick={this.handleSubmit}>登录</Button>
  82. </Spin>
  83. </div>
  84. );
  85. }
  86. });
  87. export default Login;