CoverCardList.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import React, { PureComponent } from 'react';
  2. import moment from 'moment';
  3. import { connect } from 'dva';
  4. import { routerRedux } from 'dva/router';
  5. import { Row, Col, Form, Card, Select, Spin } from 'antd';
  6. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  7. import StandardFormRow from '../../components/StandardFormRow';
  8. import TagSelect from '../../components/TagSelect';
  9. import AvatarList from '../../components/AvatarList';
  10. import SearchInput from '../../components/SearchInput';
  11. import styles from './CoverCardList.less';
  12. const Option = Select.Option;
  13. const FormItem = Form.Item;
  14. const TagOption = TagSelect.Option;
  15. const TagExpand = TagSelect.Expand;
  16. /* eslint react/no-array-index-key: 0 */
  17. @Form.create()
  18. @connect(state => ({
  19. list: state.list,
  20. }))
  21. export default class CoverCardList extends PureComponent {
  22. componentDidMount() {
  23. this.props.dispatch({
  24. type: 'list/fetch',
  25. payload: {
  26. count: 8,
  27. },
  28. });
  29. }
  30. handleFormSubmit = () => {
  31. const { form, dispatch } = this.props;
  32. // setTimeout 用于保证获取表单值是在所有表单字段更新完毕的时候
  33. setTimeout(() => {
  34. form.validateFields((err) => {
  35. if (!err) {
  36. // eslint-disable-next-line
  37. dispatch({
  38. type: 'list/fetch',
  39. payload: {
  40. count: 8,
  41. },
  42. });
  43. }
  44. });
  45. }, 0);
  46. }
  47. handleTabChange = (key) => {
  48. const { dispatch } = this.props;
  49. switch (key) {
  50. case 'doc':
  51. dispatch(routerRedux.push('/list/search'));
  52. break;
  53. case 'app':
  54. dispatch(routerRedux.push('/list/filter-card-list'));
  55. break;
  56. case 'project':
  57. dispatch(routerRedux.push('/list/cover-card-list'));
  58. break;
  59. default:
  60. break;
  61. }
  62. }
  63. render() {
  64. const { list: { list = [], loading }, form } = this.props;
  65. const { getFieldDecorator } = form;
  66. const cardList = list ? (
  67. <Row gutter={16} style={{ marginTop: 16 }}>
  68. {
  69. list.map(item => (
  70. <Col lg={6} md={8} sm={12} xs={24} style={{ marginBottom: 16 }} key={item.id}>
  71. <Card
  72. cover={<img alt={item.title} src={item.cover} />}
  73. >
  74. <Card.Meta
  75. title={item.title}
  76. description={item.subDescription}
  77. />
  78. <div className={styles.cardItemContent}>
  79. <span>{moment(item.updatedAt).fromNow()}</span>
  80. <div className={styles.avatarList}>
  81. <AvatarList size="small">
  82. {
  83. item.members.map((member, i) => (
  84. <AvatarList.Item
  85. key={`${item.id}-avatar-${i}`}
  86. src={member.avatar}
  87. tips={member.name}
  88. />
  89. ))
  90. }
  91. </AvatarList>
  92. </div>
  93. </div>
  94. </Card>
  95. </Col>
  96. ))
  97. }
  98. </Row>
  99. ) : null;
  100. const tabList = [
  101. {
  102. key: 'doc',
  103. tab: '文章',
  104. },
  105. {
  106. key: 'app',
  107. tab: '应用',
  108. },
  109. {
  110. key: 'project',
  111. tab: '项目',
  112. default: true,
  113. },
  114. ];
  115. const pageHeaderContent = (
  116. <div style={{ textAlign: 'center' }}>
  117. <SearchInput onSearch={this.handleFormSubmit} />
  118. </div>
  119. );
  120. const formItemLayout = {
  121. wrapperCol: {
  122. xs: { span: 24 },
  123. sm: { span: 16 },
  124. },
  125. };
  126. return (
  127. <PageHeaderLayout
  128. title="带封面的卡片列表"
  129. content={pageHeaderContent}
  130. tabList={tabList}
  131. onTabChange={this.handleTabChange}
  132. >
  133. <div className={styles.coverCardList}>
  134. <Card
  135. bordered={false}
  136. noHovering
  137. >
  138. <Form
  139. layout="inline"
  140. >
  141. <StandardFormRow title="所属类目" block>
  142. <FormItem>
  143. {getFieldDecorator('category')(
  144. <TagSelect onChange={this.handleFormSubmit}>
  145. <TagOption value="cat1">类目一</TagOption>
  146. <TagOption value="cat2">类目二</TagOption>
  147. <TagOption value="cat3">类目三</TagOption>
  148. <TagOption value="cat4">类目四</TagOption>
  149. <TagExpand>
  150. <TagOption value="cat5">类目五</TagOption>
  151. <TagOption value="cat6">类目六</TagOption>
  152. </TagExpand>
  153. </TagSelect>
  154. )}
  155. </FormItem>
  156. </StandardFormRow>
  157. <StandardFormRow
  158. title="其它选项"
  159. grid
  160. last
  161. >
  162. <Row gutter={16}>
  163. <Col lg={8} md={10} sm={10} xs={24}>
  164. <FormItem
  165. {...formItemLayout}
  166. label="作者"
  167. >
  168. {getFieldDecorator('author', {})(
  169. <Select
  170. onChange={this.handleFormSubmit}
  171. placeholder="不限"
  172. style={{ maxWidth: 200, width: '100%' }}
  173. >
  174. <Option value="lisa">王昭君</Option>
  175. </Select>
  176. )}
  177. </FormItem>
  178. </Col>
  179. <Col lg={8} md={10} sm={10} xs={24}>
  180. <FormItem
  181. {...formItemLayout}
  182. label="好评度"
  183. >
  184. {getFieldDecorator('rate', {})(
  185. <Select
  186. onChange={this.handleFormSubmit}
  187. placeholder="不限"
  188. style={{ maxWidth: 200, width: '100%' }}
  189. >
  190. <Option value="good">优秀</Option>
  191. <Option value="normal">普通</Option>
  192. </Select>
  193. )}
  194. </FormItem>
  195. </Col>
  196. </Row>
  197. </StandardFormRow>
  198. </Form>
  199. </Card>
  200. {
  201. loading && (list.length > 0) && <Spin>
  202. {cardList}
  203. </Spin>
  204. }
  205. {
  206. loading && (list.length < 1) && <div style={{ marginTop: 16 }}><Spin /></div>
  207. }
  208. {
  209. !loading && cardList
  210. }
  211. </div>
  212. </PageHeaderLayout>
  213. );
  214. }
  215. }