Page.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace WY\app\libs;
  3. if (!defined('WY_ROOT')) {
  4. exit;
  5. }
  6. class Page
  7. {
  8. public $page = 1;
  9. public $pagesize = 0;
  10. public $totalsize = 0;
  11. public $buchang = 3;
  12. public $pagelimit = 6;
  13. public $pageinfo = '条';
  14. public $url = '/';
  15. function put($data)
  16. {
  17. if (!$data) {
  18. return false;
  19. }
  20. foreach ($data as $key => $val) {
  21. $this->{$key} = $val;
  22. }
  23. $totalpage = ceil($this->totalsize / $this->pagesize);
  24. $totalpage = $totalpage ? $totalpage : 1;
  25. $this->page = $this->page > $totalpage ? $totalpage : $this->page;
  26. $nextpage = $this->page - 1;
  27. $prev = $this->page > 1 ? '<li class="pagination__item"><a class="pagination__number" href="' . $this->url . $nextpage . '">上页</a></li>' : '';
  28. $nextpage = $this->page + 1;
  29. $next = $this->page < $totalpage ? '<li class="pagination__item"><a class="pagination__number" href="' . $this->url . $nextpage . '">下页</a></li>' : '';
  30. if ($totalpage <= $this->pagelimit) {
  31. $list = '';
  32. for ($i = 1; $i <= $totalpage; $i++) {
  33. $current = $this->page == $i ? ' class="wy_page_current1" ' : '';
  34. $list .= '<li class="pagination__item"><a href="' . $this->url . $i . '"' . $current . '>第' . $i . '页</a></li>';
  35. }
  36. $list = $prev . $list . $next;
  37. }
  38. if ($totalpage > $this->pagelimit) {
  39. $list = '';
  40. $i = 1;
  41. $plimit = 6;
  42. $firstpage = '';
  43. if ($this->page > $this->buchang) {
  44. $i = $this->page - $this->buchang + 1;
  45. $plimit = $this->page + $this->buchang;
  46. $firstpage = '<li class="pagination__item"><a class="pagination__number" href="' . $this->url . '1">1</a></li><li class="pagination__item"><a class="pagination__number">...</a></li>';
  47. }
  48. $lastpage = '<li class="pagination__item"><a class="pagination__number">...</a></li><li class="pagination__item"><a class="pagination__number" href="' . $this->url . $totalpage . '">' . $totalpage . '</a></li>';
  49. if ($totalpage - $this->page < $this->buchang) {
  50. $plimit = $totalpage + 1;
  51. $lastpage = '';
  52. }
  53. for ($i; $i < $plimit; $i++) {
  54. $current = $this->page == $i ? ' class="wy_page_current1" ' : '';
  55. $list .= '<li class="pagination__item"><a href="' . $this->url . $i . '"' . $current . '>' . $i . '</li>';
  56. }
  57. $list = $prev . $firstpage . $list . $lastpage . $next;
  58. }
  59. $css = '<style>.pagination__item a.wy_page_current1{background-color: #eee;border: 1px solid #ddd;}</style>';
  60. return $css . '<div class="demo"><ul class="pagination pagination_type1 pagination_type5"><li class="pagination__item"><a class="pagination__number">记录' . $this->totalsize . $this->pageinfo . '</a></li>' . $list . '</ul></div>';
  61. }
  62. }
  63. ?>