Commit 8895a2fd authored by ZYSzys's avatar ZYSzys Committed by 陈帅

extract ListContent as a component (#2482)

* extract ListContent as a component

* rename ListContent to ArticleListContent
parent 21c252c8
import React from 'react';
import moment from 'moment';
import { Avatar } from 'antd';
import styles from './index.less';
const ArticleListContent = ({ data: { content, updatedAt, avatar, owner, href } }) => (
<div className={styles.listContent}>
<div className={styles.description}>{content}</div>
<div className={styles.extra}>
<Avatar src={avatar} size="small" />
<a href={href}>{owner}</a> 发布在 <a href={href}>{href}</a>
<em>{moment(updatedAt).format('YYYY-MM-DD HH:mm')}</em>
</div>
</div>
);
export default ArticleListContent;
@import '~antd/lib/style/themes/default.less';
.listContent {
.description {
line-height: 22px;
max-width: 720px;
}
.extra {
color: @text-color-secondary;
margin-top: 16px;
line-height: 22px;
& > :global(.ant-avatar) {
vertical-align: top;
margin-right: 8px;
width: 20px;
height: 20px;
position: relative;
top: 1px;
}
& > em {
color: @disabled-color;
font-style: normal;
margin-left: 16px;
}
}
}
@media screen and (max-width: @screen-xs) {
.listContent {
.extra {
& > em {
display: block;
margin-left: 0;
margin-top: 8px;
}
}
}
}
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { List, Icon, Avatar, Tag } from 'antd'; import { List, Icon, Tag } from 'antd';
import moment from 'moment';
import { connect } from 'dva'; import { connect } from 'dva';
import stylesArticles from '../../List/Articles.less'; import ArticleListContent from '@/components/ArticleListContent';
import styles from './Articles.less'; import styles from './Articles.less';
@connect(({ list }) => ({ @connect(({ list }) => ({
...@@ -19,16 +18,6 @@ class Center extends PureComponent { ...@@ -19,16 +18,6 @@ class Center extends PureComponent {
{text} {text}
</span> </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" />
<a href={href}>{owner}</a> 发布在 <a href={href}>{href}</a>
<em>{moment(updatedAt).format('YYYY-MM-DD HH:mm')}</em>
</div>
</div>
);
return ( return (
<List <List
size="large" size="large"
...@@ -47,7 +36,7 @@ class Center extends PureComponent { ...@@ -47,7 +36,7 @@ class Center extends PureComponent {
> >
<List.Item.Meta <List.Item.Meta
title={ title={
<a className={stylesArticles.listItemMetaTitle} href={item.href}> <a className={styles.listItemMetaTitle} href={item.href}>
{item.title} {item.title}
</a> </a>
} }
...@@ -59,7 +48,7 @@ class Center extends PureComponent { ...@@ -59,7 +48,7 @@ class Center extends PureComponent {
</span> </span>
} }
/> />
<ListContent data={item} /> <ArticleListContent data={item} />
</List.Item> </List.Item>
)} )}
/> />
......
@import '~antd/lib/style/themes/default.less';
.articleList { .articleList {
:global { :global {
.ant-list-item:first-child { .ant-list-item:first-child {
...@@ -5,3 +7,6 @@ ...@@ -5,3 +7,6 @@
} }
} }
} }
a.listItemMetaTitle {
color: @heading-color;
}
import React, { Component, Fragment } from 'react'; import React, { Component, Fragment } from 'react';
import moment from 'moment';
import { connect } from 'dva'; import { connect } from 'dva';
import { Form, Card, Select, List, Tag, Icon, Avatar, Row, Col, Button } from 'antd'; import { Form, Card, Select, List, Tag, Icon, Row, Col, Button } from 'antd';
import TagSelect from '@/components/TagSelect'; import TagSelect from '@/components/TagSelect';
import StandardFormRow from '@/components/StandardFormRow'; import StandardFormRow from '@/components/StandardFormRow';
import ArticleListContent from '@/components/ArticleListContent';
import styles from './Articles.less'; import styles from './Articles.less';
const { Option } = Select; const { Option } = Select;
...@@ -96,18 +96,6 @@ class SearchList extends Component { ...@@ -96,18 +96,6 @@ class SearchList extends Component {
</span> </span>
); );
const ListContent = ({ data: { content, updatedAt, avatar, owner, href } }) => (
<div className={styles.listContent}>
<div className={styles.description}>{content}</div>
<div className={styles.extra}>
<Avatar src={avatar} size="small" />
<a href={href}>{owner}</a> 发布
<a href={href}>{href}</a>
<em>{moment(updatedAt).format('YYYY-MM-DD HH:mm')}</em>
</div>
</div>
);
const formItemLayout = { const formItemLayout = {
wrapperCol: { wrapperCol: {
xs: { span: 24 }, xs: { span: 24 },
...@@ -186,10 +174,7 @@ class SearchList extends Component { ...@@ -186,10 +174,7 @@ class SearchList extends Component {
<Col xl={8} lg={10} md={12} sm={24} xs={24}> <Col xl={8} lg={10} md={12} sm={24} xs={24}>
<FormItem {...formItemLayout} label="活跃用户"> <FormItem {...formItemLayout} label="活跃用户">
{getFieldDecorator('user', {})( {getFieldDecorator('user', {})(
<Select <Select placeholder="不限" style={{ maxWidth: 200, width: '100%' }}>
placeholder="不限"
style={{ maxWidth: 200, width: '100%' }}
>
<Option value="lisa">李三</Option> <Option value="lisa">李三</Option>
</Select> </Select>
)} )}
...@@ -198,10 +183,7 @@ class SearchList extends Component { ...@@ -198,10 +183,7 @@ class SearchList extends Component {
<Col xl={8} lg={10} md={12} sm={24} xs={24}> <Col xl={8} lg={10} md={12} sm={24} xs={24}>
<FormItem {...formItemLayout} label="好评度"> <FormItem {...formItemLayout} label="好评度">
{getFieldDecorator('rate', {})( {getFieldDecorator('rate', {})(
<Select <Select placeholder="不限" style={{ maxWidth: 200, width: '100%' }}>
placeholder="不限"
style={{ maxWidth: 200, width: '100%' }}
>
<Option value="good">优秀</Option> <Option value="good">优秀</Option>
</Select> </Select>
)} )}
...@@ -247,7 +229,7 @@ class SearchList extends Component { ...@@ -247,7 +229,7 @@ class SearchList extends Component {
</span> </span>
} }
/> />
<ListContent data={item} /> <ArticleListContent data={item} />
</List.Item> </List.Item>
)} )}
/> />
......
@import '~antd/lib/style/themes/default.less'; @import '~antd/lib/style/themes/default.less';
@import '~@/utils/utils.less';
.listContent {
.description {
line-height: 22px;
max-width: 720px;
}
.extra {
color: @text-color-secondary;
margin-top: 16px;
line-height: 22px;
& > :global(.ant-avatar) {
vertical-align: top;
margin-right: 8px;
width: 20px;
height: 20px;
position: relative;
top: 1px;
}
& > em {
color: @disabled-color;
font-style: normal;
margin-left: 16px;
}
}
}
a.listItemMetaTitle { a.listItemMetaTitle {
color: @heading-color; color: @heading-color;
} }
...@@ -41,15 +16,6 @@ a.listItemMetaTitle { ...@@ -41,15 +16,6 @@ a.listItemMetaTitle {
display: block; display: block;
margin-left: 0; margin-left: 0;
} }
.listContent {
.extra {
& > em {
display: block;
margin-left: 0;
margin-top: 8px;
}
}
}
} }
@media screen and (max-width: @screen-md) { @media screen and (max-width: @screen-md) {
.selfTrigger { .selfTrigger {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment