|
|
@@ -22,28 +22,39 @@ const { Content } = Layout;
|
|
|
|
|
|
// 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;
|
|
|
- });
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ if (item.path) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ })
|
|
|
+ .filter(item => item);
|
|
|
}
|
|
|
|
|
|
const memoizeOneFormatter = memoizeOne(formatter, isEqual);
|
|
|
@@ -85,6 +96,7 @@ class BasicLayout extends React.PureComponent {
|
|
|
state = {
|
|
|
rendering: true,
|
|
|
isMobile: false,
|
|
|
+ menuData: this.getMenuData(),
|
|
|
};
|
|
|
|
|
|
componentDidMount() {
|
|
|
@@ -224,9 +236,8 @@ class BasicLayout extends React.PureComponent {
|
|
|
children,
|
|
|
location: { pathname },
|
|
|
} = this.props;
|
|
|
- const { isMobile } = this.state;
|
|
|
+ const { isMobile, menuData } = this.state;
|
|
|
const isTop = PropsLayout === 'topmenu';
|
|
|
- const menuData = this.getMenuData();
|
|
|
const routerConfig = this.matchParamsPath(pathname);
|
|
|
const layout = (
|
|
|
<Layout>
|