Commit 26dc3af8 authored by 陈帅's avatar 陈帅

fix login status error

parent 825425c5
......@@ -11,10 +11,11 @@
"url": "https://github.com/umijs/umi-blocks/ant-design-pro/userlogin"
},
"dependencies": {
"@types/qs": "^6.5.3",
"antd": "^3.16.3",
"dva": "^2.4.0",
"moment": "^2.22.2",
"query-string": "^6.0.0",
"qs": "^6.7.0",
"react": "^16.6.3",
"umi-request": "^1.0.0"
},
......
import { routerRedux } from 'dva/router';
import { getPageQuery } from './utils/utils';
import { getPageQuery, setAuthority } from './utils/utils';
import { fakeAccountLogin, getFakeCaptcha } from './service';
import { stringify } from 'qs';
import { Reducer } from 'redux';
import { EffectsCommandMap } from 'dva';
import { AnyAction } from 'redux';
......@@ -23,6 +23,7 @@ export interface ModelType {
effects: {
login: Effect;
getCaptcha: Effect;
logout: Effect;
};
reducers: {
changeLoginStatus: Reducer<IStateType>;
......@@ -67,10 +68,33 @@ const Model: ModelType = {
*getCaptcha({ payload }, { call }) {
yield call(getFakeCaptcha, payload);
},
*logout(_, { put }) {
yield put({
type: 'changeLoginStatus',
payload: {
status: false,
currentAuthority: 'guest',
},
});
const { redirect } = getPageQuery();
// redirect
if (window.location.pathname !== '/user/login' && !redirect) {
yield put(
routerRedux.replace({
pathname: '/user/login',
search: stringify({
redirect: window.location.href,
}),
}),
);
}
},
},
reducers: {
changeLoginStatus(state, { payload }) {
setAuthority(payload.currentAuthority);
return {
...state,
status: payload.status,
......
......@@ -3,3 +3,8 @@ import { parse } from 'query-string';
export function getPageQuery() {
return parse(window.location.href.split('?')[1]);
}
export function setAuthority(authority: string | string[]) {
const proAuthority = typeof authority === 'string' ? [authority] : authority;
return localStorage.setItem('antd-pro-authority', JSON.stringify(proAuthority));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment