import { Avatar, Card, Col, Divider, Icon, Input, Row, Tag } from 'antd'; import React, { PureComponent } from 'react'; import { Dispatch } from 'redux'; import { GridContent } from '@ant-design/pro-layout'; import Link from 'umi/link'; import { RouteChildrenProps } from 'react-router'; import { connect } from 'dva'; import { ModalState } from './model'; import Projects from './components/Projects'; import Articles from './components/Articles'; import Applications from './components/Applications'; import { CurrentUser, TagType } from './data.d'; import styles from './Center.less'; const operationTabList = [ { key: 'articles', tab: ( 文章 (8) ), }, { key: 'applications', tab: ( 应用 (8) ), }, { key: 'projects', tab: ( 项目 (8) ), }, ]; interface AccountCenterProps extends RouteChildrenProps { dispatch: Dispatch; currentUser: CurrentUser; currentUserLoading: boolean; } interface AccountCenterState { newTags: TagType[]; tabKey: 'articles' | 'applications' | 'projects'; inputVisible: boolean; inputValue: string; } @connect( ({ loading, accountCenter, }: { loading: { effects: { [key: string]: boolean } }; accountCenter: ModalState; }) => ({ currentUser: accountCenter.currentUser, currentUserLoading: loading.effects['accountCenter/fetchCurrent'], }), ) class Center extends PureComponent { // static getDerivedStateFromProps( // props: accountCenterProps, // state: accountCenterState, // ) { // const { match, location } = props; // const { tabKey } = state; // const path = match && match.path; // const urlTabKey = location.pathname.replace(`${path}/`, ''); // if (urlTabKey && urlTabKey !== '/' && tabKey !== urlTabKey) { // return { // tabKey: urlTabKey, // }; // } // return null; // } state: AccountCenterState = { newTags: [], inputVisible: false, inputValue: '', tabKey: 'articles', }; public input: Input | null | undefined = undefined; componentDidMount() { const { dispatch } = this.props; dispatch({ type: 'accountCenter/fetchCurrent', }); dispatch({ type: 'accountCenter/fetch', }); } onTabChange = (key: string) => { // If you need to sync state to url // const { match } = this.props; // router.push(`${match.url}/${key}`); this.setState({ tabKey: key as accountCenterState['tabKey'], }); }; showInput = () => { this.setState({ inputVisible: true }, () => this.input && this.input.focus()); }; saveInputRef = (input: Input | null) => { this.input = input; }; handleInputChange = (e: React.ChangeEvent) => { this.setState({ inputValue: e.target.value }); }; handleInputConfirm = () => { const { state } = this; const { inputValue } = state; let { newTags } = state; if (inputValue && newTags.filter(tag => tag.label === inputValue).length === 0) { newTags = [...newTags, { key: `new-${newTags.length}`, label: inputValue }]; } this.setState({ newTags, inputVisible: false, inputValue: '', }); }; renderChildrenByTabKey = (tabKey: accountCenterState['tabKey']) => { if (tabKey === 'projects') { return ; } if (tabKey === 'applications') { return ; } if (tabKey === 'articles') { return ; } return null; }; render() { const { newTags, inputVisible, inputValue, tabKey } = this.state; const { currentUser, currentUserLoading } = this.props; const dataLoading = currentUserLoading || !(currentUser && Object.keys(currentUser).length); return ( {!dataLoading ? (
{currentUser.name}
{currentUser.signature}

{currentUser.title}

{currentUser.group}

{currentUser.geographic.province.label} {currentUser.geographic.city.label}

标签
{currentUser.tags.concat(newTags).map(item => ( {item.label} ))} {inputVisible && ( this.saveInputRef(ref)} type="text" size="small" style={{ width: 78 }} value={inputValue} onChange={this.handleInputChange} onBlur={this.handleInputConfirm} onPressEnter={this.handleInputConfirm} /> )} {!inputVisible && ( )}
团队
{currentUser.notice && currentUser.notice.map(item => ( {item.member} ))}
) : null}
{this.renderChildrenByTabKey(tabKey)}
); } } export default Center;