Commit c2fe4009 authored by afc163's avatar afc163 Committed by 偏右

remove LoadingPage

parent c93b0169
...@@ -13,7 +13,7 @@ module.exports = [ ...@@ -13,7 +13,7 @@ module.exports = [
// app // app
{ {
path: '/', path: '/',
component: '../layouts/LoadingPage', component: '../layouts/BasicLayout',
routes: [ routes: [
// dashboard // dashboard
{ path: '/', redirect: '/dashboard/analysis' }, { path: '/', redirect: '/dashboard/analysis' },
......
import React from 'react'; import React from 'react';
import { Layout } from 'antd'; import { Layout } from 'antd';
import DocumentTitle from 'react-document-title'; import DocumentTitle from 'react-document-title';
import deepEqual from 'lodash/isEqual'; import isEqual from 'lodash/isEqual';
import memoizeOne from 'memoize-one'; import memoizeOne from 'memoize-one';
import { connect } from 'dva'; import { connect } from 'dva';
import { ContainerQuery } from 'react-container-query'; import { ContainerQuery } from 'react-container-query';
import classNames from 'classnames'; import classNames from 'classnames';
import pathToRegexp from 'path-to-regexp'; import pathToRegexp from 'path-to-regexp';
import { enquireScreen, unenquireScreen } from 'enquire-js';
import { formatMessage } from 'umi/locale'; import { formatMessage } from 'umi/locale';
import SiderMenu from '@/components/SiderMenu'; import SiderMenu from '@/components/SiderMenu';
import Authorized from '@/utils/Authorized'; import Authorized from '@/utils/Authorized';
...@@ -15,28 +16,59 @@ import logo from '../assets/logo.svg'; ...@@ -15,28 +16,59 @@ import logo from '../assets/logo.svg';
import Footer from './Footer'; import Footer from './Footer';
import Header from './Header'; import Header from './Header';
import Context from './MenuContext'; import Context from './MenuContext';
// TODO: should use this.props.routes
import routerConfig from '../../config/router.config';
const { Content } = Layout; const { Content } = Layout;
const { check } = Authorized; const { check } = Authorized;
// Conversion router to menu.
function formatter(data, parentPath = '', parentAuthority, parentName) {
return data.map(item => {
let locale = 'menu';
if (parentName && item.name) {
locale = `${parentName}.${item.name}`;
} else if (item.name) {
locale = `menu.${item.name}`;
} else if (parentName) {
locale = parentName;
}
const result = {
...item,
locale,
authority: item.authority || parentAuthority,
};
if (item.routes) {
const children = formatter(item.routes, `${parentPath}${item.path}/`, item.authority, locale);
// Reduce memory usage
result.children = children;
}
delete result.routes;
return result;
});
}
// get menu map data
const menuData = formatter(routerConfig[1].routes);
/** /**
* 获取面包屑映射 * 获取面包屑映射
* @param {Object} menuData 菜单配置 * @param {Object} menuData 菜单配置
*/ */
const getBreadcrumbNameMap = memoizeOne(meun => { const getBreadcrumbNameMap = memoizeOne(menu => {
const routerMap = {}; const routerMap = {};
const mergeMeunAndRouter = meunData => { const mergeMenuAndRouter = () => {
meunData.forEach(meunItem => { menuData.forEach(menuItem => {
if (meunItem.children) { if (menuItem.children) {
mergeMeunAndRouter(meunItem.children); mergeMenuAndRouter(menuItem.children);
} }
// Reduce memory usage // Reduce memory usage
routerMap[meunItem.path] = meunItem; routerMap[menuItem.path] = menuItem;
}); });
}; };
mergeMeunAndRouter(meun); mergeMenuAndRouter(menu);
return routerMap; return routerMap;
}, deepEqual); }, isEqual);
const query = { const query = {
'screen-xs': { 'screen-xs': {
...@@ -66,31 +98,47 @@ const query = { ...@@ -66,31 +98,47 @@ const query = {
class BasicLayout extends React.PureComponent { class BasicLayout extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
const { menuData } = this.props;
this.getPageTitle = memoizeOne(this.getPageTitle); this.getPageTitle = memoizeOne(this.getPageTitle);
// Because there are many places to be. So put it here // Because there are many places to be. So put it here
this.breadcrumbNameMap = getBreadcrumbNameMap(menuData); this.breadcrumbNameMap = getBreadcrumbNameMap();
console.log(this.breadcrumbNameMap);
} }
state = { state = {
rendering: true, rendering: true,
isMobile: false,
}; };
componentDidMount() { componentDidMount() {
const { dispatch } = this.props;
dispatch({
type: 'user/fetchCurrent',
});
dispatch({
type: 'setting/getSetting',
});
this.renderRef = requestAnimationFrame(() => { this.renderRef = requestAnimationFrame(() => {
this.setState({ this.setState({
rendering: false, rendering: false,
}); });
}); });
this.enquireHandler = enquireScreen(mobile => {
const { isMobile } = this.state;
if (isMobile !== mobile) {
this.setState({
isMobile: mobile,
});
}
});
} }
componentDidUpdate() { componentDidUpdate() {
const { menuData } = this.props; this.breadcrumbNameMap = getBreadcrumbNameMap();
this.breadcrumbNameMap = getBreadcrumbNameMap(menuData);
} }
componentWillUnmount() { componentWillUnmount() {
cancelAnimationFrame(this.renderRef); cancelAnimationFrame(this.renderRef);
unenquireScreen(this.enquireHandler);
} }
getContext() { getContext() {
...@@ -168,13 +216,12 @@ class BasicLayout extends React.PureComponent { ...@@ -168,13 +216,12 @@ class BasicLayout extends React.PureComponent {
render() { render() {
const { const {
isMobile,
silderTheme, silderTheme,
layout: PropsLayout, layout: PropsLayout,
children, children,
location: { pathname }, location: { pathname },
} = this.props; } = this.props;
const { rendering } = this.state; const { rendering, isMobile } = this.state;
const isTop = PropsLayout === 'topmenu'; const isTop = PropsLayout === 'topmenu';
const layout = ( const layout = (
<Layout> <Layout>
......
import React, { PureComponent } from 'react';
import { Spin } from 'antd';
import { connect } from 'dva';
import { enquireScreen, unenquireScreen } from 'enquire-js';
import BasicLayout from './BasicLayout';
// TODO: should use this.props.routes
import routerConfig from '../../config/router.config';
// Conversion router to menu.
function formatter(data, parentPath = '', parentAuthority, parentName) {
return data.map(item => {
let locale = 'menu';
if (parentName && item.name) {
locale = `${parentName}.${item.name}`;
} else if (item.name) {
locale = `menu.${item.name}`;
} else if (parentName) {
locale = parentName;
}
const result = {
...item,
locale,
authority: item.authority || parentAuthority,
};
if (item.routes) {
const children = formatter(item.routes, `${parentPath}${item.path}/`, item.authority, locale);
// Reduce memory usage
result.children = children;
}
delete result.routes;
return result;
});
}
// get meun map data
const MenuData = formatter(routerConfig[1].routes);
class LoadingPage extends PureComponent {
state = {
loading: true,
isMobile: false,
};
componentDidMount() {
const { dispatch } = this.props;
this.enquireHandler = enquireScreen(mobile => {
const { isMobile } = this.state;
if (isMobile !== mobile) {
this.setState({
isMobile: mobile,
});
}
});
dispatch({
type: 'user/fetchCurrent',
});
this.hideLoading();
this.initSetting();
}
componentWillUnmount() {
unenquireScreen(this.enquireHandler);
}
hideLoading() {
this.setState({
loading: false,
});
}
/**
* get setting from url params
*/
initSetting() {
const { dispatch } = this.props;
dispatch({
type: 'setting/getSetting',
});
}
render() {
const { loading, isMobile } = this.state;
if (loading) {
return (
<div
style={{
width: '100%',
height: '100%',
margin: 'auto',
paddingTop: 50,
textAlign: 'center',
}}
>
<Spin size="large" />
</div>
);
}
return (
<BasicLayout
isMobile={isMobile}
menuData={MenuData}
routerData={routerConfig}
redirectData={[]}
{...this.props}
/>
);
}
}
export default connect()(LoadingPage);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment