onethink后台支持三级菜单,CMS管理后台1.0版本本身不支持三级菜单,稍加改动,即可支持无限级分类
/**
* 获取控制器菜单数组,二级菜单元素位于一级菜单的'_child'元素中
* @author 朱亚杰 <xcoolcc@gmail.com>
*/
final public function getMenus($controller=CONTROLLER_NAME){
// $menus = session('ADMIN_MENU_LIST'.$controller)
$flag=false//是否开启menu三级菜单
if(empty($menus)){
// 获取主菜单
$where['pid'] = 0
$where['hide'] = 0
if(!C('DEVELOP_MODE')){ // 是否开发者模式
$where['is_dev']= 0
}
$menus['main'] = M('Menu')->where($where)->order('sort asc')->select()
$menus['child'] = array()//设置子节点
//高亮主菜单
$current = M('Menu')->where("url like '%{$controller}/".ACTION_NAME."%'")->field('id')->find()
if($current){
$nav = D('Menu')->getPath($current['id'])
$nav_first_title = $nav[0]['title']
foreach ($menus['main'] as $key =>$item) {
if (!is_array($item) || empty($item['title']) || empty($item['url']) ) {
$this->error('控制器基类$menus属性元素配置有误')
}
if( stripos($item['url'],MODULE_NAME)!==0 ){
$item['url'] = MODULE_NAME.'/'.$item['url']
}
// 判断主菜单权限
if ( !IS_ROOT &&!$this->checkRule($item['url'],AuthRuleModel::RULE_MAIN,null) ) {
unset($menus['main'][$key])
continue//继续循环
}
// 获取当前主菜单的子菜单项
if($item['title'] == $nav_first_title){
$menus['main'][$key]['class']='current'
//生成child树
$groups = M('Menu')->where("pid = {$item['id']}")->distinct(true)->field("`group`")->select()
if($groups){
$groups = array_column($groups, 'group')
}else{
$groups = array()
}
//获取二级分类的合法url
$where = array()
$where['pid'] = $item['id']
$where['hide'] = 0
if(!C('DEVELOP_MODE')){ // 是否开发者模式
$where['is_dev']= 0
}
$second_urls = M('Menu')->where($where)->getField('id,url')
$third_urlss=array()
if(!empty($second_urls) &&$flag){
foreach($second_urls as $key=>$v){
$wheres = array()
$wheres['pid'] = $key
$wheres['hide'] = 0
if(!C('DEVELOP_MODE')){ // 是否开发者模式
$wheres['is_dev']= 0
}
$third_urls[] = M('Menu')->where($wheres)->getField('id,url')
foreach($third_urls as $vv){
foreach($vv as $key=>$vs){
$third_urlss[$key]=$vs
}
}
}
}
if(!IS_ROOT){
// 检测菜单权限
$to_check_urls = array()
foreach ($second_urls as $key=>$to_check_url) {
if( stripos($to_check_url,MODULE_NAME)!==0 ){
$rule = MODULE_NAME.'/'.$to_check_url
}else{
$rule = $to_check_url
}
if($this->checkRule($rule, AuthRuleModel::RULE_URL,null))
$to_check_urls[] = $to_check_url
}
if(!empty($third_urlss) &&$flag){
foreach ($third_urlss as $key=>$to_check_urlss) {
if( stripos($to_check_urlss,MODULE_NAME)!==0 ){
$rules = MODULE_NAME.'/'.$to_check_urlss
}else{
$rules = $to_check_urlss
}
if($this->checkRule($rules, AuthRuleModel::RULE_URL,null))
echo $rules."<br/>"
$to_check_urlsss[] = $to_check_urlss
}
}
}
// 按照分组生成子菜单树
foreach ($groups as $g) {
$map = array('group'=>$g)
if(isset($to_check_urls)){
if(empty($to_check_urls)){
// 没有任何权限
continue
}else{
$map['url'] = array('in', $to_check_urls)
}
}
$map['pid'] = $item['id']
$map['hide']= 0
if(!C('DEVELOP_MODE')){ // 是否开发者模式
$map['is_dev'] = 0
}
$menuList = M('Menu')->where($map)->field('id,pid,title,url,tip')->order('sort asc')->select()
$menus['child'][$g] = list_to_tree($menuList, 'id', 'pid', 'operater', $item['id'])
//支持三级菜单
if(!empty($menus['child'][$g]) &&$flag){
foreach($menuList as $key=>$v){
$maps['pid'] = $v['id']
$menuLists = M('Menu')->where($maps)->field('id,pid,title,url,tip')->order('sort asc')->select()
$menus['child'][$g][$key]['ttt'] = list_to_tree($menuLists, 'id', 'pid', 'operater', $v['id'])
}
}
}
if($menus['child'] === array()){
//$this->error('主菜单下缺少子菜单,请去系统=》后台菜单管理里添加')
}
}
}
}
// session('ADMIN_MENU_LIST'.$controller,$menus)
}
return $menus
}
然后Public/base.html
<!-- 边栏 -->
<div class="sidebar">
<!-- 子导航 -->
<block name="sidebar">
<div class="sidebar-collapse" id="sidebar-collapse">
<i class="fa fa-angle-double-left"><<</i>
</div>
<div id="subnav" class="subnav">
<notempty name="_extra_menu">
{// 动态扩展菜单 //}
{:extra_menu($_extra_menu,$__MENU__)}
</notempty>
<volist name="__MENU__.child" id="sub_menu">
<!-- 子导航 -->
<notempty name="sub_menu">
<notempty name="key"><h3><i class="icon icon-unfold"></i>{$key}</h3></notempty>
<ul class="side-sub-menu">
<volist name="sub_menu" id="menu">
<li>
<a class="item" href="{$menu.url|U}">{$menu.title}</a>
</li>
</volist>
<notempty name="menu.ttt">
<volist name="menu.ttt" id="menus">
<li>
<a class="item" href="{$menus.url|U}">{$menus.title}</a>
</li>
</volist>
</notempty>
</ul>
</notempty>
<!-- /子导航 -->
</volist>
</div>
</block>
<!-- /子导航 -->
</div>
FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架。权限管理
基于完善的Auth权限控制管理、无限父子级权限分组、可自由分配子级权限、一个管理员可同时属于多个组别
响应式开发
基于Bootstrap和AdminLTE进行二次开发,手机、平板、PC均自动适配,无需要担心兼容性问题
多语言
不仅仅后台开发支持多语言,同时视图部分和JS部分仍然共享同一个语言包,语法相同且自动加载
模块化开发
控制器、模型、视图、JS一一对应,使用RequireJS进行JS模块化管理,采用Bower进行前端包组件管理
CRUD
控制台进行一键生成控制器、模型、视图和JS文件,同时可一键生成后台权限节点和菜单栏
丰富的插件
基于ThinkPHP行为功能实现的插件机制,拥有丰富的插件和扩展,可直接在线安装卸载
主要特性
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)