import React, { PureComponent } from 'react'; import { connect } from 'dva'; import { Link, routerRedux, Route, Switch, Redirect } from 'dva/router'; import { Card, Row, Col, Icon, Avatar, Tag, Divider, Spin, Input } from 'antd'; import { getRoutes } from '../../../utils/utils'; import GridContent from '../../../layouts/GridContent'; import styles from './Center.less'; @connect(({ list, loading, user, project }) => ({ list, listLoading: loading.effects['list/fetch'], currentUser: user.currentUser, currentUserLoading: loading.effects['user/fetchCurrent'], project, projectLoading: loading.effects['project/fetchNotice'], })) export default class Center extends PureComponent { state = { newTags: [], inputVisible: false, inputValue: '', }; componentDidMount() { const { dispatch } = this.props; dispatch({ type: 'user/fetchCurrent', }); dispatch({ type: 'list/fetch', payload: { count: 8, }, }); dispatch({ type: 'project/fetchNotice', }); } onTabChange = key => { const { dispatch, match } = this.props; switch (key) { case 'articles': dispatch(routerRedux.push(`${match.url}/articles`)); break; case 'applications': dispatch(routerRedux.push(`${match.url}/applications`)); break; case 'projects': dispatch(routerRedux.push(`${match.url}/projects`)); break; default: break; } }; showInput = () => { this.setState({ inputVisible: true }, () => this.input.focus()); }; saveInputRef = input => { this.input = input; }; handleInputChange = e => { 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: '', }); }; render() { const { newTags, inputVisible, inputValue } = this.state; const { list: { list }, listLoading, currentUser, currentUserLoading, project: { notice }, projectLoading, match, routerData, location, } = this.props; const routes = getRoutes(match.path, routerData); const operationTabList = [ { key: 'articles', tab: ( 文章 (8) ), }, { key: 'applications', tab: ( 应用 (8) ), }, { key: 'projects', tab: ( 项目 (8) ), }, ]; return ( {currentUser && Object.keys(currentUser).length ? (
{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 && ( )} {!inputVisible && ( )}
团队
{notice.map(item => ( {item.member} ))}
) : ( 'loading...' )}
{routes.map(item => ( } exact={item.exact} /> ))}
); } }