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

Applications.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import React, { PureComponent } from 'react';
  2. import numeral from 'numeral';
  3. import { connect } from 'dva';
  4. import { Row, Col, Form, Card, Select, Icon, Avatar, List, Tooltip, Dropdown, Menu } from 'antd';
  5. import TagSelect from 'components/TagSelect';
  6. import StandardFormRow from 'components/StandardFormRow';
  7. import styles from './Applications.less';
  8. const { Option } = Select;
  9. const FormItem = Form.Item;
  10. const formatWan = val => {
  11. const v = val * 1;
  12. if (!v || isNaN(v)) return '';
  13. let result = val;
  14. if (val > 10000) {
  15. result = Math.floor(val / 10000);
  16. result = (
  17. <span>
  18. {result}
  19. <em className={styles.wan}>万</em>
  20. </span>
  21. );
  22. }
  23. return result;
  24. };
  25. /* eslint react/no-array-index-key: 0 */
  26. @Form.create()
  27. @connect(({ list, loading }) => ({
  28. list,
  29. loading: loading.models.list,
  30. }))
  31. export default class FilterCardList extends PureComponent {
  32. componentDidMount() {
  33. this.props.dispatch({
  34. type: 'list/fetch',
  35. payload: {
  36. count: 8,
  37. },
  38. });
  39. }
  40. handleFormSubmit = () => {
  41. const { form, dispatch } = this.props;
  42. // setTimeout 用于保证获取表单值是在所有表单字段更新完毕的时候
  43. setTimeout(() => {
  44. form.validateFields(err => {
  45. if (!err) {
  46. // eslint-disable-next-line
  47. dispatch({
  48. type: 'list/fetch',
  49. payload: {
  50. count: 8,
  51. },
  52. });
  53. }
  54. });
  55. }, 0);
  56. };
  57. render() {
  58. const { list: { list }, loading, form } = this.props;
  59. const { getFieldDecorator } = form;
  60. const CardInfo = ({ activeUser, newUser }) => (
  61. <div className={styles.cardInfo}>
  62. <div>
  63. <p>活跃用户</p>
  64. <p>{activeUser}</p>
  65. </div>
  66. <div>
  67. <p>新增用户</p>
  68. <p>{newUser}</p>
  69. </div>
  70. </div>
  71. );
  72. const formItemLayout = {
  73. wrapperCol: {
  74. xs: { span: 24 },
  75. sm: { span: 16 },
  76. },
  77. };
  78. const itemMenu = (
  79. <Menu>
  80. <Menu.Item>
  81. <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
  82. 1st menu item
  83. </a>
  84. </Menu.Item>
  85. <Menu.Item>
  86. <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
  87. 2nd menu item
  88. </a>
  89. </Menu.Item>
  90. <Menu.Item>
  91. <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
  92. 3d menu item
  93. </a>
  94. </Menu.Item>
  95. </Menu>
  96. );
  97. return (
  98. <div className={styles.filterCardList}>
  99. <Card bordered={false}>
  100. <Form layout="inline">
  101. <StandardFormRow title="所属类目" block style={{ paddingBottom: 11 }}>
  102. <FormItem>
  103. {getFieldDecorator('category')(
  104. <TagSelect onChange={this.handleFormSubmit} expandable>
  105. <TagSelect.Option value="cat1">类目一</TagSelect.Option>
  106. <TagSelect.Option value="cat2">类目二</TagSelect.Option>
  107. <TagSelect.Option value="cat3">类目三</TagSelect.Option>
  108. <TagSelect.Option value="cat4">类目四</TagSelect.Option>
  109. <TagSelect.Option value="cat5">类目五</TagSelect.Option>
  110. <TagSelect.Option value="cat6">类目六</TagSelect.Option>
  111. <TagSelect.Option value="cat7">类目七</TagSelect.Option>
  112. <TagSelect.Option value="cat8">类目八</TagSelect.Option>
  113. <TagSelect.Option value="cat9">类目九</TagSelect.Option>
  114. <TagSelect.Option value="cat10">类目十</TagSelect.Option>
  115. <TagSelect.Option value="cat11">类目十一</TagSelect.Option>
  116. <TagSelect.Option value="cat12">类目十二</TagSelect.Option>
  117. </TagSelect>
  118. )}
  119. </FormItem>
  120. </StandardFormRow>
  121. <StandardFormRow title="其它选项" grid last>
  122. <Row gutter={16}>
  123. <Col lg={8} md={10} sm={10} xs={24}>
  124. <FormItem {...formItemLayout} label="作者">
  125. {getFieldDecorator('author', {})(
  126. <Select
  127. onChange={this.handleFormSubmit}
  128. placeholder="不限"
  129. style={{ maxWidth: 200, width: '100%' }}
  130. >
  131. <Option value="lisa">王昭君</Option>
  132. </Select>
  133. )}
  134. </FormItem>
  135. </Col>
  136. <Col lg={8} md={10} sm={10} xs={24}>
  137. <FormItem {...formItemLayout} label="好评度">
  138. {getFieldDecorator('rate', {})(
  139. <Select
  140. onChange={this.handleFormSubmit}
  141. placeholder="不限"
  142. style={{ maxWidth: 200, width: '100%' }}
  143. >
  144. <Option value="good">优秀</Option>
  145. <Option value="normal">普通</Option>
  146. </Select>
  147. )}
  148. </FormItem>
  149. </Col>
  150. </Row>
  151. </StandardFormRow>
  152. </Form>
  153. </Card>
  154. <List
  155. rowKey="id"
  156. style={{ marginTop: 24 }}
  157. grid={{ gutter: 24, xl: 4, lg: 3, md: 3, sm: 2, xs: 1 }}
  158. loading={loading}
  159. dataSource={list}
  160. renderItem={item => (
  161. <List.Item key={item.id}>
  162. <Card
  163. hoverable
  164. bodyStyle={{ paddingBottom: 20 }}
  165. actions={[
  166. <Tooltip title="下载">
  167. <Icon type="download" />
  168. </Tooltip>,
  169. <Tooltip title="编辑">
  170. <Icon type="edit" />
  171. </Tooltip>,
  172. <Tooltip title="分享">
  173. <Icon type="share-alt" />
  174. </Tooltip>,
  175. <Dropdown overlay={itemMenu}>
  176. <Icon type="ellipsis" />
  177. </Dropdown>,
  178. ]}
  179. >
  180. <Card.Meta avatar={<Avatar size="small" src={item.avatar} />} title={item.title} />
  181. <div className={styles.cardItemContent}>
  182. <CardInfo
  183. activeUser={formatWan(item.activeUser)}
  184. newUser={numeral(item.newUser).format('0,0')}
  185. />
  186. </div>
  187. </Card>
  188. </List.Item>
  189. )}
  190. />
  191. </div>
  192. );
  193. }
  194. }