import * as React from 'react'; import classsames from "classnames"; import Card from './Card' import './index.scss'; interface UserTreeProps { prefix?: string; addVSCallback: Function; canVS: boolean; keyword: string; currentUserId: number; showVS: Function; } interface UserTreeState { cardIndex: number; direction: boolean; cardDelay: boolean; } export default class UserTree extends React.PureComponent { static defaultProps = { prefix: 'upaas' } currentUserId: number; constructor(props: UserTreeProps) { super(props); this.currentUserId = props.currentUserId; this.state = { cardIndex: 0, direction: true, // 离场方向 top: true, bottom: false cardDelay: false } } componentDidMount() { } componentWillUnmount() { clearTimeout(this.delayTimer) } getCardShow = () => { const { cardIndex } = this.state; return !!(Math.abs(cardIndex) % 2) } delayTimer: any = null toogleCard = (toogle: string, userId: number) => { let { cardIndex } = this.state; const newCardIndex = cardIndex += toogle == 'top' ? 1 : -1; this.currentUserId = userId; this.setState({ cardIndex: newCardIndex, direction: toogle == 'top', cardDelay: true }) clearTimeout(this.delayTimer) this.delayTimer = setTimeout(() => { this.setState({ cardDelay: false }) }, 300) } render() { const { prefix, canVS, addVSCallback, showVS } = this.props; const { currentUserId } = this; const { direction, cardDelay } = this.state; const classStr = classsames(`${prefix}-usertree`); return (
) } }