Page.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Page.php UTF-8
  4. * 页面处理
  5. *
  6. * @date : 2018/5/21 20:08
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huolib\tool;
  13. use think\Config;
  14. use think\Paginator;
  15. use think\Session;
  16. class Page {
  17. /**
  18. * 分页查询
  19. *
  20. * @param array $list 列表数据
  21. * @param int $count
  22. * @param int $page
  23. * @param int $offset
  24. * @param array $config 配置参数
  25. * page:当前页,
  26. * path:url路径,
  27. * query:url额外参数,
  28. * fragment:url锚点,
  29. * var_page:分页变量,
  30. * list_rows:每页数量
  31. * type:分页类名
  32. *
  33. * @return \think\Paginator
  34. */
  35. public static function paginate($count, $list, $page, $offset, $config = []) {
  36. $_simple = false;
  37. $_total = 0;
  38. if (is_int($count)) {
  39. $_total = $count;
  40. }
  41. $_offset = $offset;
  42. $_config = array_merge(Config::get('paginate'), $config);
  43. $_offset = $_offset ?: request()->param('list_rows/d', 0);
  44. if (empty($_offset)) {
  45. $_offset = Session::get('list_rows');
  46. } else {
  47. Session::set('list_rows', $_offset);
  48. }
  49. $_offset = $_offset ?: $_config['list_rows'];
  50. /** @var Paginator $_class */
  51. $_class = false !== strpos($_config['type'], '\\')
  52. ? $_config['type']
  53. : '\\think\\paginator\\driver\\'.ucwords(
  54. $_config['type']
  55. );
  56. $_page = $page < 1 ? 1 : $page;
  57. $_config['path'] = isset($_config['path']) ? $_config['path'] : call_user_func([$_class, 'getCurrentPath']);
  58. return $_class::make($list, $_offset, $_page, $_total, $_simple, $_config);
  59. }
  60. }