Menu.js 2.03 KB
Newer Older
dengxiaofeng's avatar
dengxiaofeng committed
1 2 3 4
import React from 'react';

import styles from './index.less';

邓晓峰's avatar
邓晓峰 committed
5
const Menu = props => {
邓晓峰's avatar
邓晓峰 committed
6
  const renderTitle = title => <h4 className={styles.title}>{title}</h4>;
邓晓峰's avatar
邓晓峰 committed
7 8 9 10
  const renderMenuItem = data => {
    let menuItem = [];
    if (!data) {
      return;
dengxiaofeng's avatar
dengxiaofeng committed
11
    }
邓晓峰's avatar
邓晓峰 committed
12
    // eslint-disable-next-line no-prototype-builtins
邓晓峰's avatar
邓晓峰 committed
13 14 15 16 17 18
    if (!data.hasOwnProperty('routes')) {
      menuItem = (
        <div
          className={styles['main-menus-recentAll-menu-group-items-menu-item']}
          onClick={event => props.handleClick(event, data)}
        >
19
          <img src={data.extData.icon} alt="" />
邓晓峰's avatar
邓晓峰 committed
20 21 22 23 24 25 26 27 28 29 30
          <a
            className={`${
              styles['main-menus-recentAll-menu-group-items-menu-item-name']
            } ${styles.pad}`}
          >
            {data.name}
          </a>
        </div>
      );
    } else {
      data.routes.forEach((item, index) => {
邓晓峰's avatar
邓晓峰 committed
31
        const render = (
邓晓峰's avatar
邓晓峰 committed
32 33 34 35 36 37 38
          <div
            className={
              styles['main-menus-recentAll-menu-group-items-menu-item']
            }
            key={item.name}
            onClick={event => props.handleClick(event, item)}
          >
39
            <img src={item.extData.icon} alt="" />
邓晓峰's avatar
邓晓峰 committed
40 41 42 43 44 45 46 47 48 49 50
            <a
              className={`${
                styles['main-menus-recentAll-menu-group-items-menu-item-name']
              } ${styles.pad}`}
            >
              {item.name}
            </a>
          </div>
        );
        menuItem.push(render);
      });
dengxiaofeng's avatar
dengxiaofeng committed
51
    }
邓晓峰's avatar
邓晓峰 committed
52

邓晓峰's avatar
邓晓峰 committed
53
    // eslint-disable-next-line consistent-return
邓晓峰's avatar
邓晓峰 committed
54 55 56 57 58 59
    return menuItem;
  };
  return (
    <div className={styles['main-menus']}>
      <div className={styles['main-menus-recentAll']}>
        <div className={styles['main-menus-recentAll-menu-group']}>
邓晓峰's avatar
邓晓峰 committed
60 61 62 63 64 65 66 67 68
          {(props.data.routes || []).map((item, index) => (
            <div
              className={styles['main-menus-recentAll-menu-group-items']}
              key={item.name}
            >
              {renderTitle(item.name)}
              {renderMenuItem(item)}
            </div>
          ))}
dengxiaofeng's avatar
dengxiaofeng committed
69
        </div>
邓晓峰's avatar
邓晓峰 committed
70 71 72 73
      </div>
    </div>
  );
};
dengxiaofeng's avatar
dengxiaofeng committed
74 75

export default Menu;