App.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React, { Component } from 'react';
  2. import Routes from './routes';
  3. import DocumentTitle from 'react-document-title';
  4. import SiderCustom from './components/SiderCustom';
  5. import HeaderCustom from './components/HeaderCustom';
  6. import { Layout, notification, Icon } from 'antd';
  7. import { ThemePicker } from './components/widget';
  8. import { connectAlita } from 'redux-alita';
  9. import './data/index'
  10. const { Content, Footer } = Layout;
  11. class App extends Component {
  12. state = {
  13. collapsed: false,
  14. title: '',
  15. };
  16. componentWillMount() {
  17. const { setAlitaState } = this.props;
  18. const user = JSON.parse(localStorage.getItem('user'));
  19. // user && receiveData(user, 'auth');
  20. user && setAlitaState({ stateName: 'auth', data: user });
  21. // receiveData({a: 213}, 'auth');
  22. // fetchData({funcName: 'admin', stateName: 'auth'});
  23. this.getClientWidth();
  24. window.onresize = () => {
  25. console.log('屏幕变化了');
  26. this.getClientWidth();
  27. };
  28. }
  29. componentDidMount() {
  30. const openNotification = () => {
  31. notification.open({
  32. message: '博主-yezihaohao',
  33. description: (
  34. <div>
  35. <p>
  36. GitHub地址:{' '}
  37. <a
  38. href="https://github.com/yezihaohao"
  39. target="_blank"
  40. rel="noopener noreferrer"
  41. >
  42. https://github.com/yezihaohao
  43. </a>
  44. </p>
  45. <p>
  46. 博客地址:{' '}
  47. <a
  48. href="https://yezihaohao.github.io/"
  49. target="_blank"
  50. rel="noopener noreferrer"
  51. >
  52. https://yezihaohao.github.io/
  53. </a>
  54. </p>
  55. </div>
  56. ),
  57. icon: <Icon type="smile-circle" style={{ color: 'red' }} />,
  58. duration: 0,
  59. });
  60. localStorage.setItem('isFirst', JSON.stringify(true));
  61. };
  62. const isFirst = JSON.parse(localStorage.getItem('isFirst'));
  63. !isFirst && openNotification();
  64. }
  65. getClientWidth = () => {
  66. // 获取当前浏览器宽度并设置responsive管理响应式
  67. const { setAlitaState } = this.props;
  68. const clientWidth = window.innerWidth;
  69. console.log(clientWidth);
  70. setAlitaState({ stateName: 'responsive', data: { isMobile: clientWidth <= 992 } });
  71. // receiveData({isMobile: clientWidth <= 992}, 'responsive');
  72. };
  73. toggle = () => {
  74. this.setState({
  75. collapsed: !this.state.collapsed,
  76. });
  77. };
  78. render() {
  79. const { title } = this.state;
  80. const { auth = { data: {} }, responsive = { data: {} } } = this.props;
  81. console.log(auth);
  82. return (
  83. <DocumentTitle title={title}>
  84. <Layout>
  85. {!responsive.data.isMobile && <SiderCustom collapsed={this.state.collapsed} />}
  86. <ThemePicker />
  87. <Layout style={{ flexDirection: 'column' }}>
  88. <HeaderCustom
  89. toggle={this.toggle}
  90. collapsed={this.state.collapsed}
  91. user={auth.data || {}}
  92. />
  93. <Content style={{ margin: '0 16px', overflow: 'initial', flex: '1 1 0' }}>
  94. <Routes auth={auth} />
  95. </Content>
  96. <Footer style={{ textAlign: 'center' }}>
  97. React-Admin ©{new Date().getFullYear()} Created by 976056042@qq.com
  98. </Footer>
  99. </Layout>
  100. </Layout>
  101. </DocumentTitle>
  102. );
  103. }
  104. }
  105. export default connectAlita(['auth', 'responsive'])(App);