mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
修正分页类简洁模式
This commit is contained in:
@@ -53,12 +53,13 @@ abstract class Paginator
|
|||||||
$this->simple = $simple;
|
$this->simple = $simple;
|
||||||
$this->listRows = $listRows;
|
$this->listRows = $listRows;
|
||||||
|
|
||||||
$this->items = PaginatorCollection::make($items, $this);
|
|
||||||
|
|
||||||
if ($simple) {
|
if ($simple) {
|
||||||
|
if (!$items instanceof Collection) {
|
||||||
|
$items = Collection::make($items);
|
||||||
|
}
|
||||||
$this->currentPage = $this->setCurrentPage($currentPage);
|
$this->currentPage = $this->setCurrentPage($currentPage);
|
||||||
$this->hasMore = count($this->items) > ($this->listRows);
|
$this->hasMore = count($items) > ($this->listRows);
|
||||||
$this->items = $this->items->slice(0, $this->listRows);
|
$items = $items->slice(0, $this->listRows);
|
||||||
} else {
|
} else {
|
||||||
$this->total = $total;
|
$this->total = $total;
|
||||||
$this->lastPage = (int)ceil($total / $listRows);
|
$this->lastPage = (int)ceil($total / $listRows);
|
||||||
@@ -66,6 +67,7 @@ abstract class Paginator
|
|||||||
$this->hasMore = $this->currentPage < $this->lastPage;
|
$this->hasMore = $this->currentPage < $this->lastPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->items = PaginatorCollection::make($items, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function items()
|
public function items()
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ class Collection extends \think\Collection
|
|||||||
|
|
||||||
public function __construct($items = [], Paginator $paginator = null)
|
public function __construct($items = [], Paginator $paginator = null)
|
||||||
{
|
{
|
||||||
if (!$paginator instanceof Paginator) {
|
|
||||||
throw new \RuntimeException('Paginator Required!');
|
|
||||||
}
|
|
||||||
$this->paginator = $paginator;
|
$this->paginator = $paginator;
|
||||||
parent::__construct($items);
|
parent::__construct($items);
|
||||||
}
|
}
|
||||||
@@ -44,9 +41,19 @@ class Collection extends \think\Collection
|
|||||||
return new static($items, $paginator);
|
return new static($items, $paginator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPaginator(Paginator $paginator)
|
||||||
|
{
|
||||||
|
$this->paginator = $paginator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPaginator()
|
||||||
|
{
|
||||||
|
return $this->paginator;
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
|
if ($this->paginator) {
|
||||||
try {
|
try {
|
||||||
$total = $this->total();
|
$total = $this->total();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -59,11 +66,14 @@ class Collection extends \think\Collection
|
|||||||
'current_page' => $this->currentPage(),
|
'current_page' => $this->currentPage(),
|
||||||
'data' => parent::toArray()
|
'data' => parent::toArray()
|
||||||
];
|
];
|
||||||
|
} else {
|
||||||
|
return parent::toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __call($method, $args)
|
public function __call($method, $args)
|
||||||
{
|
{
|
||||||
if (method_exists($this->paginator, $method)) {
|
if ($this->paginator && method_exists($this->paginator, $method)) {
|
||||||
return call_user_func_array([$this->paginator, $method], $args);
|
return call_user_func_array([$this->paginator, $method], $args);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception(__CLASS__ . ':' . $method . ' method not exist');
|
throw new Exception(__CLASS__ . ':' . $method . ' method not exist');
|
||||||
|
|||||||
Reference in New Issue
Block a user