topTab.jsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import { Row, Col } 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: '管理员',
  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 + "/admin/login.html"
  19. });
  20. },
  21. componentWillMount () {
  22. this.loadData();
  23. },
  24. loadData() {
  25. this.setState({
  26. loading: true
  27. });
  28. $.ajax({
  29. method: "get",
  30. dataType: "json",
  31. crossDomain: false,
  32. url: globalConfig.context + "/api/admin/notice/unreadCount",
  33. success: function (data) {
  34. if (!data.data) {
  35. if (data.error[0] && data.error[0]) {
  36. message.warning(data.error[0].message);
  37. return;
  38. };
  39. };
  40. this.setState({
  41. badge: data.data,
  42. });
  43. }.bind(this),
  44. }).always(function (data) {
  45. this.setState({
  46. loading: false
  47. });
  48. }.bind(this));
  49. },
  50. render() {
  51. return (
  52. <div className="account-top" >
  53. <div className="acc-top-user">
  54. <span className="acc-top-user-name">欢迎您, {this.state.username||adminData.name || adminData.mobile } <a onClick={this.logOut}>[ 退出 ]</a></span>
  55. <span className="acc-top-user-toindex"><a href={globalConfig.context + "/portal/index.html"}>返回首页</a></span>
  56. </div >
  57. </div >
  58. )
  59. }
  60. });
  61. export default TopTab;