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 => (
);
const tipFollow = (
);
const tipAdd = (
);
const tipDoc = (
使用文档 推荐!
初次使用 YApi,强烈建议你阅读{' '}
使用文档
,我们为你提供了通俗易懂的快速入门教程,更有详细的使用说明,欢迎阅读!{' '}
);
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 (
-
}
title={tipFollow}
placement="bottomRight"
arrowPointAtCenter
visible={props.studyTip === 1 && !props.study}
>
-
}
title={tipAdd}
placement="bottomRight"
arrowPointAtCenter
visible={props.studyTip === 2 && !props.study}
>
-
}
title={tipDoc}
placement="bottomRight"
arrowPointAtCenter
visible={props.studyTip === 3 && !props.study}
>
-
-
}
>
{/*props.imageUrl? : */}
);
};
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 (
);
}
}