mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-06 12:45:22 +08:00
feat: 登录模块添加状态提示
This commit is contained in:
parent
ff1d162d0e
commit
a2358c7670
@ -2,7 +2,8 @@ import {
|
||||
LOGIN,
|
||||
LOGIN_OUT,
|
||||
LOGIN_TYPE,
|
||||
GET_LOGIN_STATE
|
||||
GET_LOGIN_STATE,
|
||||
REGISTER
|
||||
} from '../constants/action-types.js';
|
||||
import axios from 'axios';
|
||||
|
||||
@ -22,52 +23,29 @@ const checkLoginState = () => {
|
||||
}
|
||||
|
||||
const loginActions = (data) => {
|
||||
return (dispatch) => {
|
||||
axios.post('/user/login', data).then((res) => {
|
||||
if (res.data.errcode === 0) {
|
||||
dispatch({
|
||||
return {
|
||||
type: LOGIN,
|
||||
payload: {
|
||||
data: res
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('登录失败,errcode不为0');
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
payload: axios.post('/user/login', data)
|
||||
};
|
||||
};
|
||||
|
||||
const regActions = (data) => {
|
||||
console.log(data);
|
||||
const { email, password, userName } = data;
|
||||
const param = {
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
username: data.userName
|
||||
}
|
||||
return () => {
|
||||
axios.post('/user/login', param).then((res) => {
|
||||
console.log(res);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
email,
|
||||
password,
|
||||
username: userName
|
||||
};
|
||||
return {
|
||||
type: REGISTER,
|
||||
payload: axios.post('/user/reg', param)
|
||||
};
|
||||
};
|
||||
|
||||
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);
|
||||
})
|
||||
return {
|
||||
type: LOGIN_OUT,
|
||||
payload: axios.get('./user/logout')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ import React, { Component } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Icon, Layout, Menu, Dropdown } from 'antd'
|
||||
import { Icon, Layout, Menu, Dropdown, message } from 'antd'
|
||||
import { checkLoginState, logoutActions, loginTypeAction} from '../../actions/login'
|
||||
import { changeMenuItem } from '../../actions/menu'
|
||||
import { withRouter } from 'react-router';
|
||||
@ -98,12 +98,17 @@ class HeaderCom extends Component {
|
||||
}
|
||||
logout = (e) => {
|
||||
e.preventDefault();
|
||||
this.props.logoutActions();
|
||||
this.props.logoutActions().then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
this.props.history.push('/');
|
||||
this.props.changeMenuItem("/");
|
||||
// this.setState({
|
||||
// current : "/"
|
||||
// })
|
||||
message.success('退出成功! ');
|
||||
} else {
|
||||
message.error(res.payload.data.errmsg);
|
||||
}
|
||||
}).catch((err) => {
|
||||
message.error(err);
|
||||
});
|
||||
}
|
||||
handleLogin = (e) => {
|
||||
e.preventDefault();
|
||||
@ -114,7 +119,7 @@ class HeaderCom extends Component {
|
||||
this.props.loginTypeAction("2");
|
||||
}
|
||||
checkLoginState = () => {
|
||||
this.props.checkLoginState().then((res) => {
|
||||
this.props.checkLoginState.then((res) => {
|
||||
if (res.payload.data.errcode !== 0) {
|
||||
this.props.history.push('/');
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import { Form, Button, Input, Icon } from 'antd';
|
||||
import { Form, Button, Input, Icon, message } from 'antd';
|
||||
import { loginActions } from '../../actions/login';
|
||||
const FormItem = Form.Item;
|
||||
@connect(
|
||||
@ -30,7 +30,15 @@ class Login extends Component {
|
||||
const form = this.props.form;
|
||||
form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
this.props.loginActions(values);
|
||||
this.props.loginActions(values).then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
message.success('登录成功! ');
|
||||
} else {
|
||||
message.error(res.payload.data.errmsg);
|
||||
}
|
||||
}).catch((err) => {
|
||||
message.error(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import { Form, Button, Input, Icon } from 'antd';
|
||||
import { Form, Button, Input, Icon, message } from 'antd';
|
||||
import { regActions } from '../../actions/login';
|
||||
|
||||
const FormItem = Form.Item;
|
||||
@ -34,7 +34,15 @@ class Reg extends Component {
|
||||
const form = this.props.form;
|
||||
form.validateFieldsAndScroll((err, values) => {
|
||||
if (!err) {
|
||||
this.props.regActions(values);
|
||||
this.props.regActions(values).then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
message.success('注册成功! ');
|
||||
} else {
|
||||
message.error(res.payload.data.errmsg);
|
||||
}
|
||||
}).catch((err) => {
|
||||
message.error(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ export default (state = initialState, action) => {
|
||||
...state,
|
||||
isLogin: true,
|
||||
loginState: MEMBER_STATUS,
|
||||
uid: action.payload.data.uid,
|
||||
userName: action.payload.data.userName
|
||||
uid: action.payload.data.data.uid,
|
||||
userName: action.payload.data.data.username
|
||||
};
|
||||
}
|
||||
case LOGIN_OUT: {
|
||||
|
@ -32,8 +32,8 @@ export default (state = initialState, action) => {
|
||||
...state,
|
||||
isLogin: true,
|
||||
loginState: MEMBER_STATUS,
|
||||
uid: action.payload.data.uid,
|
||||
userName: action.payload.data.userName
|
||||
uid: action.payload.data.data.uid,
|
||||
userName: action.payload.data.data.username
|
||||
};
|
||||
}
|
||||
case LOGIN_OUT: {
|
||||
|
Loading…
Reference in New Issue
Block a user