table.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React, { PureComponent } from 'react';
  2. import PropTypes from 'prop-types';
  3. import moment from 'moment';
  4. import classnames from 'classnames';
  5. import queryString from 'query-string';
  6. import { Popover, Modal, Table, Menu, Icon, Badge } from 'antd';
  7. import AnimTableBody from '../../../components/Animation/AnimTableBody';
  8. import { statuses, Codes } from '../../../utils/config'
  9. import styles from './table.less';
  10. const confirm = Modal.confirm;
  11. export default class TableList extends PureComponent {
  12. static propTypes = {
  13. location: PropTypes.object,
  14. onChange: PropTypes.func.isRequired,
  15. onDeleteItem: PropTypes.func.isRequired,
  16. onPlayVideo: PropTypes.func.isRequired,
  17. };
  18. handleDeleteItem = (record) => {
  19. const { onDeleteItem } = this.props;
  20. confirm({
  21. title: `您确定要${record.status === Codes.CODE_NORMAL ? '删除' : '恢复'}该视频?`,
  22. onOk () {
  23. onDeleteItem(record.id);
  24. },
  25. })
  26. }
  27. render() {
  28. const { curStatus, onPlayVideo, location, pagination, ...tableProps } = this.props;
  29. const columns = [{
  30. title: '视频编号',
  31. dataIndex: 'code',
  32. key: 'code',
  33. },{
  34. title: '视频名称',
  35. dataIndex: 'name',
  36. key: 'name',
  37. },{
  38. title: '视频大小(B)',
  39. dataIndex: 'size',
  40. key: 'size',
  41. },{
  42. title: '状态',
  43. dataIndex: 'status',
  44. key: 'status',
  45. render: (text, record) => {
  46. const statusMap = {[Codes.CODE_NORMAL]: 'success', [Codes.CODE_DELETE]: 'error'};
  47. return (<Badge status={statusMap[record.status]} text={statuses[record.status]} />);
  48. },
  49. filters: Object.keys(statuses).map(key => ({ text: statuses[key], value: key })),
  50. filterMultiple: false,
  51. filteredValue: [curStatus],
  52. },{
  53. title: '添加时间',
  54. dataIndex: 'gmtCreated',
  55. key: 'gmtCreated',
  56. render: (text, record) => (
  57. <div>{moment(text).format('YYYY-MM-DD')}</div>
  58. )
  59. },{
  60. title: '操作',
  61. dataIndex: 'operation',
  62. key: 'operation',
  63. render: (text, record) => (
  64. <div>
  65. <a onClick={() => onPlayVideo(record)}>播放</a>
  66. <span className={styles.splitLine} />
  67. <a onClick={() => this.handleDeleteItem(record)}>{record.status === Codes.CODE_NORMAL ? '删除' : '恢复'}</a>
  68. </div>
  69. )
  70. }];
  71. // 数据table列表表头的筛选按钮点击重置后status值为空,此时删除该参数
  72. columns.map(item => {
  73. item.dataIndex === 'status' && !curStatus ? delete item.filteredValue : null;
  74. });
  75. tableProps.pagination = !!pagination && { ...pagination, showSizeChanger: true, showQuickJumper: true, showTotal: total => `共 ${total} 条`};
  76. const getBodyWrapperProps = {
  77. page: location.query.page,
  78. current: tableProps.pagination.current,
  79. };
  80. const getBodyWrapper = (body) => (<AnimTableBody {...getBodyWrapperProps} body={body} />);
  81. return (
  82. <Table
  83. simple
  84. bordered
  85. { ...tableProps }
  86. columns={columns}
  87. className={classnames({ [styles.table]: true, [styles.motion]: true })}
  88. rowKey={record => record.id}
  89. getBodyWrapper={getBodyWrapper}
  90. />
  91. );
  92. }
  93. }