index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React from 'react';
  2. import Media from 'react-media';
  3. import { connect } from 'dva';
  4. import PageLoading from '@/components/PageLoading';
  5. import BasicLayout from './BasicLayout';
  6. class LayoutWrapper extends React.PureComponent {
  7. componentDidMount() {
  8. const { dispatch, currentSite } = this.props;
  9. dispatch({ type: 'global/get_site_list_data', payload: { isAll: true } });
  10. }
  11. render() {
  12. const { currentSite } = this.props;
  13. if (!currentSite) {
  14. // 非 apply 页且未初始化完成 → Loading
  15. return (
  16. <div style={{ height: '100vh', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
  17. <PageLoading />
  18. </div>
  19. );
  20. }
  21. //currentSite 已有值 → 渲染 BasicLayout(key 确保切换站点强制刷新)
  22. return (
  23. <Media query="(max-width: 599px)">
  24. {isMobile => (
  25. <BasicLayout
  26. key={currentSite}
  27. {...this.props}
  28. isMobile={isMobile}
  29. />
  30. )}
  31. </Media>
  32. );
  33. }
  34. }
  35. export default connect(({ global, setting, menu }) => ({
  36. collapsed: global.collapsed,
  37. currentSite: global.currentSite,
  38. layout: setting.layout,
  39. menuData: menu.menuData,
  40. breadcrumbNameMap: menu.breadcrumbNameMap,
  41. ...setting,
  42. }))(LayoutWrapper);