$html.='10 条/页 ';
$html.='20 条/页 ';
$html.='30 条/页 ';
$html.='50 条/页 ';
$html.=’ ';
$html.=’ 到第页 ';
$html.='确定 ';
$html.=’
’;return $html;
}
/**
-
页码按钮
-
@return string
*/
protected function getLinks()
{
$block = [
‘first’ => null,
‘slider’ => null,
‘last’ => null
];
$side = 3;
$window = $side * 2;
if ($this->lastPage < $window + 6) {
$block[
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
‘first’] = $this->getUrlRange(1, $this->lastPage);
} elseif ($this->currentPage <= $window) {
$block[‘first’] = $this->getUrlRange(1, $window + 2);
$block[‘last’] = t h i s − > g e t U r l R a n g e ( this->getUrlRange( this−>getUrlRange(this->lastPage - 1, $this->lastPage);
} elseif ( t h i s − > c u r r e n t P a g e > ( this->currentPage > ( this−>currentPage>(this->lastPage - $window)) {
$block[‘first’] = $this->getUrlRange(1, 2);
$block[‘last’] = t h i s − > g e t U r l R a n g e ( this->getUrlRange( this−>getUrlRange(this->lastPage - ($window + 2), $this->lastPage);
} else {
$block[‘first’] = $this->getUrlRange(1, 2);
$block[‘slider’] = t h i s − > g e t U r l R a n g e ( this->getUrlRange( this−>getUrlRange(this->currentPage - $side, $this->currentPage + $side);
$block[‘last’] = t h i s − > g e t U r l R a n g e ( this->getUrlRange( this−>getUrlRange(this->lastPage - 1, $this->lastPage);
}
$html = ‘’;
if (is_array($block[‘first’])) {
$html .= t h i s − > g e t U r l L i n k s ( this->getUrlLinks( this−>getUrlLinks(block[‘first’]);
}
if (is_array($block[‘slider’])) {
$html .= $this->getDots();
$html .= t h i s − > g e t U r l L i n k s ( this->getUrlLinks( this−>getUrlLinks(block[‘slider’]);
}
if (is_array($block[‘last’])) {
$html .= $this->getDots();
$html .= t h i s − > g e t U r l L i n k s ( this->getUrlLinks( this−>getUrlLinks(block[‘last’]);
}
return $html;
}
/**
-
渲染分页html
-
@return mixed
*/
public function render()
{
if ($this->hasPages()) {
if ($this->simple) {
return sprintf(
‘%s
$this->css(),
$this->prev(),
$this->getLinks(),
$this->next()
);
} else {
return sprintf(
‘%s
$this->css(),
$this->home(),
$this->prev(),
$this->getLinks(),
$this->next(),
$this->last(),
$this->info(),
$this->js()
);
}
}
}
/**
-
生成一个可点击的按钮
-
@param string $url
-
@param int $page
-
@return string
*/
protected function getAvailablePageWrapper($url, $page)
{
return ‘’ . $page . ‘’;
}
/**
-
生成一个禁用的按钮
-
@param string $text
-
@return string
*/
protected function getDisabledTextWrapper($text)
{
return ‘
’ . $text . ‘
’;}
/**
-
生成一个激活的按钮
-
@param string $text
-
@return string
*/
protected function getActivePageWrapper($text)
{
return ‘’ . $text . ‘’;
}
/**
-
生成省略号按钮
-
@return string
*/
protected function getDots()
{
return $this->getDisabledTextWrapper(’…’);
}
/**
-
批量生成页码按钮.
-
@param array $urls
-
@return string
*/
protected function getUrlLinks(array $urls)
{
$html = ‘’;
foreach ($urls as $page => $url) {
$html .= t h i s − > g e t P a g e L i n k W r a p p e r ( this->getPageLinkWrapper( this−>getPageLinkWrapper(url, $page);
}
return $html;
}
/**
-
生成普通页码按钮
-
@param string $url
-
@param int $page
-
@return string
*/
protected function getPageLinkWrapper($url, $page)
{
if ($page == $this->currentPage()) {
return t h i s − > g e t A c t i v e P a g e W r a p p e r ( this->getActivePageWrapper( this−>getActivePageWrapper(page);
}
return t h i s − > g e t A v a i l a b l e P a g e W r a p p e r ( this->getAvailablePageWrapper( this−>getAvailablePageWrapper(url, $page);
}
protected function js(){
return '
page.addEventListener(“change”, function() {
var _index = this.selectedIndex;
var size = this.options[_index].value;
var url="’.$this->url(1).’";
if(url.indexOf("&size") !=-1) {
var index=url.lastIndexOf("&size");
url=url.substring(0,index);
}
url+="&size="+size;
window.location.href=url});
function gotoPage(){
var input=document.getElementById(“pageInput”);
var url="’.$this->url(1).’";
if(url.indexOf("&page") !=-1) {
var index=url.lastIndexOf("&page");
url=url.substring(0,index);
}
url+="&page="+input.value;
window.location.href=url
}
';
}
/**
- 分页样式
*/
protected function css(){
return ’
.page-box,
.page-box * {
text-align:center;
box-sizing: content-box;
}
.pagination p{
margin:0;
cursor:pointer
}
.pagination{
height:40px;
padding:20px 0px;
}
.pagination a{
display:block;
float:left;
margin-right:10px;
padding:2px 12px;
height:24px;
border:1px #cccccc solid;
background:#fff;
text-decoration:none;
color:#808080;
font-size:12px;
line-height:24px;
}
.pagination a:hover{
color:#077ee3;
background: white;
border:1px #077ee3 solid;
}
.pagination a.cur{
border:none;
background:#077ee3;
color:#fff;
}
.pagination p{
float:left;
padding:2px 12px;
font-size:12px;
height:24px;
line-height:24px;
color:#bbb;
margin-right:8px;
}
.pagination p.disabled{
border:1px #ccc solid;
background:#fcfcfc;
cursor:not-allowed;
}
.pagination p.pageRemark{
display:block;
margin-right:10px;
font-size:14px;
padding:4px 0px;
color:#666;
}
/屏幕宽度小于992px时/
@media all and (max-width: 992px) {
.pagination p.pageRemark{
display: none;
}
}
.pagination p.pageRemark b{
color:red;
}
.pagination p select{
font-size:12px;
margin: 0 5px;
padding: 0 10px;
text-align: center;
height: 28px;
line-height: 28px;
border: 1px solid #e2e2e2;
border-radius: 2px;
vertical-align: top;
background-color: #fff;
box-sizing: border-box;
}
.pagination p.pageEllipsis{
border-style:none;
background:none;
padding:4px 0px;
color:#808080;
cursor: not-allowed;
}
.dates li {font-size: 14px;margin:20px 0}
.dates li span{float:right}
.page-input{
display: inline-block;
width: 40px;
margin: 0 5px;
padding: 0 5px;
text-align: center;
height: 28px;
line-height: 28px;
border: 1px solid #e2e2e2;
border-radius: 2px;
vertical-align: top;
background-color: #fff;
box-sizing: border-box;
}
.page-btn{
font-size:12px;
margin: 0 5px;
padding: 0 10px;
text-align: center;
height: 28px;
line-height: 28px;
border: 1px solid #e2e2e2;
border-radius: 2px;
vertical-align: top;
background-color: #fff;
box-sizing: border-box;
}
.page-btn:hover{
color:#077ee3;
background: white;
border:1px #077ee3 solid;
}
';
}
}