table.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import React, { PureComponent } from 'react';
  2. import moment from 'moment';
  3. import queryString from 'query-string';
  4. import { Divider, Modal, Table, Icon, Badge } from 'antd';
  5. import { statuses, Codes } from '../../../utils/config';
  6. export default class TableList extends PureComponent {
  7. handleDeleteItem = (record) => {
  8. const { onDeleteItem } = this.props;
  9. Modal.confirm({
  10. title: `您确定要删除该课程?`,
  11. okText: '确定',
  12. cancelText: '取消',
  13. onOk: () => onDeleteItem({ id: record.id }),
  14. });
  15. }
  16. render() {
  17. const { onDeleteItem, onEditItem, pagination, ...tableProps } = this.props;
  18. const columns = [{
  19. title: '课程编号',
  20. dataIndex: 'code',
  21. key: 'code',
  22. width: '20%',
  23. },{
  24. title: '课程名称',
  25. dataIndex: 'name',
  26. key: 'name',
  27. width: '36%',
  28. },{
  29. title: '状态',
  30. dataIndex: 'status',
  31. key: 'status',
  32. render: (text, record) => {
  33. const statusMap = {[Codes.CODE_NORMAL]: 'success', [Codes.CODE_DELETE]: 'error'};
  34. return (<Badge status={statusMap[record.status]} text={statuses[record.status]} />);
  35. },
  36. width: '12%',
  37. },{
  38. title: '修改时间',
  39. dataIndex: 'gmtModified',
  40. key: 'gmtModified',
  41. render: (text, record) => (
  42. <div>{moment(text).format('YYYY-MM-DD HH:mm:ss')}</div>
  43. ),
  44. width: '20%',
  45. },{
  46. title: '操作',
  47. dataIndex: 'operation',
  48. key: 'operation',
  49. render: (text, record) => (
  50. <div>
  51. <a onClick={() => onEditItem(record)}>编辑</a>
  52. <Divider type="vertical" />
  53. <a onClick={() => this.handleDeleteItem(record)}>删除</a>
  54. </div>
  55. ),
  56. width: '12%',
  57. }];
  58. // 配置分页
  59. tableProps.pagination = !!pagination && { ...pagination, showSizeChanger: true, showQuickJumper: true, showTotal: total => `共 ${total} 条`};
  60. return (
  61. <Table
  62. simple
  63. bordered
  64. { ...tableProps }
  65. columns={columns}
  66. rowKey={record => record.id}
  67. />
  68. );
  69. }
  70. }