import './Header.scss'; import React, { PureComponent as Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { Link } from 'react-router-dom'; import { Icon, Layout, Menu, Dropdown, message, Tooltip, Popover, Tag } from 'antd'; import { checkLoginState, logoutActions, loginTypeAction } from '../../reducer/modules/user'; import { changeMenuItem } from '../../reducer/modules/menu'; import { withRouter } from 'react-router'; import Srch from './Search/Search'; const { Header } = Layout; import LogoSVG from '../LogoSVG/index.js'; import Breadcrumb from '../Breadcrumb/Breadcrumb.js'; import GuideBtns from '../GuideBtns/GuideBtns.js'; const plugin = require('client/plugin.js'); let HeaderMenu = { user: { path: '/user/profile', name: '个人中心', icon: 'user', adminFlag: false }, solution: { path: '/user/list', name: '用户管理', icon: 'solution', adminFlag: true } }; plugin.emitHook('header_menu', HeaderMenu); const MenuUser = props => ( {Object.keys(HeaderMenu).map(key => { let item = HeaderMenu[key]; const isAdmin = props.role === 'admin'; if (item.adminFlag && !isAdmin) { return null; } return ( {item.name === '个人中心' ? ( {item.name} ) : ( {item.name} )} ); })} 退出 ); const tipFollow = (

关注

这里是你的专属收藏夹,便于你找到自己的项目

); const tipAdd = (

新建项目

在任何页面都可以快速新建项目

); const tipDoc = (

使用文档 推荐!

初次使用 mofish,强烈建议你阅读{' '} 使用文档 ,我们为你提供了通俗易懂的快速入门教程,更有详细的使用说明,欢迎阅读!{' '}

); MenuUser.propTypes = { user: PropTypes.string, msg: PropTypes.string, role: PropTypes.string, uid: PropTypes.number, relieveLink: PropTypes.func, logout: PropTypes.func }; const ToolUser = props => { let imageUrl = props.imageUrl ? props.imageUrl : `/api/user/avatar?uid=${props.uid}`; return ( ); }; ToolUser.propTypes = { user: PropTypes.string, msg: PropTypes.string, role: PropTypes.string, uid: PropTypes.number, relieveLink: PropTypes.func, logout: PropTypes.func, groupList: PropTypes.array, studyTip: PropTypes.number, study: PropTypes.bool, imageUrl: PropTypes.any }; @connect( state => { return { user: state.user.userName, uid: state.user.uid, msg: null, role: state.user.role, login: state.user.isLogin, studyTip: state.user.studyTip, study: state.user.study, imageUrl: state.user.imageUrl }; }, { loginTypeAction, logoutActions, checkLoginState, changeMenuItem } ) @withRouter export default class HeaderCom extends Component { constructor(props) { super(props); } static propTypes = { router: PropTypes.object, user: PropTypes.string, msg: PropTypes.string, uid: PropTypes.number, role: PropTypes.string, login: PropTypes.bool, relieveLink: PropTypes.func, logoutActions: PropTypes.func, checkLoginState: PropTypes.func, loginTypeAction: PropTypes.func, changeMenuItem: PropTypes.func, history: PropTypes.object, location: PropTypes.object, study: PropTypes.bool, studyTip: PropTypes.number, imageUrl: PropTypes.any }; linkTo = e => { if (e.key != '/doc') { this.props.changeMenuItem(e.key); if (!this.props.login) { message.info('请先登录', 1); } } }; relieveLink = () => { this.props.changeMenuItem(''); }; logout = e => { e.preventDefault(); this.props .logoutActions() .then(res => { if (res.payload.data.errcode == 0) { this.props.history.push('/'); this.props.changeMenuItem('/'); message.success('退出成功! '); } else { message.error(res.payload.data.errmsg); } }) .catch(err => { message.error(err); }); }; handleLogin = e => { e.preventDefault(); this.props.loginTypeAction('1'); }; handleReg = e => { e.preventDefault(); this.props.loginTypeAction('2'); }; checkLoginState = () => { this.props.checkLoginState .then(res => { if (res.payload.data.errcode !== 0) { this.props.history.push('/'); } }) .catch(err => { console.log(err); }); }; render() { const { login, user, msg, uid, role, studyTip, study, imageUrl } = this.props; return (
0 ? 3 : 1 }} > {login ? ( ) : ( '' )}
); } }