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

张烨's avatar
张烨 committed
11 12 13 14 15 16 17
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
18
      if (r.hideMenu) return null;
张烨's avatar
张烨 committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
      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
34 35
const GlobalHeaderRight = props => {
  const { theme, layout } = props;
邓超's avatar
邓超 committed
36 37 38 39 40 41
  const [dosRouter, setDosRouter] = useState('');
  const { pathname } = useLocation();
  useEffect(() => {
    console.log(pathname, 'location');
    setDosRouter(pathname);
  }, [pathname]);
dengxiaofeng's avatar
dengxiaofeng committed
42
  let className = styles.right;
43
  const value = useContext(RouteContext);
张烨's avatar
张烨 committed
44

dengxiaofeng's avatar
dengxiaofeng committed
45
  if (theme === 'dark' && layout === 'top') {
dengxiaofeng's avatar
dengxiaofeng committed
46
    className = `${styles.right}  ${styles.dark}`;
dengxiaofeng's avatar
dengxiaofeng committed
47 48 49 50
  }

  return (
    <div className={className}>
51 52 53
      {/* <span className={styles.left}>{value.title}</span> */}
      <Breadcrumb {...value.breadcrumb} className={styles.lineHeight} />
      <div style={{ flex: 1 }} />
邓超's avatar
邓超 committed
54 55 56 57 58 59 60 61 62
      <div style={{ margin: '0 10px' }}>
        <a
          target="_blank"
          href={`${window.location.origin}/civmanage/site/content${dosRouter}`}
          rel="noopener noreferer"
        >
          文档说明
        </a>
      </div>
63
      {/* <Colophon /> */}
64 65 66 67 68 69 70 71 72 73
      <div style={{ margin: '0 10px' }}>
        <a
          target="_blank"
          href={`${window.location.origin}/cityoms3/4.0.html`}
          rel="noopener noreferer"
        >
          运维平台4.0
        </a>
      </div>
      {/* <HeaderSearch
74
        className={`${styles.action} ${styles.search} ${styles.toRight}`}
dengxiaofeng's avatar
dengxiaofeng committed
75
        placeholder="站内搜索"
dengxiaofeng's avatar
dengxiaofeng committed
76
        defaultValue=""
张烨's avatar
张烨 committed
77 78
        filterOption={(inputValue, option) =>
          option.value.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1
79
        }
张烨's avatar
张烨 committed
80
        options={[...routesOptions(value.route)]}
81
      /> */}
张烨's avatar
张烨 committed
82
      {/* <NoticeIcon className={`${styles.action} ${styles.toRight}`} /> */}
83
      <Avatar className={styles.toRight} />
dengxiaofeng's avatar
dengxiaofeng committed
84 85 86 87 88 89
      {/* <SelectLang className={styles.action} /> */}
    </div>
  );
};

export default GlobalHeaderRight;