index.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* eslint no-undef: 0 */
  2. /* eslint arrow-parens: 0 */
  3. import React from 'react';
  4. import { enquireScreen } from 'enquire-js';
  5. import Nav0 from './Nav0';
  6. import Content13 from './Content13';
  7. import Footer0 from './Footer0';
  8. import {
  9. Nav00DataSource,
  10. Content130DataSource,
  11. Footer00DataSource,
  12. } from './data.source';
  13. import './less/antMotionStyle.less';
  14. import MyMap from '../../components/Map'
  15. let isMobile;
  16. enquireScreen((b) => {
  17. isMobile = b;
  18. });
  19. const { location = {} } = typeof window !== 'undefined' ? window : {};
  20. export default class Home extends React.Component {
  21. constructor(props) {
  22. super(props);
  23. this.state = {
  24. isMobile,
  25. show: !location.port, // 如果不是 dva 2.0 请删除
  26. };
  27. }
  28. componentDidMount() {
  29. // 适配手机屏幕;
  30. enquireScreen((b) => {
  31. this.setState({ isMobile: !!b });
  32. });
  33. // dva 2.0 样式在组件渲染之后动态加载,导致滚动组件不生效;线上不影响;
  34. /* 如果不是 dva 2.0 请删除 start */
  35. if (location.port) {
  36. // 样式 build 时间在 200-300ms 之间;
  37. setTimeout(() => {
  38. this.setState({
  39. show: true,
  40. });
  41. }, 500);
  42. }
  43. /* 如果不是 dva 2.0 请删除 end */
  44. }
  45. render() {
  46. const children = [
  47. <Nav0
  48. id="Nav0_0"
  49. key="Nav0_0"
  50. dataSource={Nav00DataSource}
  51. isMobile={this.state.isMobile}
  52. />,
  53. <Content13
  54. id="Content13_0"
  55. key="Content13_0"
  56. dataSource={Content130DataSource}
  57. isMobile={this.state.isMobile}
  58. />,
  59. <MyMap
  60. id="Content13_1"
  61. key="Content13_1"
  62. isMobile={this.state.isMobile}
  63. />,
  64. <Footer0
  65. id="Footer0_0"
  66. key="Footer0_0"
  67. dataSource={Footer00DataSource}
  68. isMobile={this.state.isMobile}
  69. />,
  70. ];
  71. return (
  72. <div
  73. className="templates-wrapper"
  74. ref={(d) => {
  75. this.dom = d;
  76. }}
  77. >
  78. {/* 如果不是 dva 2.0 替换成 {children} start */}
  79. {this.state.show && children}
  80. {/* 如果不是 dva 2.0 替换成 {children} end */}
  81. </div>
  82. );
  83. }
  84. }