1
0

index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React from 'react';
  2. import './index.less';
  3. function Table(props) {
  4. const { columns = [], data = [] } = props;
  5. return (
  6. <div className="table">
  7. <div className="tr">
  8. {columns.map(column => {
  9. return (
  10. <div style={{ width: column.width, textAlign: column.align }} className={`th ${column.className || ''}`}>
  11. {column.title}
  12. </div>
  13. );
  14. })}
  15. </div>
  16. {data.length === 0 && <div className="empty">暂无数据</div>}
  17. {data.map(row => {
  18. return (
  19. <div className="tr">
  20. {columns.map(column => {
  21. return (
  22. <div
  23. style={{ width: column.width, textAlign: column.align }}
  24. className={`td ${column.className || ''}`}
  25. >
  26. {column.render ? column.render(row, row[column.key]) : row[column.key]}
  27. </div>
  28. );
  29. })}
  30. </div>
  31. );
  32. })}
  33. </div>
  34. );
  35. }
  36. Table.propTypes = {};
  37. export default Table;