|
@@ -1,7 +1,8 @@
|
|
|
import { apiLogout } from '@/components/Menu/api'
|
|
|
-import consts from '@/utils/consts'
|
|
|
-import history from '@/utils/history'
|
|
|
+import { Action } from 'redux'
|
|
|
+import { ThunkAction } from 'redux-thunk'
|
|
|
import { delUserInfo, getUserInfo, saveUserInfo } from './../../../utils/common/user'
|
|
|
+import { RootState } from './../../reducers'
|
|
|
import { CHECK_PERMISSION, DEL_USER_INFO, iUserInfo, iUserInfoState, SAVE_USER_INFO, UserInfoActionTypes } from './types'
|
|
|
export const initUserState: iUserInfoState = {
|
|
|
userInfo: {
|
|
@@ -42,16 +43,16 @@ export function updateUserInfo(userInfo: iUserInfo): UserInfoActionTypes{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export async function deleteUserInfo(): UserInfoActionTypes {
|
|
|
- const { code = -1 } = await apiLogout()
|
|
|
- if (code === consts.RET_CODE.SUCCESS) {
|
|
|
- history.push('/')
|
|
|
- delUserInfo()
|
|
|
- }
|
|
|
+export function deleteUserInfo(): UserInfoActionTypes {
|
|
|
+ delUserInfo()
|
|
|
return {
|
|
|
type: DEL_USER_INFO
|
|
|
}
|
|
|
}
|
|
|
+export const asyncLogout = ():ThunkAction<void, RootState, null, Action<string>> => async (dispatch) => {
|
|
|
+ await apiLogout()
|
|
|
+ dispatch(deleteUserInfo())
|
|
|
+}
|
|
|
|
|
|
export function checkPermission(): UserInfoActionTypes {
|
|
|
const userInfo: iUserInfo = getUserInfo()
|