diff --git a/client/actions/login.js b/client/actions/login.js index bd8e3daf..f1d9f6eb 100644 --- a/client/actions/login.js +++ b/client/actions/login.js @@ -1,7 +1,8 @@ import { LOGIN, - REGISTER -} from '../actionTypes.js'; + REGISTER, + LOGIN_TYPE +} from '../constants/action-types.js'; // import Server from '../server/listRequest'; const loginActions = (data) => { @@ -20,7 +21,15 @@ const regActions = (data) => { } } +const loginTypeAction = (index) => { + return{ + type: LOGIN_TYPE, + index + } +} + export default { loginActions, - regActions + regActions, + loginTypeAction } diff --git a/client/components/Header/Header.js b/client/components/Header/Header.js index 9f4eddcb..ff5cc082 100644 --- a/client/components/Header/Header.js +++ b/client/components/Header/Header.js @@ -4,6 +4,7 @@ import PropTypes from 'prop-types' import { connect } from 'react-redux' import { Link } from 'react-router-dom' import { Icon } from 'antd' +import { loginTypeAction } from '../../actions/login'; const ToolUser = (props)=> ( ); ToolUser.propTypes={ - user:PropTypes.string.isRequired, - msg:PropTypes.string.isRequired + user:PropTypes.string, + msg:PropTypes.string }; -const ToolGuest = ()=> - ( - - ); +const ToolGuest = (props)=> ( + +); +ToolGuest.propTypes={ + onLogin:PropTypes.func, + onReg:PropTypes.func +} class Header extends Component { constructor(props) { 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 + }) } render () { const { login, user, msg } = this.props; + console.log(this.state.guestToolShow); return (

YAPI

-
) @@ -57,16 +84,20 @@ class Header extends Component { } Header.propTypes={ - user: PropTypes.string.isRequired, - msg: PropTypes.string.isRequired, - login:PropTypes.bool.isRequired + user: PropTypes.string, + msg: PropTypes.string, + login:PropTypes.bool, + loginTypeAction:PropTypes.func }; export default connect( - () => ({ - user: "王亮", - msg: "暂无消息", - login:false - }) + (state) => { + return{ + user: state.login.userName, + msg: "暂无消息", + login:state.login.isLogin + } + }, + {loginTypeAction} )(Header) diff --git a/client/constants/action-types.js b/client/constants/action-types.js index 01d95a12..86506622 100644 --- a/client/constants/action-types.js +++ b/client/constants/action-types.js @@ -7,3 +7,7 @@ export const FETCH_CURR_GROUP = 'FETCH_CURR_GROUP' // login export const LOGIN = 'LOGIN'; +export const REGISTER = 'REGISTER'; + +//header +export const LOGIN_TYPE = 'LOGIN_TYPE'; \ No newline at end of file diff --git a/client/containers/Login/loginWrap.js b/client/containers/Login/loginWrap.js index 1b985011..0e616cf8 100644 --- a/client/containers/Login/loginWrap.js +++ b/client/containers/Login/loginWrap.js @@ -1,19 +1,27 @@ import './Login.scss' import React, { Component } from 'react' +import { connect } from 'react-redux' import PropTypes from 'prop-types' import { Tabs } from 'antd'; import LoginForm from './login'; import RegForm from './reg'; const TabPane = Tabs.TabPane; + class LoginWrap extends Component { + constructor(props){ + super(props); + } + static propTypes = { - form: PropTypes.object + form: PropTypes.object, + loginWrapActiveKey:PropTypes.string } render() { + const { loginWrapActiveKey } = this.props; return ( - + @@ -25,4 +33,8 @@ class LoginWrap extends Component { } } -export default LoginWrap; +export default connect( + state =>({ + loginWrapActiveKey: state.login.loginWrapActiveKey + }) +)(LoginWrap) diff --git a/client/reducer/Login/login.js b/client/reducer/Login/login.js index 09160325..61e4f764 100644 --- a/client/reducer/Login/login.js +++ b/client/reducer/Login/login.js @@ -1,11 +1,13 @@ import { - LOGIN + LOGIN, + LOGIN_TYPE } from '../../constants/action-types'; const initialState = { isLogin: false, userName: null, - uid: null + uid: null, + loginWrapActiveKey:"1" }; export default (state = initialState, action) => { @@ -17,6 +19,12 @@ export default (state = initialState, action) => { userName: action.userName }; } + case LOGIN_TYPE: { + return { + ...state, + loginWrapActiveKey: action.index + }; + } default: return state; }