RightContent.js 1.9 KB
Newer Older
张烨's avatar
张烨 committed
1
import React, { useContext, useState } from 'react';
2
import { RouteContext } from '@ant-design/pro-layout';
张烨's avatar
张烨 committed
3 4 5
import { Breadcrumb } from 'antd';
import check from '@/components/Authorized/CheckPermissions';
import { Link } from 'react-router-dom';
dengxiaofeng's avatar
dengxiaofeng committed
6 7
import HeaderSearch from '../HeaderSearch';
import Avatar from './AvatarDropdown';
dengxiaofeng's avatar
dengxiaofeng committed
8
import styles from './index.less';
dengxiaofeng's avatar
dengxiaofeng committed
9

张烨's avatar
张烨 committed
10 11 12 13 14 15 16
const routesOptions = route => {
  const buildOption = routeConfig => ({
    label: <Link to={routeConfig.path}>{routeConfig.name}</Link>,
    value: routeConfig.name,
  });
  return route.routes
    .map(r => {
张烨's avatar
张烨 committed
17
      if (r.hideMenu) return null;
张烨's avatar
张烨 committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
      if (r.authority) {
        if (r.routes) {
          return routesOptions(r);
        }
        return check(r.authority, buildOption(r), null);
      }
      if (r.routes) {
        return routesOptions(r);
      }
      return buildOption(r);
    })
    .flat()
    .filter(Boolean);
};

dengxiaofeng's avatar
dengxiaofeng committed
33 34
const GlobalHeaderRight = props => {
  const { theme, layout } = props;
dengxiaofeng's avatar
dengxiaofeng committed
35
  let className = styles.right;
36
  const value = useContext(RouteContext);
张烨's avatar
张烨 committed
37

dengxiaofeng's avatar
dengxiaofeng committed
38
  if (theme === 'dark' && layout === 'top') {
dengxiaofeng's avatar
dengxiaofeng committed
39
    className = `${styles.right}  ${styles.dark}`;
dengxiaofeng's avatar
dengxiaofeng committed
40 41 42 43
  }

  return (
    <div className={className}>
44 45 46
      {/* <span className={styles.left}>{value.title}</span> */}
      <Breadcrumb {...value.breadcrumb} className={styles.lineHeight} />
      <div style={{ flex: 1 }} />
dengxiaofeng's avatar
dengxiaofeng committed
47
      <HeaderSearch
48
        className={`${styles.action} ${styles.search} ${styles.toRight}`}
dengxiaofeng's avatar
dengxiaofeng committed
49
        placeholder="站内搜索"
dengxiaofeng's avatar
dengxiaofeng committed
50
        defaultValue=""
张烨's avatar
张烨 committed
51 52
        filterOption={(inputValue, option) =>
          option.value.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1
53
        }
张烨's avatar
张烨 committed
54
        options={[...routesOptions(value.route)]}
dengxiaofeng's avatar
dengxiaofeng committed
55
      />
张烨's avatar
张烨 committed
56
      {/* <NoticeIcon className={`${styles.action} ${styles.toRight}`} /> */}
57
      <Avatar className={styles.toRight} />
dengxiaofeng's avatar
dengxiaofeng committed
58 59 60 61 62 63
      {/* <SelectLang className={styles.action} /> */}
    </div>
  );
};

export default GlobalHeaderRight;