从数据库中生成菜单

This commit is contained in:
邹景立 2017-02-13 17:38:38 +08:00
parent 09a8fa89f9
commit 63e2e92795
4 changed files with 78 additions and 108 deletions

View File

@ -3,15 +3,43 @@
namespace app\admin\controller;
use controller\BasicAdmin;
use library\Tools;
use think\Db;
class Index extends BasicAdmin {
public function index() {
$this->assign('ptitle', '后台管理');
$menuList = Db::name('SystemMenu')->field('title,id,pid,url,icon')->where('status', '1')->select();
$result = Tools::arr2tree($menuList);
$this->assign('menus', $this->_filterMenu($result));
return view();
}
/**
* 后台主菜单权限过滤
* --- 权限只检测节点三级
* @param array $menus
* @return array
*/
private function _filterMenu($menus) {
foreach ($menus as $key => &$menu) {
if (!empty($menu['sub'])) {
$menu['sub'] = $this->_filterMenu($menu['sub']);
}
if (!empty($menu['sub'])) {
$menu['url'] = '#';
} elseif (stripos($menu['url'], 'http') === 0) {
continue;
} elseif ($menu['url'] !== '#' && auth(join('/', array_slice(explode('/', $menu['url']), 0, 3)))) {
$menu['url'] = url($menu['url']);
} else {
unset($menus[$key]);
}
}
return $menus;
}
public function main() {
$version = Db::query('select version() as ver');
$version = array_pop($version);

View File

@ -53,6 +53,15 @@ function decode($string) {
return unserialize(base64_decode($data));
}
/**
* RBAC节点权限验证
* @param string $node
* @return bool
*/
function auth($node) {
return true;
}
/**
* 从配置表读取配置信息
* @param string $name

View File

@ -4,122 +4,49 @@
<div class="sidebar-fold">
<span class="glyphicon glyphicon-option-vertical transition"></span>
</div>
<div class="" data-menu-box="m-3">
<div class="sidebar-nav main-nav open">
{volist name='menus' id='pmenu'}
{notempty name='pmenu.sub'}
<div data-menu-box="m-{$pmenu.id}">
{volist name='pmenu.sub' id='menu'}
<div class="sidebar-nav main-nav">
{empty name='menu.sub'}
<ul class="sidebar-trans">
<li class="nav-item">
<a data-menu-node='m-{$pmenu.id}-{$menu.id}' data-open="{$menu.url}"
class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="{$menu.icon|default='fa fa-link'} transition-min"></span>
</div>
<span class="nav-title">{$menu.title}</span>
</a>
</li>
</ul>
{else}
<div class="sidebar-title">
<div class="sidebar-title-inner">
<span class="sidebar-title-icon fa fa-caret-right transition-min"></span>
<span class="sidebar-title-text">系统配置</span>
<span class="sidebar-title-text">{$menu.title}</span>
</div>
</div>
<ul class="sidebar-trans" style="" data-menu-node="m-3-10044">
<li class="nav-item active">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="fa fa-envelope transition-min"></span>
</div>
<span class="nav-title">邮箱配置</span>
</a>
</li>
<ul class="sidebar-trans" style="display:none" data-menu-node='m-{$pmenu.id}-{$menu.id}'>
{volist name='menu.sub' id='submenu'}
<li class="nav-item">
<a class="sidebar-trans">
<a data-menu-node='m-{$pmenu.id}-{$submenu.id}' data-open="{$submenu.url}"
class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="fa fa-envelope-square transition-min"></span>
<span class="{$submenu.icon|default='fa fa-link'} transition-min"></span>
</div>
<span class="nav-title">短信配置</span>
<span class="nav-title">{$submenu.title}</span>
</a>
</li>
<li class="nav-item">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="fa fa-internet-explorer transition-min"></span>
</div>
<span class="nav-title">网站配置</span>
</a>
</li>
<li class="nav-item">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="fa fa-apple transition-min"></span>
</div>
<span class="nav-title">后台配置</span>
</a>
</li>
<li class="nav-item">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="fa fa-hdd-o transition-min"></span>
</div>
<span class="nav-title">文件存储</span>
</a>
</li>
{/volist}
</ul>
{/empty}
</div>
<div class="sidebar-nav main-nav open">
<div class="sidebar-title">
<div class="sidebar-title-inner">
<span class="sidebar-title-icon fa fa-caret-right transition-min"></span>
<span class="sidebar-title-text">系统权限</span>
</div>
</div>
<ul class="sidebar-trans" style="" data-menu-node="m-3-10043">
<li class="nav-item">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="fa fa-user-secret transition-min"></span>
</div>
<span class="nav-title">权限管理</span>
</a>
</li>
<li class="nav-item">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="fa fa-user transition-min"></span>
</div>
<span class="nav-title">用户管理</span>
</a>
</li>
<li class="nav-item">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="glyphicon glyphicon-menu-hamburger transition-min"></span>
</div>
<span class="nav-title">系统菜单</span>
</a>
</li>
</ul>
</div>
<div class="sidebar-nav main-nav open">
<div class="sidebar-title">
<div class="sidebar-title-inner">
<span class="sidebar-title-icon fa fa-caret-right transition-min"></span>
<span class="sidebar-title-text">系统工具</span>
</div>
</div>
<ul class="sidebar-trans" style="" data-menu-node="m-3-10045">
<li class="nav-item">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="glyphicon glyphicon-hourglass transition-min"></span>
</div>
<span class="nav-title">系统日志</span>
</a>
</li>
<li class="nav-item">
<a class="sidebar-trans">
<div class="nav-icon sidebar-trans">
<span class="glyphicon glyphicon-hdd transition-min"></span>
</div>
<span class="nav-title">数据备份</span>
</a>
</li>
</ul>
</div>
{/volist}
</div>
{/notempty}
{/volist}
</div>
</div>
</div>

View File

@ -6,13 +6,19 @@
<span class="icon-logo">{:sysconf('app_name')} <sup>{:sysconf('app_version')}</sup></span>
</a>
</div>
<a data-menu-node='1' data-open="{:url('@admin/index/main')}"
class="topbar-home-link topbar-btn topbar-left active">
<span> 系统信息</span>
{volist name='menus' id='pmenu'}
{empty name='pmenu.sub'}
<a data-menu-node='m-{$pmenu.id}' data-open="{$pmenu.url}"
class="topbar-home-link topbar-btn topbar-left">
<span>{notempty name='$pmenu.icon'}<i class="{$pmenu.icon}"></i>{/notempty} {$pmenu.title}</span>
</a>
<a data-menu-target="m-3" class="topbar-home-link topbar-btn topbar-left">
<span> 系统管理</span>
{else/}
<a data-menu-target='m-{$pmenu.id}' class="topbar-home-link topbar-btn topbar-left">
<span>{notempty name='$pmenu.icon'}<i class="{$pmenu.icon}"></i>{/notempty} {$pmenu.title}</span>
</a>
{/empty}
{/volist}
<div class="topbar-info topbar-right">
<a data-reload data-tips-text='刷新'
class=" topbar-btn topbar-left topbar-info-item text-center"