Articles.js 1.98 KB
Newer Older
愚道's avatar
愚道 committed
1
import React, { PureComponent } from 'react';
ddcat1115's avatar
ddcat1115 committed
2 3
import { List, Icon, Avatar, Tag } from 'antd';
import moment from 'moment';
愚道's avatar
愚道 committed
4 5
import { connect } from 'dva';
import stylesArticles from '../../List/Articles.less';
ddcat1115's avatar
ddcat1115 committed
6 7
import styles from './Articles.less';

愚道's avatar
愚道 committed
8 9 10
@connect(({ list }) => ({
  list,
}))
afc163's avatar
afc163 committed
11
class Center extends PureComponent {
愚道's avatar
愚道 committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  render() {
    const {
      list: { list },
    } = this.props;
    const IconText = ({ type, text }) => (
      <span>
        <Icon type={type} style={{ marginRight: 8 }} />
        {text}
      </span>
    );
    const ListContent = ({ data: { content, updatedAt, avatar, owner, href } }) => (
      <div className={stylesArticles.listContent}>
        <div className={stylesArticles.description}>{content}</div>
        <div className={stylesArticles.extra}>
          <Avatar src={avatar} size="small" />
ZYSzys's avatar
ZYSzys committed
27
          <a href={href}>{owner}</a> 发布在 <a href={href}>{href}</a>
愚道's avatar
愚道 committed
28 29
          <em>{moment(updatedAt).format('YYYY-MM-DD HH:mm')}</em>
        </div>
ddcat1115's avatar
ddcat1115 committed
30
      </div>
愚道's avatar
愚道 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    );
    return (
      <List
        size="large"
        className={styles.articleList}
        rowKey="id"
        itemLayout="vertical"
        dataSource={list}
        renderItem={item => (
          <List.Item
            key={item.id}
            actions={[
              <IconText type="star-o" text={item.star} />,
              <IconText type="like-o" text={item.like} />,
              <IconText type="message" text={item.message} />,
            ]}
          >
            <List.Item.Meta
              title={
                <a className={stylesArticles.listItemMetaTitle} href={item.href}>
                  {item.title}
                </a>
              }
              description={
                <span>
                  <Tag>Ant Design</Tag>
                  <Tag>设计语言</Tag>
                  <Tag>蚂蚁金服</Tag>
                </span>
              }
            />
            <ListContent data={item} />
          </List.Item>
        )}
      />
    );
  }
}
lijiehua's avatar
lijiehua committed
69 70

export default Center;