mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-30 13:20:24 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
7c75baa27e
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
LOGIN,
|
LOGIN,
|
||||||
|
LOGIN_OUT,
|
||||||
LOGIN_TYPE
|
LOGIN_TYPE
|
||||||
} from '../constants/action-types.js';
|
} from '../constants/action-types.js';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
@ -42,6 +43,21 @@ const regActions = (data) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const logoutActions = () => {
|
||||||
|
return(dispatch)=>{
|
||||||
|
axios.get('./user/logout').then((res) => {
|
||||||
|
console.log(res);
|
||||||
|
if(res.data.errcode === 0){
|
||||||
|
dispatch({
|
||||||
|
type: LOGIN_OUT
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const loginTypeAction = (index) => {
|
const loginTypeAction = (index) => {
|
||||||
return{
|
return{
|
||||||
type: LOGIN_TYPE,
|
type: LOGIN_TYPE,
|
||||||
@ -52,5 +68,6 @@ const loginTypeAction = (index) => {
|
|||||||
export default {
|
export default {
|
||||||
loginActions,
|
loginActions,
|
||||||
regActions,
|
regActions,
|
||||||
|
logoutActions,
|
||||||
loginTypeAction
|
loginTypeAction
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { Icon, Layout, Menu} from 'antd'
|
import { Icon, Layout, Menu} from 'antd'
|
||||||
import loginTypeAction from '../../actions/login';
|
import { logoutActions, loginTypeAction} from '../../actions/login'
|
||||||
|
|
||||||
const { Header } = Layout;
|
const { Header } = Layout;
|
||||||
const ToolUser = (props)=> (
|
const ToolUser = (props)=> (
|
||||||
@ -12,13 +12,14 @@ const ToolUser = (props)=> (
|
|||||||
<li><Icon type="question-circle-o" />帮助</li>
|
<li><Icon type="question-circle-o" />帮助</li>
|
||||||
<li><Link to="/user" onClick={props.relieveLink}><Icon type="user" />{ props.user }</Link></li>
|
<li><Link to="/user" onClick={props.relieveLink}><Icon type="user" />{ props.user }</Link></li>
|
||||||
<li><Link to="/News" onClick={props.relieveLink}><Icon type="mail" />{ props.msg }</Link></li>
|
<li><Link to="/News" onClick={props.relieveLink}><Icon type="mail" />{ props.msg }</Link></li>
|
||||||
<li>退出</li>
|
<li onClick={props.logout}>退出</li>
|
||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
ToolUser.propTypes={
|
ToolUser.propTypes={
|
||||||
user:PropTypes.string,
|
user:PropTypes.string,
|
||||||
msg:PropTypes.string,
|
msg:PropTypes.string,
|
||||||
relieveLink:PropTypes.func
|
relieveLink:PropTypes.func,
|
||||||
|
logout:PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
const ToolGuest = ()=> (
|
const ToolGuest = ()=> (
|
||||||
@ -38,16 +39,28 @@ class HeaderCom extends Component {
|
|||||||
current : window.location.hash.split("#")[1]
|
current : window.location.hash.split("#")[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static propTypes ={
|
||||||
|
user: PropTypes.string,
|
||||||
|
msg: PropTypes.string,
|
||||||
|
login:PropTypes.bool,
|
||||||
|
relieveLink:PropTypes.func,
|
||||||
|
logoutActions:PropTypes.func,
|
||||||
|
loginTypeAction:PropTypes.func
|
||||||
|
}
|
||||||
linkTo = (e) =>{
|
linkTo = (e) =>{
|
||||||
this.setState({
|
this.setState({
|
||||||
current : e.key
|
current : e.key
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
relieveLink = () =>{
|
relieveLink = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
current : ""
|
current : ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
logout = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
this.props.logoutActions();
|
||||||
|
}
|
||||||
handleLogin = (e) => {
|
handleLogin = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.props.loginTypeAction("1");
|
this.props.loginTypeAction("1");
|
||||||
@ -85,7 +98,7 @@ class HeaderCom extends Component {
|
|||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
</Menu>
|
</Menu>
|
||||||
<div className="user-toolbar">
|
<div className="user-toolbar">
|
||||||
{login?<ToolUser user={user} msg={msg} relieveLink={this.relieveLink}/>:<ToolGuest/>}
|
{login?<ToolUser user={user} msg={msg} relieveLink={this.relieveLink} logout={this.logout}/>:<ToolGuest/>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Header>
|
</Header>
|
||||||
@ -95,14 +108,6 @@ class HeaderCom extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HeaderCom.propTypes={
|
|
||||||
user: PropTypes.string,
|
|
||||||
msg: PropTypes.string,
|
|
||||||
login:PropTypes.bool,
|
|
||||||
relieveLink:PropTypes.func,
|
|
||||||
loginTypeAction:PropTypes.func
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
(state) => {
|
(state) => {
|
||||||
return{
|
return{
|
||||||
@ -111,6 +116,9 @@ export default connect(
|
|||||||
login:state.login.isLogin
|
login:state.login.isLogin
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{loginTypeAction}
|
{
|
||||||
|
loginTypeAction,
|
||||||
|
logoutActions
|
||||||
|
}
|
||||||
)(HeaderCom)
|
)(HeaderCom)
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ $color-black-light : #404040;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
i{
|
i{
|
||||||
margin-right: .09rem;
|
margin-right: .03rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ export const REGISTER = 'REGISTER';
|
|||||||
|
|
||||||
//header
|
//header
|
||||||
export const LOGIN_TYPE = 'LOGIN_TYPE';
|
export const LOGIN_TYPE = 'LOGIN_TYPE';
|
||||||
|
export const LOGIN_OUT = 'LOGIN_OUT';
|
||||||
|
|
||||||
// News
|
// News
|
||||||
export const FETCH_NEWS_DATA = 'FETCH_NEWS_DATA';
|
export const FETCH_NEWS_DATA = 'FETCH_NEWS_DATA';
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
LOGIN,
|
LOGIN,
|
||||||
|
LOGIN_OUT,
|
||||||
LOGIN_TYPE
|
LOGIN_TYPE
|
||||||
} from '../../constants/action-types';
|
} from '../../constants/action-types';
|
||||||
|
|
||||||
@ -20,6 +21,14 @@ export default (state = initialState, action) => {
|
|||||||
userName: action.payload.data.userName
|
userName: action.payload.data.userName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case LOGIN_OUT: {
|
||||||
|
return{
|
||||||
|
...state,
|
||||||
|
isLogin: false,
|
||||||
|
userName: null,
|
||||||
|
uid: null
|
||||||
|
}
|
||||||
|
}
|
||||||
case LOGIN_TYPE: {
|
case LOGIN_TYPE: {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
Loading…
Reference in New Issue
Block a user