first commit
This commit is contained in:
55
application/service/MenuService.php
Normal file
55
application/service/MenuService.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/11/13 0013
|
||||
* Time: 上午 10:50
|
||||
*/
|
||||
namespace app\service;
|
||||
|
||||
use think\Collection;
|
||||
|
||||
class MenuService
|
||||
{
|
||||
|
||||
/**
|
||||
* 树形结构
|
||||
*
|
||||
* @time at 2018年11月13日
|
||||
* @param $menu
|
||||
* @return Collection
|
||||
*/
|
||||
public function tree(Collection $menus, int $pid = 0)
|
||||
{
|
||||
$collection = new Collection();
|
||||
|
||||
$menus->each(function ($item, $key) use ($pid, $menus, $collection){
|
||||
if ($item->pid == $pid) {
|
||||
$collection[$key] = $item;
|
||||
$collection[$key][$item->id] = $this->tree($menus, $item->id);
|
||||
}
|
||||
});
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* 顺序结构
|
||||
*
|
||||
* @time at 2018年11月13日
|
||||
* @param $menu
|
||||
* @return Collection
|
||||
*/
|
||||
public function sort(Collection $menus, int $pid = 0, int $level = 0)
|
||||
{
|
||||
$collection = [];
|
||||
foreach ($menus as $menu) {
|
||||
if ($menu->pid == $pid) {
|
||||
$menu->level = $level;
|
||||
$collection[] = $menu;
|
||||
$collection = array_merge($collection, $this->sort($menus, $menu->id, $level+1));
|
||||
}
|
||||
}
|
||||
return $collection;
|
||||
}
|
||||
}
|
64
application/service/PaginateService.php
Normal file
64
application/service/PaginateService.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/11/16 0016
|
||||
* Time: 上午 11:01
|
||||
*/
|
||||
namespace app\service;
|
||||
|
||||
use think\paginator\driver\Bootstrap;
|
||||
use think\Collection;
|
||||
|
||||
class PaginateService extends Bootstrap
|
||||
{
|
||||
|
||||
/**
|
||||
* 渲染分页html
|
||||
* @return mixed
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
if ($this->hasPages()) {
|
||||
if ($this->simple) {
|
||||
return sprintf(
|
||||
'<ul class="pager">%s %s</ul>',
|
||||
$this->getPreviousButton(),
|
||||
$this->getNextButton()
|
||||
);
|
||||
} else {
|
||||
return sprintf(
|
||||
'<ul class="pagination">%s %s %s %s</ul>',
|
||||
$this->getPreviousButton(),
|
||||
$this->getLinks(),
|
||||
$this->getNextButton(),
|
||||
$this->changeLimit()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function changeLimit()
|
||||
{
|
||||
$query = $this->options['query'];
|
||||
$html = ' <li class="project_page">';
|
||||
|
||||
$pageLimit = config('admin.page_limit');
|
||||
$html .= '<select class="page-form-control limit" name="limit">';
|
||||
foreach ($pageLimit as $limit) {
|
||||
if (isset($query['limit']) && $query['limit'] == $limit) {
|
||||
$html .= sprintf('<option value="%s" selected>%s条/页</option>', $limit, $limit);
|
||||
} else {
|
||||
$html .= sprintf('<option value="%s">%s条/页</option>', $limit, $limit);
|
||||
}
|
||||
}
|
||||
$html .= '</select></li> <li>';
|
||||
|
||||
$html .= sprintf('<input name="page" class="page-form-control-input" value="%s"> 页 ', $query['page'] ?? 1);
|
||||
$html .='</li>';
|
||||
|
||||
$html .= '<li><button class="btn btn-primary btn-xs hrefTo"><i class="fa fa-location-arrow"></i> 跳转</button></li>';
|
||||
return $html;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user