table.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React 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 { Modal, Table, Popconfirm, Menu, Icon } from 'antd';
  7. import AnimTableBody from '../../components/Animation/AnimTableBody';
  8. import styles from './table.less';
  9. const confirm = Modal.confirm;
  10. const TableList = ({ onDeleteItem, onEditItem, location, pagination, ...tableProps }) => {
  11. // 从url中提取查询参数
  12. location.query = queryString.parse(location.search);
  13. const handleDeleteItem = (record) => {
  14. confirm({
  15. title: `您确定要${record.status === 'NORMAL' ? '禁用' : '解禁'}该终端账号?`,
  16. onOk () {
  17. onDeleteItem(record.id);
  18. },
  19. })
  20. }
  21. const columns = [{
  22. title: '终端编号',
  23. dataIndex: 'code',
  24. key: 'code',
  25. },{
  26. title: '终端名称',
  27. dataIndex: 'name',
  28. key: 'name',
  29. },{
  30. title: '校区',
  31. dataIndex: 'campusName',
  32. key: 'campusName',
  33. },{
  34. title: '添加时间',
  35. dataIndex: 'gmtCreated',
  36. key: 'gmtCreated',
  37. render: (text, record) => (
  38. <div>{moment(text).format('YYYY-MM-DD')}</div>
  39. )
  40. },{
  41. title: '操作',
  42. dataIndex: 'operation',
  43. key: 'operation',
  44. render: (text, record) => (
  45. <div>
  46. <a onClick={() => onEditItem(record)}>编辑</a>
  47. <span className={styles.splitLine} />
  48. <a onClick={() => handleDeleteItem(record)}>{record.status === 'NORMAL' ? '禁用' : '解禁'}</a>
  49. </div>
  50. )
  51. }];
  52. tableProps.pagination = !!pagination && { ...pagination, showSizeChanger: true, showQuickJumper: true, showTotal: total => `共 ${total} 条`};
  53. const getBodyWrapperProps = {
  54. page: location.query.page,
  55. current: tableProps.pagination.current,
  56. };
  57. const getBodyWrapper = (body) => (<AnimTableBody {...getBodyWrapperProps} body={body} />);
  58. return (
  59. <Table
  60. simple
  61. bordered
  62. { ...tableProps }
  63. columns={columns}
  64. className={classnames({ [styles.table]: true, [styles.motion]: true })}
  65. rowKey={record => record.id}
  66. getBodyWrapper={getBodyWrapper}
  67. />
  68. );
  69. }
  70. TableList.propTypes = {
  71. location: PropTypes.object,
  72. onChange: PropTypes.func.isRequired,
  73. onDeleteItem: PropTypes.func.isRequired,
  74. onEditItem: PropTypes.func.isRequired,
  75. }
  76. export default TableList;