mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
fix: 修改action,去掉登录退出的强制刷新
This commit is contained in:
parent
63f18dad65
commit
ab732c5cf6
@ -9,7 +9,7 @@ import { checkLoginState } from './actions/login'
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
const MEMBER_STATUS = 2;
|
||||
// const MEMBER_STATUS = 2;
|
||||
|
||||
|
||||
class App extends Component {
|
||||
@ -21,7 +21,8 @@ class App extends Component {
|
||||
}
|
||||
}
|
||||
static propTypes = {
|
||||
checkLoginState:PropTypes.func
|
||||
checkLoginState:PropTypes.func,
|
||||
loginState:PropTypes.number
|
||||
}
|
||||
route = (status) => {
|
||||
let r;
|
||||
@ -61,34 +62,18 @@ class App extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.checkLoginState().then((res) => {
|
||||
console.log(res);
|
||||
if (res.payload.data.errcode === 0 && res.payload.data.data._id > 0) {
|
||||
this.setState({
|
||||
login: MEMBER_STATUS
|
||||
})
|
||||
} else {
|
||||
this.setState({
|
||||
login: GUEST_STATUS
|
||||
})
|
||||
}
|
||||
}).catch((err) => {
|
||||
this.setState({
|
||||
login: GUEST_STATUS
|
||||
});
|
||||
console.log(err)
|
||||
});
|
||||
this.props.checkLoginState();
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.route(this.state.login)
|
||||
return this.route(this.props.loginState)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
state => {
|
||||
return{
|
||||
login:state.login.isLogin
|
||||
loginState:state.login.loginState
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -6,12 +6,19 @@ import {
|
||||
} from '../constants/action-types.js';
|
||||
import axios from 'axios';
|
||||
|
||||
|
||||
const checkLoginState = () => {
|
||||
return {
|
||||
return(dispatch)=> {
|
||||
axios.get('/user/status').then((res) => {
|
||||
console.log(res);
|
||||
dispatch({
|
||||
type: GET_LOGIN_STATE,
|
||||
// payload 可以返回 Promise,异步请求使用 axios 即可
|
||||
payload: axios.get('/user/status')
|
||||
};
|
||||
payload: res
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const loginActions = (data) => {
|
||||
@ -24,7 +31,6 @@ const loginActions = (data) => {
|
||||
data: res
|
||||
}
|
||||
});
|
||||
location.reload();
|
||||
} else {
|
||||
console.log('登录失败,errcode不为0');
|
||||
}
|
||||
@ -58,7 +64,6 @@ const logoutActions = () => {
|
||||
dispatch({
|
||||
type: LOGIN_OUT
|
||||
})
|
||||
location.reload();
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
|
@ -9,7 +9,7 @@ import { checkLoginState } from './actions/login'
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
const MEMBER_STATUS = 2;
|
||||
// const MEMBER_STATUS = 2;
|
||||
|
||||
|
||||
class App extends Component {
|
||||
@ -21,7 +21,8 @@ class App extends Component {
|
||||
}
|
||||
}
|
||||
static propTypes = {
|
||||
checkLoginState:PropTypes.func
|
||||
checkLoginState:PropTypes.func,
|
||||
loginState:PropTypes.number
|
||||
}
|
||||
route = (status) => {
|
||||
let r;
|
||||
@ -61,34 +62,18 @@ class App extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.checkLoginState().then((res) => {
|
||||
console.log(res);
|
||||
if (res.payload.data.errcode === 0 && res.payload.data.data._id > 0) {
|
||||
this.setState({
|
||||
login: MEMBER_STATUS
|
||||
})
|
||||
} else {
|
||||
this.setState({
|
||||
login: GUEST_STATUS
|
||||
})
|
||||
}
|
||||
}).catch((err) => {
|
||||
this.setState({
|
||||
login: GUEST_STATUS
|
||||
});
|
||||
console.log(err)
|
||||
});
|
||||
this.props.checkLoginState();
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.route(this.state.login)
|
||||
return this.route(this.props.loginState)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
state => {
|
||||
return{
|
||||
login:state.login.isLogin
|
||||
loginState:state.login.loginState
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -124,7 +124,6 @@ class HeaderCom extends Component {
|
||||
}
|
||||
render () {
|
||||
const { login, user, msg, uid, curKey } = this.props;
|
||||
console.log(curKey);
|
||||
return (
|
||||
<acticle className="header-box">
|
||||
<Layout className="'layout">
|
||||
|
@ -5,10 +5,15 @@ import {
|
||||
GET_LOGIN_STATE
|
||||
} from '../../constants/action-types';
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
const MEMBER_STATUS = 2;
|
||||
|
||||
const initialState = {
|
||||
isLogin: false,
|
||||
userName: null,
|
||||
uid: null,
|
||||
loginState:LOADING_STATUS,
|
||||
loginWrapActiveKey:"1"
|
||||
};
|
||||
|
||||
@ -18,6 +23,7 @@ export default (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
isLogin: (action.payload.data.errcode == 0),
|
||||
loginState: (action.payload.data.errcode == 0)?MEMBER_STATUS:GUEST_STATUS,
|
||||
userName: action.payload.data.data ? action.payload.data.data.username : null
|
||||
};
|
||||
}
|
||||
@ -25,6 +31,7 @@ export default (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
isLogin: true,
|
||||
loginState: MEMBER_STATUS,
|
||||
uid: action.payload.data.uid,
|
||||
userName: action.payload.data.userName
|
||||
};
|
||||
@ -33,6 +40,7 @@ export default (state = initialState, action) => {
|
||||
return{
|
||||
...state,
|
||||
isLogin: false,
|
||||
loginState: GUEST_STATUS,
|
||||
userName: null,
|
||||
uid: null
|
||||
}
|
||||
|
@ -5,10 +5,15 @@ import {
|
||||
GET_LOGIN_STATE
|
||||
} from '../../constants/action-types';
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
const MEMBER_STATUS = 2;
|
||||
|
||||
const initialState = {
|
||||
isLogin: false,
|
||||
userName: null,
|
||||
uid: null,
|
||||
loginState:LOADING_STATUS,
|
||||
loginWrapActiveKey:"1"
|
||||
};
|
||||
|
||||
@ -18,6 +23,7 @@ export default (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
isLogin: (action.payload.data.errcode == 0),
|
||||
loginState: (action.payload.data.errcode == 0)?MEMBER_STATUS:GUEST_STATUS,
|
||||
userName: action.payload.data.data ? action.payload.data.data.username : null
|
||||
};
|
||||
}
|
||||
@ -25,6 +31,7 @@ export default (state = initialState, action) => {
|
||||
return {
|
||||
...state,
|
||||
isLogin: true,
|
||||
loginState: MEMBER_STATUS,
|
||||
uid: action.payload.data.uid,
|
||||
userName: action.payload.data.userName
|
||||
};
|
||||
@ -33,6 +40,7 @@ export default (state = initialState, action) => {
|
||||
return{
|
||||
...state,
|
||||
isLogin: false,
|
||||
loginState: GUEST_STATUS,
|
||||
userName: null,
|
||||
uid: null
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user