index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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, location } = this.props;
  9. const isApplyPage = location.pathname.includes('/apply');
  10. // 非 apply 页 & currentSite 为空,初始化请求
  11. if (!isApplyPage) {
  12. dispatch({ type: 'global/get_site_list_data', payload: { isAll: true } });
  13. }
  14. }
  15. render() {
  16. const { currentSite, location } = this.props;
  17. const isApplyPage = location.pathname.includes('/apply');
  18. if (isApplyPage) {
  19. // apply 页直接加载 BasicLayout
  20. return (
  21. <Media query="(max-width: 599px)">
  22. {isMobile => <BasicLayout {...this.props} isMobile={isMobile} />}
  23. </Media>
  24. );
  25. }
  26. if (!currentSite) {
  27. // 非 apply 页且未初始化完成 → Loading
  28. return (
  29. <div style={{ height: '100vh', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
  30. <PageLoading />
  31. </div>
  32. );
  33. }
  34. // 非 apply 页 & currentSite 已有值 → 渲染 BasicLayout(key 确保切换站点强制刷新)
  35. return (
  36. <Media query="(max-width: 599px)">
  37. {isMobile => (
  38. <BasicLayout
  39. key={currentSite}
  40. {...this.props}
  41. isMobile={isMobile}
  42. />
  43. )}
  44. </Media>
  45. );
  46. }
  47. }
  48. export default connect(({ global, setting, menu }) => ({
  49. collapsed: global.collapsed,
  50. currentSite: global.currentSite,
  51. layout: setting.layout,
  52. menuData: menu.menuData,
  53. breadcrumbNameMap: menu.breadcrumbNameMap,
  54. ...setting,
  55. }))(LayoutWrapper);