作者 董瑞恩
1 个管道 的构建 通过 耗费 0 秒

order

@@ -221,7 +221,7 @@ $configs = [ @@ -221,7 +221,7 @@ $configs = [
221 ], 221 ],
222 //分页配置 222 //分页配置
223 'paginate' => [ 223 'paginate' => [
224 - 'type' => '\cmf\paginator\Bootstrap', 224 + 'type' => 'page\Page',
225 'var_page' => 'page', 225 'var_page' => 'page',
226 'list_rows' => 15, 226 'list_rows' => 15,
227 ], 227 ],
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: ruidiudiu
  5 + * Date: 2018/8/13
  6 + * Time: 11:41
  7 + */
  8 +namespace page;
  9 +
  10 +use think\Paginator;
  11 +
  12 +class Page extends Paginator
  13 +{
  14 + protected function home() {
  15 + if ($this->currentPage() > 1) {
  16 + return "<a href='" . $this->url(1) . "' title='首页'>首页</a>";
  17 + } else {
  18 + return "<p>首页</p>";
  19 + }
  20 + }
  21 + //上一页
  22 + protected function prev() {
  23 + if ($this->currentPage() > 1) {
  24 + return "<a href='" . $this->url($this->currentPage - 1) . "' title='上一页'>上一页</a>";
  25 + } else {
  26 + return "<p>上一页</p>";
  27 + }
  28 + }
  29 + //下一页
  30 + protected function next() {
  31 + if ($this->hasMore) {
  32 + return "<a href='" . $this->url($this->currentPage + 1) . "' title='下一页'>下一页</a>";
  33 + } else {
  34 + return"<p>下一页</p>";
  35 + }
  36 + }
  37 + //尾页
  38 + protected function last() {
  39 + if ($this->hasMore) {
  40 + return "<a href='" . $this->url($this->lastPage) . "' title='尾页'>尾页</a>";
  41 + } else {
  42 + return "<p>尾页</p>";
  43 + }
  44 + }
  45 + //统计信息
  46 + protected function info(){
  47 + return "<p class='pageRemark'>共<b>" . $this->lastPage .
  48 + "</b>页<b>" . $this->total . "</b>条数据</p>";
  49 + }
  50 + /**
  51 + * 页码按钮
  52 + * @return string
  53 + */
  54 + protected function getLinks()
  55 + {
  56 + $block = [
  57 + 'first' => null,
  58 + 'slider' => null,
  59 + 'last' => null
  60 + ];
  61 + $side = 3;
  62 + $window = $side * 2;
  63 + if ($this->lastPage < $window + 6) {
  64 + $block['first'] = $this->getUrlRange(1, $this->lastPage);
  65 + } elseif ($this->currentPage <= $window) {
  66 + $block['first'] = $this->getUrlRange(1, $window + 2);
  67 + $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage);
  68 + } elseif ($this->currentPage > ($this->lastPage - $window)) {
  69 + $block['first'] = $this->getUrlRange(1, 2);
  70 + $block['last'] = $this->getUrlRange($this->lastPage - ($window + 2), $this->lastPage);
  71 + } else {
  72 + $block['first'] = $this->getUrlRange(1, 2);
  73 + $block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);
  74 + $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage);
  75 + }
  76 + $html = '';
  77 + if (is_array($block['first'])) {
  78 + $html .= $this->getUrlLinks($block['first']);
  79 + }
  80 + if (is_array($block['slider'])) {
  81 + $html .= $this->getDots();
  82 + $html .= $this->getUrlLinks($block['slider']);
  83 + }
  84 + if (is_array($block['last'])) {
  85 + $html .= $this->getDots();
  86 + $html .= $this->getUrlLinks($block['last']);
  87 + }
  88 + return $html;
  89 + }
  90 + /**
  91 + * 渲染分页html
  92 + * @return mixed
  93 + */
  94 + public function render()
  95 + {
  96 + if ($this->hasPages()) {
  97 + if ($this->simple) {
  98 + return sprintf(
  99 + '%s<div class="pagination">%s %s %s</div>',
  100 + $this->css(),
  101 + $this->prev(),
  102 + $this->getLinks(),
  103 + $this->next()
  104 + );
  105 + } else {
  106 + return sprintf(
  107 + '%s<div class="pagination">%s %s %s %s %s %s</div>',
  108 + $this->css(),
  109 + $this->home(),
  110 + $this->prev(),
  111 + $this->getLinks(),
  112 + $this->next(),
  113 + $this->last(),
  114 + $this->info()
  115 + );
  116 + }
  117 + }
  118 + }
  119 + /**
  120 + * 生成一个可点击的按钮
  121 + *
  122 + * @param string $url
  123 + * @param int $page
  124 + * @return string
  125 + */
  126 + protected function getAvailablePageWrapper($url, $page)
  127 + {
  128 + return '<a href="' . htmlentities($url) . '" title="第"'. $page .'"页" >' . $page . '</a>';
  129 + }
  130 + /**
  131 + * 生成一个禁用的按钮
  132 + *
  133 + * @param string $text
  134 + * @return string
  135 + */
  136 + protected function getDisabledTextWrapper($text)
  137 + {
  138 + return '<p class="pageEllipsis">' . $text . '</p>';
  139 + }
  140 + /**
  141 + * 生成一个激活的按钮
  142 + *
  143 + * @param string $text
  144 + * @return string
  145 + */
  146 + protected function getActivePageWrapper($text)
  147 + {
  148 + return '<a href="" class="cur">' . $text . '</a>';
  149 + }
  150 + /**
  151 + * 生成省略号按钮
  152 + *
  153 + * @return string
  154 + */
  155 + protected function getDots()
  156 + {
  157 + return $this->getDisabledTextWrapper('...');
  158 + }
  159 + /**
  160 + * 批量生成页码按钮.
  161 + *
  162 + * @param array $urls
  163 + * @return string
  164 + */
  165 + protected function getUrlLinks(array $urls)
  166 + {
  167 + $html = '';
  168 + foreach ($urls as $page => $url) {
  169 + $html .= $this->getPageLinkWrapper($url, $page);
  170 + }
  171 + return $html;
  172 + }
  173 + /**
  174 + * 生成普通页码按钮
  175 + *
  176 + * @param string $url
  177 + * @param int $page
  178 + * @return string
  179 + */
  180 + protected function getPageLinkWrapper($url, $page)
  181 + {
  182 + if ($page == $this->currentPage()) {
  183 + return $this->getActivePageWrapper($page);
  184 + }
  185 + return $this->getAvailablePageWrapper($url, $page);
  186 + }
  187 + /**
  188 + * 分页样式
  189 + */
  190 + protected function css(){
  191 + return ' <style type="text/css">
  192 + .pagination p{
  193 + margin:0;
  194 + cursor:pointer
  195 + }
  196 + .pagination{
  197 + height:40px;
  198 + padding:20px 0px;
  199 + }
  200 + .pagination a{
  201 + display:block;
  202 + float:left;
  203 + margin-right:10px;
  204 + padding:2px 12px;
  205 + height:24px;
  206 + border:1px #cccccc solid;
  207 + background:#fff;
  208 + text-decoration:none;
  209 + color:#808080;
  210 + font-size:12px;
  211 + line-height:24px;
  212 + }
  213 + .pagination a:hover{
  214 + color:#077ee3;
  215 + background: white;
  216 + border:1px #077ee3 solid;
  217 + }
  218 + .pagination a.cur{
  219 + border:none;
  220 + background:#077ee3;
  221 + color:#fff;
  222 + }
  223 + .pagination p{
  224 + float:left;
  225 + padding:2px 12px;
  226 + font-size:12px;
  227 + height:24px;
  228 + line-height:24px;
  229 + color:#bbb;
  230 + border:1px #ccc solid;
  231 + background:#fcfcfc;
  232 + margin-right:8px;
  233 + }
  234 + .pagination p.pageRemark{
  235 + border-style:none;
  236 + background:none;
  237 + margin-right:0px;
  238 + padding:4px 0px;
  239 + color:#666;
  240 + }
  241 + .pagination p.pageRemark b{
  242 + color:red;
  243 + }
  244 + .pagination p.pageEllipsis{
  245 + border-style:none;
  246 + background:none;
  247 + padding:4px 0px;
  248 + color:#808080;
  249 + }
  250 + .dates li {font-size: 14px;margin:20px 0}
  251 + .dates li span{float:right}
  252 + </style>';
  253 + }
  254 +}