index.js 991 Bytes
Newer Older
1 2
import React, { useContext } from 'react';
import classNames from 'classnames';
涂茜's avatar
涂茜 committed
3
import PropTypes from 'prop-types';
4 5 6 7 8 9
import { Table, ConfigProvider } from 'antd';
import './index.less';

const BasicTable = (props) => {
  const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
  const prefixCls = getPrefixCls('basic-table');
李纪文's avatar
李纪文 committed
10
  const pagination = typeof props.pagination !== 'undefined' ? props.pagination : {};
11 12 13 14 15 16 17 18 19 20
  const showTotal = (total) => {
    return `共 ${Math.ceil(
      total / (props.pagination ? props.pagination.pageSize || 10 : 10),
    )} 页 / 共 ${total} 条记录`;
  };
  return (
    <Table
      className={classNames(prefixCls)}
      scroll={{ y: 'calc(100% - 40px)' }}
      {...props}
李纪文's avatar
李纪文 committed
21
      pagination={pagination ? { showTotal, ...pagination } : pagination}
22 23
    />
  );
24 25 26 27 28 29 30 31 32 33 34 35 36
};

BasicTable.defaultProps = {
  columns: [],
  dataSource: [],
};

BasicTable.propTypes = {
  columns: PropTypes.array,
  dataSource: PropTypes.array,
};

export default BasicTable;