import React, { PureComponent } from 'react' import styled from 'styled-components'; import Avatar from 'ux-feature-avatar'; // import Pop from '&/components/common/pop' import { getUserInfo, getQueryString, taker, getApiUrl } from '&/components/helper'; import { findDOMNode } from 'react-dom'; import ReactToolTip from 'react-tooltip'; import { PrincipalUser } from '&/pages/okrPanel/components/types'; interface Props { user?:PrincipalUser workName?:string onChangeOkr: Function } interface State { userInfo?: UserInfo } interface UserInfo { UserAvatar: UserAvatar; Avatar: UserAvatar; Position: string; EmployedDate: string; EnrolledYears: string; EntryYears: number; BlessingType: number; Birthday: string; UserId: number; Name: string; Sex: string; Age: string; PersonalPictureUrl: PersonalPictureUrl; PersonalHomePageUrl: string; Email: string; DepartmentId: number; DepartmentName: string; PositionName: string; IsCurrentUser: boolean; AvatarColor?: any; HasAvatar: boolean; SubordinateNum: number; StaffStatus: number; } interface PersonalPictureUrl { s: string; b: string; l: string; n: string; } interface UserAvatar { Original: string; Small: string; Medium: string; Big: string; Large: string; Normal: string; HasAvatar: boolean; Color?: any; } const Wrapper = styled.div` position:relative; height: 46px; background-color: #1D86F0; display: flex; flex-direction: row; align-items: center; justify-content: center; padding: 0 20px; ` // const MenuWrapper = styled.div` // width: 14px; // height: 10px; // display: flex; // flex-direction: column; // justify-content: space-between; // cursor: pointer; // ` // const Line = styled.div` // width: 14px; // height: 2px; // background-color: #FFF; // border-radius: 8px; // ` const Titile = styled.span` font-size: 18px; color: #FFFFFF; line-height: 24px; margin-left: 10px; white-space: nowrap; max-width: calc(100% - 40px); overflow: hidden; cursor: default; ` const Cover = styled.div` position: absolute; top: 0px; right: 0px; width: 145px; height: 46px; display: flex; align-items: center; justify-content: flex-end; box-sizing: border-box; padding-right: 20px; background-image: linear-gradient(90deg, rgba(29,134,240,0.00) 0%, #1D86F0 91px, #1D86F0 91px); ` // const MenuList = styled.ul` // width: 88px; // background: #FFFFFF; // box-shadow: 0 1px 3px 0 rgba(0,0,0,0.20); // border-radius: 1px; // margin-top: 5px; // margin-right: 16px; // padding: 10px 0; // ` // const MenuItem = styled.li` // height: 25px; // display: flex; // align-items: center; // padding: 0 10px; // justify-content: space-between; // cursor: pointer; // &:hover { // background-color: rgba(29,134,240,0.1) // } // ` const MenuChangeKr = styled.div` width: 88px; background: rgba(255,255,255,0.2); height: 21px; line-height: 21px; border-radius: 10px; color:#fff; font-size:13px; text-align:center; cursor: pointer; font-weight: bold; &:hover{ background: rgba(255,255,255,0.3); } ` export default class Header extends PureComponent { constructor(p:Props){ super(p) this.state = { } } menuList:any; menuIcon:any; menuShowed = false; timer: any; componentDidMount(){ this.getData() } componentWillUnmount(){ clearTimeout(this.timer) } // componentWillReceiveProps(nextProp:Props){ // alert(nextProp.toUserId) // if(nextProp.toUserId && this.state.userInfo && nextProp.toUserId != this.state.userInfo.UserId){ // this.getData() // } // } componentDidUpdate(prevProps:Props,prevState:State){ const preUserName = prevProps.user? prevProps.user.name : prevState.userInfo? prevState.userInfo.Name : ''; const currentUserName = this.props.user? this.props.user.name : this.state.userInfo? this.state.userInfo.Name : ''; if(prevProps.workName != this.props.workName || preUserName != currentUserName){ ReactToolTip.rebuild() } } getData = async () => { const selfId = getUserInfo()['Id']; const toUserID = getQueryString()['to_user_id']; const url = `${getApiUrl('proxy/GetUPaaSCoreGateway/AccountService/GetUserInfo')}?toUserId=${toUserID || selfId}`; let res = await taker(url, 'get') if (!res || !res.OperationObject) return; const { OperationObject } = res; this.setState({ userInfo: OperationObject }) } showMenu = () => { clearTimeout(this.timer); if(this.menuShowed) return; this.menuShowed = true; this.menuList.show(findDOMNode(this.menuIcon)) } hideMenu = () => { this.timer = setTimeout(() => { this.menuShowed = false; this.menuList && this.menuList.hide() }, 200); } handleChangeOkr = () => { //@ts-ignore let moveX = (this.refs.wrapper.clientWidth - 589)/2; if(moveX<0) moveX = 0; this.hideMenu(); this.props.onChangeOkr(this.refs.wrapper,moveX) } renderUserAvatar = () => { const {userInfo} = this.state; const {user} = this.props; if(user){ const avatarInfo = { hasAvatar:user.avatar.hasAvatar, img: user.avatar.big, color:user.avatar.color } return (
) }else if(userInfo){ const avatarInfo = { hasAvatar: userInfo.HasAvatar, img: userInfo.Avatar.Big, color: userInfo.Avatar.Color }; return (
) } return null; } render() { const {workName} = this.props; return ( {this.renderUserAvatar()} {!!workName && {workName}} {/* this.menuIcon = r} onMouseOver={this.showMenu} onMouseOut={this.hideMenu}> */} {/* */} {/* */} 切换目标 {/* */} {/* this.menuList =r} container={document.querySelector(".pg-tmpl-honour-scroll")} style={{background:'transparent',boxShadow:'none',border:'none'}}> 切换目标 */} ) } }