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

Articles.js 7.5KB

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