index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import Icon from '../Icon';
  4. import Select from '../Select';
  5. export default class extends Component {
  6. onChangePage(page) {
  7. const { total, pageSize, onChange } = this.props;
  8. const all = Math.ceil(total / pageSize);
  9. if (page <= 0 || page > all) return;
  10. if (onChange) onChange(page);
  11. }
  12. render() {
  13. const { current, total, pageSize, jump } = this.props;
  14. const all = Math.ceil(total / pageSize);
  15. return (
  16. <div className="user-pagination">
  17. <Icon name="arrow-left-small" onClick={() => this.onChangePage(current - 1)} />
  18. <span>
  19. <b>{current}</b>/{all}
  20. </span>
  21. <Icon name="arrow-right-small" onClick={() => this.onChangePage(current + 1)} />
  22. {jump && (
  23. <div style={{ display: 'inline-block' }} className="m-l-2 v-a-m">
  24. <div style={{ display: 'inline-block' }} className="v-a-m">
  25. 跳转至
  26. </div>
  27. <Select
  28. size="small"
  29. theme="white"
  30. value={current}
  31. list={all > 0 ? [...Array(all)].map((key, index) => ({ title: `第${index + 1}页`, key: index + 1 })) : []}
  32. onChange={({ key }) => this.onChangePage(key)}
  33. />
  34. </div>
  35. )}
  36. </div>
  37. );
  38. }
  39. }