-
Notifications
You must be signed in to change notification settings - Fork 0
/
PaginatorLayui.php
97 lines (85 loc) · 2.15 KB
/
PaginatorLayui.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace tt;
use think\facade\Request;
use think\paginator\driver\Bootstrap;
class PaginatorLayui extends Bootstrap
{
/**
* 渲染分页html
* @return mixed
*/
public function render()
{
if ($this->hasPages()) {
if ($this->simple) {
return sprintf(
'<div class="layui-box layui-laypage layui-laypage-default">%s %s</div>',
$this->getPreviousButton('上一页'),
$this->getNextButton('下一页')
);
} else {
return sprintf(
'<div class="layui-box layui-laypage layui-laypage-default">%s %s %s</div>',
$this->getPreviousButton('上一页'),
$this->getLinks(),
$this->getNextButton('下一页')
);
}
}
}
/**
* 生成一个可点击的按钮
*
* @param string $url
* @param string $page
* @return string
*/
protected function getAvailablePageWrapper(string $url, string $page): string
{
return <<<EOT
<a href="$url">$page</a>
EOT;
}
/**
* 生成一个禁用的按钮
*
* @param string $text
* @return string
*/
protected function getDisabledTextWrapper(string $text): string
{
return <<<EOT
<span class="layui-laypage-spr">$text</span>
EOT;
}
/**
* 生成一个激活的按钮
*
* @param string $text
* @return string
*/
protected function getActivePageWrapper(string $text): string
{
return <<<EOT
<span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em>$text</em></span>
EOT;
}
/**
* 获取页码对应的链接
*
* @access protected
* @param int $page
* @return string
*/
protected function url(int $page): string
{
if ($page <= 0) {
$page = 1;
}
$get = Request::get();
unset($get['page']); // 为了把page参数放最后
$get['page'] = $page;
$url = Request::baseUrl().'?'.http_build_query($get);
return $url;
}
}