This commit is contained in:
2020-09-14 10:43:02 +08:00
parent 4c2d16220b
commit 43eff7cb68
2 changed files with 8 additions and 10 deletions
+4 -6
View File
@@ -172,20 +172,18 @@ class ActiveQuery extends Component
/** /**
* @param int $size * @param int $size
* @param callable $callback
* @param mixed $param
* @param int $offset * @param int $offset
* @param int $total * @param callable $callback
* @return Pagination
* @throws Exception * @throws Exception
*/ */
public function plunk(int $size, callable $callback, $param = null, $offset = 0, $total = -1) public function plunk(int $size, int $offset, callable $callback)
{ {
$pagination = new Pagination($this); $pagination = new Pagination($this);
$pagination->setOffset($offset); $pagination->setOffset($offset);
$pagination->setLimit($size); $pagination->setLimit($size);
$pagination->setMax($total);
$pagination->setCallback($callback); $pagination->setCallback($callback);
$pagination->search($param); return $pagination;
} }
/** /**
+4 -4
View File
@@ -99,12 +99,12 @@ class Pagination extends Component
/** /**
* @param array $param * @param array $param
*/ */
public function search($param = []) public function plunk($param = [])
{ {
if ($this->_length >= $this->_max) { if ($this->_length >= $this->_max) {
return; return;
} }
[$length, $data] = $this->load(); [$length, $data] = $this->get();
if ($param !== null) { if ($param !== null) {
call_user_func($this->_callback, $data, $param); call_user_func($this->_callback, $data, $param);
} else { } else {
@@ -114,14 +114,14 @@ class Pagination extends Component
if ($length < $this->_limit) { if ($length < $this->_limit) {
return; return;
} }
$this->search($param); $this->plunk($param);
} }
/** /**
* @return array|Collection * @return array|Collection
*/ */
private function load() private function get()
{ {
if ($this->_length + $this->_limit > $this->_max) { if ($this->_length + $this->_limit > $this->_max) {
$this->_limit = $this->_length + $this->_limit - $this->_max; $this->_limit = $this->_length + $this->_limit - $this->_max;