LoadingPage.js 1.97 KB
Newer Older
jim's avatar
jim committed
1 2 3
import React, { PureComponent } from 'react';
import { Spin } from 'antd';
import { connect } from 'dva';
jim's avatar
jim committed
4 5
import { enquireScreen, unenquireScreen } from 'enquire-js';

jim's avatar
jim committed
6 7 8 9 10 11 12 13 14
import BasicLayout from './BasicLayout';
import { getMenuData } from '../common/menu';
/**
 * 根据菜单取得重定向地址.
 */

const MenuData = getMenuData();
const getRedirectData = () => {
  const redirectData = [];
jim's avatar
jim committed
15
  const getRedirect = item => {
jim's avatar
jim committed
16 17 18 19 20 21
    if (item && item.children) {
      if (item.children[0] && item.children[0].path) {
        redirectData.push({
          from: `${item.path}`,
          to: `${item.children[0].path}`,
        });
jim's avatar
jim committed
22
        item.children.forEach(children => {
jim's avatar
jim committed
23 24 25 26 27 28 29 30 31 32
          getRedirect(children);
        });
      }
    }
  };
  MenuData.forEach(getRedirect);
  return redirectData;
};
const redirectData = getRedirectData();

lijiehua's avatar
lijiehua committed
33
class LoadingPage extends PureComponent {
jim's avatar
jim committed
34 35 36 37
  state = {
    loading: true,
    isMobile: false,
  };
jim's avatar
jim committed
38

jim's avatar
jim committed
39
  componentDidMount() {
jim's avatar
jim committed
40
    this.enquireHandler = enquireScreen(mobile => {
jim's avatar
jim committed
41 42 43 44 45 46 47
      this.setState({
        isMobile: mobile,
      });
    });
    this.props.dispatch({
      type: 'user/fetchCurrent',
    });
jim's avatar
jim committed
48
    this.initSetting();
jim's avatar
jim committed
49 50
    this.hideLoading();
  }
jim's avatar
jim committed
51 52 53
  componentWillUnmount() {
    unenquireScreen(this.enquireHandler);
  }
jim's avatar
jim committed
54 55 56 57 58
  hideLoading() {
    this.setState({
      loading: false,
    });
  }
jim's avatar
jim committed
59 60 61
  /**
   * get setting from url params
   */
jim's avatar
jim committed
62 63
  initSetting() {
    this.props.dispatch({
jim's avatar
jim committed
64
      type: 'setting/getSetting',
jim's avatar
jim committed
65 66
    });
  }
jim's avatar
jim committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  render() {
    if (this.state.loading) {
      return (
        <div
          style={{
            width: '100%',
            height: '100%',
            margin: 'auto',
            paddingTop: 50,
            textAlign: 'center',
          }}
        >
          <Spin size="large" />
        </div>
      );
    }
    return (
      <BasicLayout
        isMobile={this.state.isMobile}
        menuData={MenuData}
        redirectData={redirectData}
        {...this.props}
      />
    );
  }
}

lijiehua's avatar
lijiehua committed
94
export default connect()(LoadingPage);