70 lines
1.8 KiB
PHP
Executable File
70 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\TomTool;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Slim\Http\Response;
|
|
use Slim\Http\ServerRequest;
|
|
use Smarty\Exception as SmartyException;
|
|
|
|
final class PageBar
|
|
{
|
|
|
|
public static function create($iMaxLen, $iPageTotal, $iPageNow): array
|
|
{
|
|
$iPageBarLenth = $iMaxLen - 1; // 后面去0前移1
|
|
|
|
$iPageBarPage = ceil($iPageNow / ($iPageBarLenth));
|
|
$iPageBarStart = ($iPageBarPage - 1) * $iPageBarLenth;
|
|
$iPageBarEnd = $iPageBarStart + $iPageBarLenth;
|
|
|
|
$aPageBarNums = [];
|
|
for ($i=$iPageBarStart; $i<=$iPageBarEnd; $i++) {
|
|
if ($i >= $iPageTotal) {
|
|
break;
|
|
}
|
|
|
|
if ($i == 0) {
|
|
continue;
|
|
}
|
|
$aPageBarNums[] = $i;
|
|
|
|
}
|
|
array_push($aPageBarNums, end($aPageBarNums) + 1);
|
|
|
|
if ($iPageTotal - ($iPageBarEnd + 1) > 0) {
|
|
$bHaveMore = true;
|
|
} else {
|
|
$bHaveMore = false;
|
|
}
|
|
|
|
$aData = [
|
|
'barNums' => $aPageBarNums,
|
|
'haveMore' => $bHaveMore
|
|
];
|
|
|
|
return $aData;
|
|
}
|
|
|
|
// public static function argFormat($iPage, $iLimit): array
|
|
// {
|
|
// $iDefaultLimit = $limit; // 默认页数,以后是设置
|
|
//
|
|
// $iPage = (int) $request->getQueryParam('p');
|
|
// $iLimit = (int) $request->getParam('l');
|
|
//
|
|
// $iPage = $iPage == 0 ? 1 : $iPage;
|
|
// $iLimit = $iLimit == 0 ? $iDefaultLimit : $iLimit;
|
|
//
|
|
// $iOffset = ($iPage - 1) * $iLimit;
|
|
//
|
|
// return [
|
|
// 'offset' => $iOffset,
|
|
// 'limit' => $iLimit,
|
|
// 'page' => $iPage
|
|
// ];
|
|
// }
|
|
}
|