Ver código fonte

Merge branch 'master' of http://192.168.1.41:3000/lanjianrong/management

caipin 4 anos atrás
pai
commit
f53a7d11e3

+ 0 - 1
package.json

@@ -148,7 +148,6 @@
     "prettier": "^2.1.2",
     "react-app-polyfill": "^1.0.6",
     "react-dev-utils": "^10.2.1",
-    "redux-saga": "^1.1.3",
     "resolve": "1.15.0",
     "resolve-url-loader": "3.1.1",
     "sass-loader": "8.0.2",

+ 9 - 6
src/components/Menu/index.tsx

@@ -1,4 +1,5 @@
 import logo from '@/assets/img/logo.png'
+import { deleteUserInfo } from '@/store/modules/user'
 import { RootState } from '@/store/reducers'
 import { iMenuItem } from '@/types/router'
 import { Button, Dropdown, Menu } from "antd"
@@ -43,11 +44,6 @@ const NavSider:React.FC<iMenuProps> = (props)=> {
     </div>
   )
 }
-const mapStateToProps = (state:RootState) => {
-  return {
-    username: state.user.userInfo.Name
-  }
-}
 
 const DropMenu = () => {
   return (
@@ -63,9 +59,16 @@ const DropMenu = () => {
         <Link to="/acount/safe">帮助中心</Link>
       </Menu.Item>
       <Menu.Item key="3">
-        <span onClick={store.dispatch()}>退出登录</span>
+        <span onClick={store.dispatch(deleteUserInfo())}>退出登录</span>
       </Menu.Item>
     </Menu>
   )
 }
+
+const mapStateToProps = (state:RootState) => {
+  return {
+    username: state.user.userInfo.Name
+  }
+}
+
 export default connect(mapStateToProps)(NavSider)

+ 1 - 3
src/store/index.ts

@@ -1,10 +1,8 @@
 import { applyMiddleware, compose, createStore } from 'redux'
-import createSagaMiddleware from "redux-saga"
 import thunk from 'redux-thunk'
 import rootReducer from './reducers'
 
 //添加中间件和调试工具
-const sagaMiddleware = createSagaMiddleware()
 const composeEnhancers =
     typeof window === 'object' &&
     (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
@@ -13,7 +11,7 @@ const composeEnhancers =
 
 const store = createStore(
   rootReducer,
-  composeEnhancers(applyMiddleware(thunk, sagaMiddleware))
+  composeEnhancers(applyMiddleware(thunk))
 )
 
 export default store

+ 9 - 8
src/store/modules/user/index.ts

@@ -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()

+ 5 - 1
src/store/modules/user/types.ts

@@ -1,3 +1,7 @@
+import { Action } from "redux"
+import { ThunkAction } from "redux-thunk"
+import { RootState } from './../../reducers'
+
 // state
 export interface iUserInfo {
   Id: string
@@ -34,4 +38,4 @@ interface CheckPermissionAction {
   payload: iUserInfoState
 }
 
-export type UserInfoActionTypes = SaveUserInfoAction | DelUserInfoAction | CheckPermissionAction
+export type UserInfoActionTypes = SaveUserInfoAction | DelUserInfoAction | CheckPermissionAction | ThunkAction<void, RootState, null, Action<string>>