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

BasicList.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import React, { PureComponent } from 'react';
  2. import moment from 'moment';
  3. import { connect } from 'dva';
  4. import {
  5. List,
  6. Card,
  7. Row,
  8. Col,
  9. Radio,
  10. Input,
  11. Progress,
  12. Button,
  13. Icon,
  14. Dropdown,
  15. Menu,
  16. Avatar,
  17. } from 'antd';
  18. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  19. import styles from './BasicList.less';
  20. const RadioButton = Radio.Button;
  21. const RadioGroup = Radio.Group;
  22. const { Search } = Input;
  23. @connect(({ list, loading }) => ({
  24. list,
  25. loading: loading.models.list,
  26. }))
  27. export default class BasicList extends PureComponent {
  28. componentDidMount() {
  29. this.props.dispatch({
  30. type: 'list/fetch',
  31. payload: {
  32. count: 5,
  33. },
  34. });
  35. }
  36. render() {
  37. const { list: { list }, loading } = this.props;
  38. const Info = ({ title, value, bordered }) => (
  39. <div className={styles.headerInfo}>
  40. <span>{title}</span>
  41. <p>{value}</p>
  42. {bordered && <em />}
  43. </div>
  44. );
  45. const extraContent = (
  46. <div className={styles.extraContent}>
  47. <RadioGroup defaultValue="all">
  48. <RadioButton value="all">全部</RadioButton>
  49. <RadioButton value="progress">进行中</RadioButton>
  50. <RadioButton value="waiting">等待中</RadioButton>
  51. </RadioGroup>
  52. <Search className={styles.extraContentSearch} placeholder="请输入" onSearch={() => ({})} />
  53. </div>
  54. );
  55. const paginationProps = {
  56. showSizeChanger: true,
  57. showQuickJumper: true,
  58. pageSize: 5,
  59. total: 50,
  60. };
  61. const ListContent = ({ data: { owner, createdAt, percent, status } }) => (
  62. <div className={styles.listContent}>
  63. <div className={styles.listContentItem}>
  64. <span>Owner</span>
  65. <p>{owner}</p>
  66. </div>
  67. <div className={styles.listContentItem}>
  68. <span>开始时间</span>
  69. <p>{moment(createdAt).format('YYYY-MM-DD HH:mm')}</p>
  70. </div>
  71. <div className={styles.listContentItem}>
  72. <Progress percent={percent} status={status} strokeWidth={6} style={{ width: 180 }} />
  73. </div>
  74. </div>
  75. );
  76. const menu = (
  77. <Menu>
  78. <Menu.Item>
  79. <a>编辑</a>
  80. </Menu.Item>
  81. <Menu.Item>
  82. <a>删除</a>
  83. </Menu.Item>
  84. </Menu>
  85. );
  86. const MoreBtn = () => (
  87. <Dropdown overlay={menu}>
  88. <a>
  89. 更多 <Icon type="down" />
  90. </a>
  91. </Dropdown>
  92. );
  93. return (
  94. <PageHeaderLayout>
  95. <div className={styles.standardList}>
  96. <Card bordered={false}>
  97. <Row>
  98. <Col sm={8} xs={24}>
  99. <Info title="我的待办" value="8个任务" bordered />
  100. </Col>
  101. <Col sm={8} xs={24}>
  102. <Info title="本周任务平均处理时间" value="32分钟" bordered />
  103. </Col>
  104. <Col sm={8} xs={24}>
  105. <Info title="本周完成任务数" value="24个任务" />
  106. </Col>
  107. </Row>
  108. </Card>
  109. <Card
  110. className={styles.listCard}
  111. bordered={false}
  112. title="标准列表"
  113. style={{ marginTop: 24 }}
  114. bodyStyle={{ padding: '0 32px 40px 32px' }}
  115. extra={extraContent}
  116. >
  117. <Button type="dashed" style={{ width: '100%', marginBottom: 8 }} icon="plus">
  118. 添加
  119. </Button>
  120. <List
  121. size="large"
  122. rowKey="id"
  123. loading={loading}
  124. pagination={paginationProps}
  125. dataSource={list}
  126. renderItem={item => (
  127. <List.Item actions={[<a>编辑</a>, <MoreBtn />]}>
  128. <List.Item.Meta
  129. avatar={<Avatar src={item.logo} shape="square" size="large" />}
  130. title={<a href={item.href}>{item.title}</a>}
  131. description={item.subDescription}
  132. />
  133. <ListContent data={item} />
  134. </List.Item>
  135. )}
  136. />
  137. </Card>
  138. </div>
  139. </PageHeaderLayout>
  140. );
  141. }
  142. }