动态菜单和动态路由的 antd pro

Projects.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import React, { PureComponent } from 'react';
  2. import moment from 'moment';
  3. import { connect } from 'dva';
  4. import { Row, Col, Form, Card, Select, List } from 'antd';
  5. import TagSelect from 'components/TagSelect';
  6. import AvatarList from 'components/AvatarList';
  7. import Ellipsis from 'components/Ellipsis';
  8. import StandardFormRow from 'components/StandardFormRow';
  9. import styles from './Projects.less';
  10. const { Option } = Select;
  11. const FormItem = Form.Item;
  12. /* eslint react/no-array-index-key: 0 */
  13. @Form.create()
  14. @connect(({ list, loading }) => ({
  15. list,
  16. loading: loading.models.list,
  17. }))
  18. export default class CoverCardList extends PureComponent {
  19. componentDidMount() {
  20. this.props.dispatch({
  21. type: 'list/fetch',
  22. payload: {
  23. count: 8,
  24. },
  25. });
  26. }
  27. handleFormSubmit = () => {
  28. const { form, dispatch } = this.props;
  29. // setTimeout 用于保证获取表单值是在所有表单字段更新完毕的时候
  30. setTimeout(() => {
  31. form.validateFields(err => {
  32. if (!err) {
  33. // eslint-disable-next-line
  34. dispatch({
  35. type: 'list/fetch',
  36. payload: {
  37. count: 8,
  38. },
  39. });
  40. }
  41. });
  42. }, 0);
  43. };
  44. render() {
  45. const { list: { list = [] }, loading, form } = this.props;
  46. const { getFieldDecorator } = form;
  47. const cardList = list ? (
  48. <List
  49. rowKey="id"
  50. loading={loading}
  51. grid={{ gutter: 24, xl: 4, lg: 3, md: 3, sm: 2, xs: 1 }}
  52. dataSource={list}
  53. renderItem={item => (
  54. <List.Item>
  55. <Card
  56. className={styles.card}
  57. hoverable
  58. cover={<img alt={item.title} src={item.cover} height={154} />}
  59. >
  60. <Card.Meta
  61. title={<a href="#">{item.title}</a>}
  62. description={<Ellipsis lines={2}>{item.subDescription}</Ellipsis>}
  63. />
  64. <div className={styles.cardItemContent}>
  65. <span>{moment(item.updatedAt).fromNow()}</span>
  66. <div className={styles.avatarList}>
  67. <AvatarList size="mini">
  68. {item.members.map((member, i) => (
  69. <AvatarList.Item
  70. key={`${item.id}-avatar-${i}`}
  71. src={member.avatar}
  72. tips={member.name}
  73. />
  74. ))}
  75. </AvatarList>
  76. </div>
  77. </div>
  78. </Card>
  79. </List.Item>
  80. )}
  81. />
  82. ) : null;
  83. const formItemLayout = {
  84. wrapperCol: {
  85. xs: { span: 24 },
  86. sm: { span: 16 },
  87. },
  88. };
  89. return (
  90. <div className={styles.coverCardList}>
  91. <Card bordered={false}>
  92. <Form layout="inline">
  93. <StandardFormRow title="所属类目" block style={{ paddingBottom: 11 }}>
  94. <FormItem>
  95. {getFieldDecorator('category')(
  96. <TagSelect onChange={this.handleFormSubmit} expandable>
  97. <TagSelect.Option value="cat1">类目一</TagSelect.Option>
  98. <TagSelect.Option value="cat2">类目二</TagSelect.Option>
  99. <TagSelect.Option value="cat3">类目三</TagSelect.Option>
  100. <TagSelect.Option value="cat4">类目四</TagSelect.Option>
  101. <TagSelect.Option value="cat5">类目五</TagSelect.Option>
  102. <TagSelect.Option value="cat6">类目六</TagSelect.Option>
  103. <TagSelect.Option value="cat7">类目七</TagSelect.Option>
  104. <TagSelect.Option value="cat8">类目八</TagSelect.Option>
  105. <TagSelect.Option value="cat9">类目九</TagSelect.Option>
  106. <TagSelect.Option value="cat10">类目十</TagSelect.Option>
  107. <TagSelect.Option value="cat11">类目十一</TagSelect.Option>
  108. <TagSelect.Option value="cat12">类目十二</TagSelect.Option>
  109. </TagSelect>
  110. )}
  111. </FormItem>
  112. </StandardFormRow>
  113. <StandardFormRow title="其它选项" grid last>
  114. <Row gutter={16}>
  115. <Col lg={8} md={10} sm={10} xs={24}>
  116. <FormItem {...formItemLayout} label="作者">
  117. {getFieldDecorator('author', {})(
  118. <Select
  119. onChange={this.handleFormSubmit}
  120. placeholder="不限"
  121. style={{ maxWidth: 200, width: '100%' }}
  122. >
  123. <Option value="lisa">王昭君</Option>
  124. </Select>
  125. )}
  126. </FormItem>
  127. </Col>
  128. <Col lg={8} md={10} sm={10} xs={24}>
  129. <FormItem {...formItemLayout} label="好评度">
  130. {getFieldDecorator('rate', {})(
  131. <Select
  132. onChange={this.handleFormSubmit}
  133. placeholder="不限"
  134. style={{ maxWidth: 200, width: '100%' }}
  135. >
  136. <Option value="good">优秀</Option>
  137. <Option value="normal">普通</Option>
  138. </Select>
  139. )}
  140. </FormItem>
  141. </Col>
  142. </Row>
  143. </StandardFormRow>
  144. </Form>
  145. </Card>
  146. <div className={styles.cardList}>{cardList}</div>
  147. </div>
  148. );
  149. }
  150. }