初始化代码
This commit is contained in:
63
application/anchor/model/SystemMenu.php
Normal file
63
application/anchor/model/SystemMenu.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace app\anchor\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class SystemMenu extends Model
|
||||
{
|
||||
|
||||
// 获取初始化数据
|
||||
public function getSystemInit($aid = 0)
|
||||
{
|
||||
$homeInfo = [
|
||||
'title' => '首页',
|
||||
'href' => '',
|
||||
];
|
||||
$logoInfo = [
|
||||
'title' => '系统 管理',
|
||||
'image' => 'images/logo.png',
|
||||
];
|
||||
$menuInfo = $this->getMenuList($aid);
|
||||
$systemInit = [
|
||||
'homeInfo' => $homeInfo,
|
||||
'logoInfo' => $logoInfo,
|
||||
'menuInfo' => $menuInfo,
|
||||
];
|
||||
return $systemInit;
|
||||
}
|
||||
|
||||
// 获取菜单列表
|
||||
private function getMenuList($aid)
|
||||
{
|
||||
$menuList = Db::name('system_menu_anchor')
|
||||
->field('id,pid,title,icon,href,target')
|
||||
->where('status', 1)
|
||||
->where('type', 'in', [1, 2])
|
||||
->order('sort', 'desc')
|
||||
->select();
|
||||
|
||||
$menuList = $this->buildMenuChild(0, $menuList);
|
||||
return $menuList;
|
||||
}
|
||||
|
||||
//递归获取子菜单
|
||||
private function buildMenuChild($pid, $menuList)
|
||||
{
|
||||
$treeList = [];
|
||||
foreach ($menuList as &$v) {
|
||||
|
||||
if ($pid == $v['pid']) {
|
||||
$node = $v;
|
||||
$child = $this->buildMenuChild($v['id'], $menuList);
|
||||
if (!empty($child)) {
|
||||
$node['child'] = $child;
|
||||
}
|
||||
// todo 后续此处加上用户的权限判断
|
||||
$treeList[] = $node;
|
||||
}
|
||||
}
|
||||
return $treeList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user