topTab.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React from 'react';
  2. import { Row, Col, message, Badge } from 'antd';
  3. import './topTab.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. const TopTab = React.createClass({
  7. getInitialState() {
  8. return {
  9. username: 'username',
  10. };
  11. },
  12. logOut() {
  13. $.ajax({
  14. method: "get",
  15. dataType: "json",
  16. url: globalConfig.context + "/login",
  17. }).done(function (data) {
  18. window.location.href = globalConfig.context + "/portal/index.html"
  19. });
  20. },
  21. componentWillMount() {
  22. this.getData();
  23. },
  24. getData() {
  25. this.setState({
  26. loading: false
  27. });
  28. $.ajax({
  29. method: "get",
  30. dataType: "json",
  31. url: globalConfig.context + "/api/user/nickname"
  32. }).done(function (data) {
  33. if (data.error && data.error.length) {
  34. message.warning(data.error[0].message);
  35. } else {
  36. this.setState({
  37. nickname: data.data,
  38. })
  39. }
  40. }.bind(this)).always(function () {
  41. this.setState({
  42. loading: false
  43. });
  44. }.bind(this));
  45. },
  46. render() {
  47. return (
  48. <div className="account-top" >
  49. <div className="acc-top-user">
  50. <span className="acc-top-user-name">欢迎您, {this.state.nickname || userData.nickname || userData.number} <a onClick={this.logOut}>[ 退出 ]</a></span>
  51. <span className="acc-top-user-toindex"><a href={globalConfig.context + "/portal/index.html"}>返回首页</a></span>
  52. </div>
  53. </div>
  54. )
  55. }
  56. });
  57. export default TopTab;