yapi/client/components/Header/Header.js

104 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-07-10 11:50:56 +08:00
import './Header.scss'
2017-07-07 17:26:31 +08:00
import React, { Component } from 'react'
2017-07-12 16:27:06 +08:00
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
2017-07-10 21:29:03 +08:00
import { Link } from 'react-router-dom'
2017-07-12 16:27:06 +08:00
import { Icon } from 'antd'
import { loginTypeAction } from '../../actions/login';
2017-07-12 16:27:06 +08:00
const ToolUser = (props)=> (
<ul>
<li><Icon type="user" />{ props.user }</li>
<li>消息{ props.msg.length }</li>
<li>退出</li>
</ul>
);
ToolUser.propTypes={
user:PropTypes.string,
msg:PropTypes.string
2017-07-12 16:27:06 +08:00
};
const ToolGuest = (props)=> (
<ul>
<li onClick={e => props.onLogin(e)}><Link to={`/Login`}>登录</Link></li>
<li onClick={e => props.onReg(e)}><Link to={`/Login`}>注册</Link></li>
</ul>
);
ToolGuest.propTypes={
onLogin:PropTypes.func,
onReg:PropTypes.func
}
2017-07-07 17:26:31 +08:00
class Header extends Component {
constructor(props) {
2017-07-12 16:27:06 +08:00
super(props);
this.state={
guestToolShow:true
}
}
handleLogin = (e) => {
e.preventDefault();
this.props.loginTypeAction("1");
this.setState({
guestToolShow:false
})
}
handleReg = (e)=>{
e.preventDefault();
this.props.loginTypeAction("2");
this.setState({
guestToolShow:false
})
}
hideGuestTool = (e)=>{
e.preventDefault();
this.setState({
guestToolShow:true
})
2017-07-07 17:26:31 +08:00
}
render () {
2017-07-12 16:27:06 +08:00
const { login, user, msg } = this.props;
console.log(this.state.guestToolShow);
2017-07-07 17:26:31 +08:00
return (
<acticle className="header-box">
<div className="content">
<h1>YAPI</h1>
2017-07-12 16:27:06 +08:00
<ul className="nav-toolbar">
<li onClick={this.hideGuestTool}>
2017-07-12 16:27:06 +08:00
<Link to={`/ProjectGroups`}>分组</Link>
2017-07-07 17:26:31 +08:00
</li>
<li onClick={this.hideGuestTool}>
2017-07-12 16:27:06 +08:00
<a>我的项目</a>
2017-07-07 17:26:31 +08:00
</li>
<li onClick={this.hideGuestTool}>
2017-07-12 16:27:06 +08:00
<a>文档</a>
</li>
</ul>
<ul className="user-toolbar">
{login?<ToolUser user={user} msg={msg}/>:(this.state.guestToolShow?<ToolGuest onLogin={this.handleLogin} onReg={this.handleReg}/>:'')}
2017-07-07 17:26:31 +08:00
</ul>
</div>
</acticle>
)
}
2017-07-06 01:09:33 +08:00
}
2017-07-07 17:26:31 +08:00
2017-07-12 16:27:06 +08:00
Header.propTypes={
user: PropTypes.string,
msg: PropTypes.string,
login:PropTypes.bool,
loginTypeAction:PropTypes.func
2017-07-12 16:27:06 +08:00
};
export default connect(
(state) => {
return{
user: state.login.userName,
msg: "暂无消息",
login:state.login.isLogin
}
},
{loginTypeAction}
2017-07-12 16:27:06 +08:00
)(Header)