From 837a178343cd5d46382d44a60dd2c5619f33d2d2 Mon Sep 17 00:00:00 2001 From: zwesy Date: Mon, 7 Dec 2020 09:52:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/provider.php | 5 + extend/tool/CustomPageHelper.php | 164 +++++++++++++++++++++++++++++++ public/static/css/style.css | 8 ++ 3 files changed, 177 insertions(+) create mode 100644 app/provider.php create mode 100644 extend/tool/CustomPageHelper.php diff --git a/app/provider.php b/app/provider.php new file mode 100644 index 0000000..f3f2856 --- /dev/null +++ b/app/provider.php @@ -0,0 +1,5 @@ + 'tool\CustomPageHelper' +]; \ No newline at end of file diff --git a/extend/tool/CustomPageHelper.php b/extend/tool/CustomPageHelper.php new file mode 100644 index 0000000..9d3b84e --- /dev/null +++ b/extend/tool/CustomPageHelper.php @@ -0,0 +1,164 @@ +currentPage() <= 1) { + return $this->getDisabledTextWrapper($str); + } + + $url = $this->url(1); + + return $this->getPageLinkWrapper($url, $str); + } + + // 上一页 + protected function getPreviousButton($text = "«") + { + + if ($this->currentPage() <= 1) { + return $this->getDisabledTextWrapper($text, 'prev'); + } + + $url = $this->url( + $this->currentPage() - 1 + ); + + return $this->getPageLinkWrapper($url, $text, 'prev'); + } + + // 页码 + protected function getLinks() + { + if ($this->total > $this->listRows) { + if ($this->lastPage < $this->btnNumber) { + return $this->getUrlLinks($this->getUrlRange(1, $this->lastPage), false); + } else { + $min = 1; + if ($this->currentPage > $this->btnNumber / 2) $min = $this->currentPage - floor($this->btnNumber / 2); + if ($this->lastPage - $this->currentPage < $this->btnNumber / 2) $min = $this->lastPage - $this->btnNumber + 1; + $max = $min + $this->btnNumber - 1; + $ellipsis = false; + if ($this->lastPage > $max) { + $ellipsis = true; + $max = $max - 1; + } + return $this->getUrlLinks($this->getUrlRange($min, $max), $ellipsis); + } + } + } + + // 下一页 + protected function getNextButton($text = '»') + { + if (!$this->hasMore) { + return $this->getDisabledTextWrapper($text, 'next'); + } + + $url = $this->url($this->currentPage() + 1); + + return $this->getPageLinkWrapper($url, $text, 'next'); + } + + // 末页 + protected function getLastButton($text = '') + { + if (!$this->hasMore) { + return $this->getDisabledTextWrapper($text); + } + + $url = $this->url($this->lastPage()); + + return $this->getPageLinkWrapper($url, $text); + } + + // 渲染分页 + public function render($type = '') + { + //数据是否足够分页 + if ($this->hasPages()) { + if(strtoupper($type) == 'A') { + return sprintf( + '', + $this->getFirstButton('首页'), + $this->getPreviousButton('上一页'), + $this->getLinks(), + $this->getNextButton('下一页') + ); + } elseif (strtoupper($type) == 'B') { + return sprintf( + '', + $this->getFirstButton('首页'), + $this->getPreviousButton('上一页'), + $this->getLinks(), + $this->getNextButton('下一页'), + $this->getLastButton('末页') + ); + } else { + return sprintf( + '', + $this->getPreviousButton('上一页'), + $this->getLinks(), + $this->getNextButton('下一页') + ); + } + } + } + + // 生成禁用按钮 + protected function getDisabledTextWrapper($text, $htmlClass = '') + { + return '
  • ' . $text . '
  • '; + } + + // 生成普通按钮 + protected function getPageLinkWrapper($url, $page, $htmlClass = '') + { + if ($page == $this->currentPage()) { + return $this->getActivePageWrapper($page, $htmlClass); + } + + return $this->getAvailablePageWrapper($url, $page, $htmlClass); + } + + // 生成当前页按钮 + protected function getActivePageWrapper($text, $htmlClass = '') + { + return '
  • ' . $text . '
  • '; + } + + // 可点击按钮 + protected function getAvailablePageWrapper($url, $page, $htmlClass = '') + { + return '
  • ' . $page . '
  • '; + } + + // 批量生成页码按钮 + protected function getUrlLinks(array $urls, bool $ellipsis, $htmlClass = '') + { + $html = ''; + + foreach ($urls as $page => $url) { + $html .= $this->getPageLinkWrapper($url, $page, $htmlClass); + } + if($ellipsis) { + $html .= $this->getDisabledTextWrapper('...', $htmlClass); + } + + return $html; + } + +} \ No newline at end of file diff --git a/public/static/css/style.css b/public/static/css/style.css index 1666915..8971989 100644 --- a/public/static/css/style.css +++ b/public/static/css/style.css @@ -346,6 +346,14 @@ input,select,textarea{outline:medium none; resize: none;} .product-box .center-block ul li a:hover span img{ transform: scale(1.1);} .pager{ margin: 3rem 0 0;} +.pageing{ display: flex; justify-content: center; flex-wrap: wrap;} +.pageing li{ display: inline-block;} +.pageing li a,.pageing li span{ display: block; min-width: 14px; border: 1px solid #d1d1d1; background: #fff; text-align: center; font-size: 14px; color: #565656; margin: 0 3px; transition: all 0.5s;} +.pageing li a:hover{ color: #0677ce;} +.pageing li.prev a:hover, .pageing li.next a:hover{ color: #fff; background: #999; border-color: #999;} +.pageing li.cur a,.pageing li.cur span{ background: #0677ce; border-color: #0677ce; color: #fff;} +.pageing li.cur a:hover{ color: #fff;} +.pageing li.disabled{ cursor: not-allowed;} .search-form-box .layui-form{ padding: 0 20%;} .search-form-box .layui-form .layui-input,.product-box .layui-form .layui-form-select{ width: 100%; margin: 0 15px;}