Articles.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import React, { Component, Fragment } from 'react';
  2. import moment from 'moment';
  3. import { connect } from 'dva';
  4. import { Form, Card, Select, List, Tag, Icon, Avatar, Row, Col, Button } from 'antd';
  5. import TagSelect from 'components/TagSelect';
  6. import StandardFormRow from 'components/StandardFormRow';
  7. import styles from './Articles.less';
  8. const { Option } = Select;
  9. const FormItem = Form.Item;
  10. const pageSize = 5;
  11. @Form.create()
  12. @connect(({ list, loading }) => ({
  13. list,
  14. loading: loading.models.list,
  15. }))
  16. export default class SearchList extends Component {
  17. componentDidMount() {
  18. this.fetchMore();
  19. }
  20. setOwner = () => {
  21. const { form } = this.props;
  22. form.setFieldsValue({
  23. owner: ['wzj'],
  24. });
  25. };
  26. fetchMore = () => {
  27. const { dispatch } = this.props;
  28. dispatch({
  29. type: 'list/appendFetch',
  30. payload: {
  31. count: pageSize,
  32. },
  33. });
  34. };
  35. render() {
  36. const {
  37. form,
  38. list: { list },
  39. loading,
  40. } = this.props;
  41. const { getFieldDecorator } = form;
  42. const owners = [
  43. {
  44. id: 'wzj',
  45. name: '我自己',
  46. },
  47. {
  48. id: 'wjh',
  49. name: '吴家豪',
  50. },
  51. {
  52. id: 'zxx',
  53. name: '周星星',
  54. },
  55. {
  56. id: 'zly',
  57. name: '赵丽颖',
  58. },
  59. {
  60. id: 'ym',
  61. name: '姚明',
  62. },
  63. ];
  64. const IconText = ({ type, text }) => (
  65. <span>
  66. <Icon type={type} style={{ marginRight: 8 }} />
  67. {text}
  68. </span>
  69. );
  70. const ListContent = ({ data: { content, updatedAt, avatar, owner, href } }) => (
  71. <div className={styles.listContent}>
  72. <div className={styles.description}>{content}</div>
  73. <div className={styles.extra}>
  74. <Avatar src={avatar} size="small" />
  75. <a href={href}>{owner}</a> 发布在
  76. <a href={href}>{href}</a>
  77. <em>{moment(updatedAt).format('YYYY-MM-DD HH:mm')}</em>
  78. </div>
  79. </div>
  80. );
  81. const formItemLayout = {
  82. wrapperCol: {
  83. xs: { span: 24 },
  84. sm: { span: 24 },
  85. md: { span: 12 },
  86. },
  87. };
  88. const loadMore =
  89. list.length > 0 ? (
  90. <div style={{ textAlign: 'center', marginTop: 16 }}>
  91. <Button onClick={this.fetchMore} style={{ paddingLeft: 48, paddingRight: 48 }}>
  92. {loading ? (
  93. <span>
  94. <Icon type="loading" /> 加载中...
  95. </span>
  96. ) : (
  97. '加载更多'
  98. )}
  99. </Button>
  100. </div>
  101. ) : null;
  102. return (
  103. <Fragment>
  104. <Card bordered={false}>
  105. <Form layout="inline">
  106. <StandardFormRow title="所属类目" block style={{ paddingBottom: 11 }}>
  107. <FormItem>
  108. {getFieldDecorator('category')(
  109. <TagSelect onChange={this.handleFormSubmit} expandable>
  110. <TagSelect.Option value="cat1">类目一</TagSelect.Option>
  111. <TagSelect.Option value="cat2">类目二</TagSelect.Option>
  112. <TagSelect.Option value="cat3">类目三</TagSelect.Option>
  113. <TagSelect.Option value="cat4">类目四</TagSelect.Option>
  114. <TagSelect.Option value="cat5">类目五</TagSelect.Option>
  115. <TagSelect.Option value="cat6">类目六</TagSelect.Option>
  116. <TagSelect.Option value="cat7">类目七</TagSelect.Option>
  117. <TagSelect.Option value="cat8">类目八</TagSelect.Option>
  118. <TagSelect.Option value="cat9">类目九</TagSelect.Option>
  119. <TagSelect.Option value="cat10">类目十</TagSelect.Option>
  120. <TagSelect.Option value="cat11">类目十一</TagSelect.Option>
  121. <TagSelect.Option value="cat12">类目十二</TagSelect.Option>
  122. </TagSelect>
  123. )}
  124. </FormItem>
  125. </StandardFormRow>
  126. <StandardFormRow title="owner" grid>
  127. <Row>
  128. <Col lg={16} md={24} sm={24} xs={24}>
  129. <FormItem>
  130. {getFieldDecorator('owner', {
  131. initialValue: ['wjh', 'zxx'],
  132. })(
  133. <Select
  134. mode="multiple"
  135. style={{ maxWidth: 286, width: '100%' }}
  136. placeholder="选择 owner"
  137. >
  138. {owners.map(owner => (
  139. <Option key={owner.id} value={owner.id}>
  140. {owner.name}
  141. </Option>
  142. ))}
  143. </Select>
  144. )}
  145. <a className={styles.selfTrigger} onClick={this.setOwner}>
  146. 只看自己的
  147. </a>
  148. </FormItem>
  149. </Col>
  150. </Row>
  151. </StandardFormRow>
  152. <StandardFormRow title="其它选项" grid last>
  153. <Row gutter={16}>
  154. <Col xl={8} lg={10} md={12} sm={24} xs={24}>
  155. <FormItem {...formItemLayout} label="活跃用户">
  156. {getFieldDecorator('user', {})(
  157. <Select
  158. onChange={this.handleFormSubmit}
  159. placeholder="不限"
  160. style={{ maxWidth: 200, width: '100%' }}
  161. >
  162. <Option value="lisa">李三</Option>
  163. </Select>
  164. )}
  165. </FormItem>
  166. </Col>
  167. <Col xl={8} lg={10} md={12} sm={24} xs={24}>
  168. <FormItem {...formItemLayout} label="好评度">
  169. {getFieldDecorator('rate', {})(
  170. <Select
  171. onChange={this.handleFormSubmit}
  172. placeholder="不限"
  173. style={{ maxWidth: 200, width: '100%' }}
  174. >
  175. <Option value="good">优秀</Option>
  176. </Select>
  177. )}
  178. </FormItem>
  179. </Col>
  180. </Row>
  181. </StandardFormRow>
  182. </Form>
  183. </Card>
  184. <Card
  185. style={{ marginTop: 24 }}
  186. bordered={false}
  187. bodyStyle={{ padding: '8px 32px 32px 32px' }}
  188. >
  189. <List
  190. size="large"
  191. loading={list.length === 0 ? loading : false}
  192. rowKey="id"
  193. itemLayout="vertical"
  194. loadMore={loadMore}
  195. dataSource={list}
  196. renderItem={item => (
  197. <List.Item
  198. key={item.id}
  199. actions={[
  200. <IconText type="star-o" text={item.star} />,
  201. <IconText type="like-o" text={item.like} />,
  202. <IconText type="message" text={item.message} />,
  203. ]}
  204. extra={<div className={styles.listItemExtra} />}
  205. >
  206. <List.Item.Meta
  207. title={
  208. <a className={styles.listItemMetaTitle} href={item.href}>
  209. {item.title}
  210. </a>
  211. }
  212. description={
  213. <span>
  214. <Tag>Ant Design</Tag>
  215. <Tag>设计语言</Tag>
  216. <Tag>蚂蚁金服</Tag>
  217. </span>
  218. }
  219. />
  220. <ListContent data={item} />
  221. </List.Item>
  222. )}
  223. />
  224. </Card>
  225. </Fragment>
  226. );
  227. }
  228. }