added 去除隐藏菜单

This commit is contained in:
zhaoxiang 2016-11-15 14:33:17 +08:00
parent 21fe069f77
commit 1ce7527b4e

View File

@ -45,30 +45,46 @@ class Base extends Controller {
return (new PublicShow())->show_404(); return (new PublicShow())->show_404();
} }
/**
* 过滤没有权限和隐藏的菜单
* @param $temp
* @return mixed
*/
protected function _prepareTemplate( $temp ){ protected function _prepareTemplate( $temp ){
if( isAdministrator() ){
$MenuInfo = Menu::where([])->column('hide','url');
$authList = (new \Permission())->getAuthList($this->uid); $authList = (new \Permission())->getAuthList($this->uid);
switch ( $temp['tempType'] ){ switch ( $temp['tempType'] ){
case 'table': case 'table':
foreach ( $temp['topButton'] as $key => $value ){ foreach ( $temp['topButton'] as $key => $value ){
if( !isset($authList[$value['href']]) || !$authList[$value['href']] ){ if( !isset($authList[$value['href']]) || !$authList[$value['href']] ){
unset($temp['topButton'][$key]); unset($temp['topButton'][$key]);
}else{
if( !isset($MenuInfo[$value['href']]) || $MenuInfo[$value['href']] ){
unset($temp['topButton'][$key]);
}else{ }else{
$temp['topButton'][$key]['href'] = url($value['href']); $temp['topButton'][$key]['href'] = url($value['href']);
} }
} }
}
$temp['topButton'] = array_values($temp['topButton']); $temp['topButton'] = array_values($temp['topButton']);
foreach ( $temp['rightButton'] as $k => $v ){ foreach ( $temp['rightButton'] as $k => $v ){
if( !isset($authList[$v['href']]) || !$authList[$v['href']] ){ if( !isset($authList[$v['href']]) || !$authList[$v['href']] ){
unset($temp['rightButton'][$k]); unset($temp['rightButton'][$k]);
}else{
if( !isset($MenuInfo[$v['href']]) || $MenuInfo[$v['href']] ){
unset($temp['rightButton'][$k]);
}else{ }else{
$temp['rightButton'][$k]['href'] = url($v['href']); $temp['rightButton'][$k]['href'] = url($v['href']);
} }
} }
}
$temp['rightButton'] = array_values($temp['rightButton']); $temp['rightButton'] = array_values($temp['rightButton']);
break; break;
case 'form': case 'form':
break; break;
} }
}
return $temp; return $temp;
} }