import React, { PureComponent } from 'react'; import { connect } from 'dva'; import { Link } from 'dva/router'; import moment from 'moment'; import numeral from 'numeral'; import { List, Card, Row, Col, Icon, Dropdown, Menu, Avatar, Tag, Divider, Tooltip, Spin, Input } from 'antd'; import AvatarList from '../components/AvatarList'; import { formatWan } from '../utils/utils'; import styles from './UserCenter.less'; import stylesArticles from './List/Articles.less'; import stylesApplications from './List/Applications.less'; import stylesProjects from './List/Projects.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 UserCenter extends PureComponent { state = { key: 'article', newTags: [], inputVisible: false, inputValue: '', } componentDidMount() { const { dispatch } = this.props; this.props.dispatch({ type: 'user/fetchCurrent', }); dispatch({ type: 'list/fetch', payload: { count: 8, }, }); dispatch({ type: 'project/fetchNotice', }); } onTabChange = (key) => { this.setState({ key }); } 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: '', }); } renderArticles = (list, loading) => { const IconText = ({ type, text }) => ( {text} ); const ListContent = ({ data: { content, updatedAt, avatar, owner, href } }) => (
{content}
{owner} 发布在 {href} {moment(updatedAt).format('YYYY-MM-DD HH:mm')}
); return ( ( , , , ]} > {item.title} )} description={ Ant Design 设计语言 蚂蚁金服 } /> )} /> ); } renderApplications = (list, loading) => { const itemMenu = ( 1st menu item 2nd menu item 3d menu item ); const CardInfo = ({ activeUser, newUser }) => (

活跃用户

{activeUser}

新增用户

{newUser}

); return ( ( , , , , ]} > } title={item.title} />
)} /> ); } renderProjects = (list, loading) => { return ( ( } > {item.title}} description={item.subDescription} />
{moment(item.updatedAt).fromNow()}
{ item.members.map(member => ( )) }
)} /> ); } render() { const { key, newTags, inputVisible, inputValue } = this.state; const { list: { list }, listLoading, currentUser, currentUserLoading, project: { notice }, projectLoading } = this.props; const operationTabList = [{ key: 'article', tab: 文章 (8), }, { key: 'application', tab: 应用 (8), }, { key: 'project', tab: 项目 (8), }]; const contentMap = { article: this.renderArticles(list, listLoading), application: this.renderApplications(list, listLoading), project: this.renderProjects(list, listLoading), }; 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...' }
{contentMap[key]}
); } }