* @version : HUOSDK 8.0 */ namespace huolib\tool; use think\Config; use think\Paginator; use think\Session; class Page { /** * 分页查询 * * @param array $list 列表数据 * @param int $count * @param int $page * @param int $offset * @param array $config 配置参数 * page:当前页, * path:url路径, * query:url额外参数, * fragment:url锚点, * var_page:分页变量, * list_rows:每页数量 * type:分页类名 * * @return \think\Paginator */ public static function paginate($count, $list, $page, $offset, $config = []) { $_simple = false; $_total = 0; if (is_int($count)) { $_total = $count; } $_offset = $offset; $_config = array_merge(Config::get('paginate'), $config); $_offset = $_offset ?: request()->param('list_rows/d', 0); if (empty($_offset)) { $_offset = Session::get('list_rows'); } else { Session::set('list_rows', $_offset); } $_offset = $_offset ?: $_config['list_rows']; /** @var Paginator $_class */ $_class = false !== strpos($_config['type'], '\\') ? $_config['type'] : '\\think\\paginator\\driver\\'.ucwords( $_config['type'] ); $_page = $page < 1 ? 1 : $page; $_config['path'] = isset($_config['path']) ? $_config['path'] : call_user_func([$_class, 'getCurrentPath']); return $_class::make($list, $_offset, $_page, $_total, $_simple, $_config); } }