From 1ce7527b4e7edec40306e27ad7409452e64b27c7 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Tue, 15 Nov 2016 14:33:17 +0800 Subject: [PATCH] =?UTF-8?q?added=20=E5=8E=BB=E9=99=A4=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Base.php | 56 +++++++++++++++++---------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/application/admin/controller/Base.php b/application/admin/controller/Base.php index 0163dd9..f9ded73 100644 --- a/application/admin/controller/Base.php +++ b/application/admin/controller/Base.php @@ -45,29 +45,45 @@ class Base extends Controller { return (new PublicShow())->show_404(); } + /** + * 过滤没有权限和隐藏的菜单 + * @param $temp + * @return mixed + */ protected function _prepareTemplate( $temp ){ - $authList = (new \Permission())->getAuthList($this->uid); - switch ( $temp['tempType'] ){ - case 'table': - foreach ( $temp['topButton'] as $key => $value ){ - if( !isset($authList[$value['href']]) || !$authList[$value['href']] ){ - unset($temp['topButton'][$key]); - }else{ - $temp['topButton'][$key]['href'] = url($value['href']); + if( isAdministrator() ){ + $MenuInfo = Menu::where([])->column('hide','url'); + $authList = (new \Permission())->getAuthList($this->uid); + switch ( $temp['tempType'] ){ + case 'table': + foreach ( $temp['topButton'] as $key => $value ){ + if( !isset($authList[$value['href']]) || !$authList[$value['href']] ){ + unset($temp['topButton'][$key]); + }else{ + if( !isset($MenuInfo[$value['href']]) || $MenuInfo[$value['href']] ){ + unset($temp['topButton'][$key]); + }else{ + $temp['topButton'][$key]['href'] = url($value['href']); + } + } } - } - $temp['topButton'] = array_values($temp['topButton']); - foreach ( $temp['rightButton'] as $k => $v ){ - if( !isset($authList[$v['href']]) || !$authList[$v['href']] ){ - unset($temp['rightButton'][$k]); - }else{ - $temp['rightButton'][$k]['href'] = url($v['href']); + $temp['topButton'] = array_values($temp['topButton']); + foreach ( $temp['rightButton'] as $k => $v ){ + if( !isset($authList[$v['href']]) || !$authList[$v['href']] ){ + unset($temp['rightButton'][$k]); + }else{ + if( !isset($MenuInfo[$v['href']]) || $MenuInfo[$v['href']] ){ + unset($temp['rightButton'][$k]); + }else{ + $temp['rightButton'][$k]['href'] = url($v['href']); + } + } } - } - $temp['rightButton'] = array_values($temp['rightButton']); - break; - case 'form': - break; + $temp['rightButton'] = array_values($temp['rightButton']); + break; + case 'form': + break; + } } return $temp; }