index.js 1014 Bytes
Newer Older
1
import React from 'react';
陈帅's avatar
陈帅 committed
2
import { Drawer } from 'antd';
qixian.cs@outlook.com's avatar
qixian.cs@outlook.com committed
3
import SiderMenu from './SliderMenu';
偏右's avatar
偏右 committed
4

jim's avatar
jim committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**
 * Recursively flatten the data
 * [{path:string},{path:string}] => {path,path2}
 * @param  menus
 */
const getFlatMenuKeys = menuData => {
  let keys = [];
  menuData.forEach(item => {
    if (item.children) {
      keys = keys.concat(getFlatMenuKeys(item.children));
    }
    keys.push(item.path);
  });
  return keys;
};

陈帅's avatar
陈帅 committed
21 22 23
const SiderMenuWrapper = props => {
  const { isMobile, menuData, collapsed } = props;
  return isMobile ? (
陈帅's avatar
陈帅 committed
24 25 26 27
    <Drawer
      visible={!collapsed}
      placement="left"
      onClose={() => {
jim's avatar
jim committed
28 29
        props.onCollapse(true);
      }}
陈帅's avatar
陈帅 committed
30 31 32 33
      style={{
        padding: 0,
        height: '100vh',
      }}
34
    >
jim's avatar
jim committed
35 36
      <SiderMenu
        {...props}
陈帅's avatar
陈帅 committed
37 38
        flatMenuKeys={getFlatMenuKeys(menuData)}
        collapsed={isMobile ? false : collapsed}
jim's avatar
jim committed
39
      />
陈帅's avatar
陈帅 committed
40
    </Drawer>
jim's avatar
jim committed
41
  ) : (
陈帅's avatar
陈帅 committed
42
    <SiderMenu {...props} flatMenuKeys={getFlatMenuKeys(menuData)} />
jim's avatar
jim committed
43
  );
陈帅's avatar
陈帅 committed
44
};
ZHAO Jinxiang's avatar
ZHAO Jinxiang committed
45 46

export default SiderMenuWrapper;