|
@@ -1,10 +1,11 @@
|
|
|
import logo from '@/assets/img/logo.png'
|
|
|
-import store from '@/store'
|
|
|
-import { deleteUserInfo } from '@/store/modules/user'
|
|
|
+import { DEL_USER_INFO } from '@/store/modules/user/types'
|
|
|
+import { RootState } from '@/store/reducers'
|
|
|
import { iMenuItem } from '@/types/router'
|
|
|
import consts from '@/utils/consts'
|
|
|
import { Button, Dropdown, Menu } from "antd"
|
|
|
import React, { useEffect } from 'react'
|
|
|
+import { connect } from 'react-redux'
|
|
|
import { Link, RouteComponentProps, withRouter } from "react-router-dom"
|
|
|
import { apiLogout } from './api'
|
|
|
import styles from './index.module.scss'
|
|
@@ -13,10 +14,12 @@ import MenuItem from './MenuItem'
|
|
|
interface iMenuProps extends RouteComponentProps{
|
|
|
list: iMenuItem[],
|
|
|
history: any
|
|
|
+ username: string
|
|
|
+ logout: Function
|
|
|
}
|
|
|
|
|
|
const NavSider:React.FC<iMenuProps> = (props)=> {
|
|
|
- const { list: MeunList, history } = props
|
|
|
+ const { list: MeunList, history, username, logout } = props
|
|
|
const handleLogout = async () => {
|
|
|
const { code = -1 } = await apiLogout()
|
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
@@ -25,7 +28,7 @@ const NavSider:React.FC<iMenuProps> = (props)=> {
|
|
|
}
|
|
|
useEffect(() => {
|
|
|
return () => {
|
|
|
- store.dispatch(deleteUserInfo())
|
|
|
+ logout()
|
|
|
}
|
|
|
}, [])
|
|
|
return (
|
|
@@ -65,7 +68,7 @@ const NavSider:React.FC<iMenuProps> = (props)=> {
|
|
|
</Menu>
|
|
|
)
|
|
|
}} trigger={[ 'click' ]} placement="topRight">
|
|
|
- <Button size="small" className={styles.bottomBtn} >张三</Button>
|
|
|
+ <Button size="small" className={styles.bottomBtn}>{username}</Button>
|
|
|
</Dropdown>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -73,4 +76,14 @@ const NavSider:React.FC<iMenuProps> = (props)=> {
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
-export default withRouter(NavSider)
|
|
|
+const mapStateToProps = (state:RootState) => {
|
|
|
+ return {
|
|
|
+ username: state.user.userInfo.Name
|
|
|
+ }
|
|
|
+}
|
|
|
+const mapDispathToProps = {
|
|
|
+ logout: () => {
|
|
|
+ return { type: DEL_USER_INFO }
|
|
|
+ }
|
|
|
+}
|
|
|
+export default withRouter(connect(mapStateToProps, mapDispathToProps)(NavSider))
|