added 去除隐藏菜单

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

View File

@ -45,29 +45,45 @@ 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 ){
$authList = (new \Permission())->getAuthList($this->uid); if( isAdministrator() ){
switch ( $temp['tempType'] ){ $MenuInfo = Menu::where([])->column('hide','url');
case 'table': $authList = (new \Permission())->getAuthList($this->uid);
foreach ( $temp['topButton'] as $key => $value ){ switch ( $temp['tempType'] ){
if( !isset($authList[$value['href']]) || !$authList[$value['href']] ){ case 'table':
unset($temp['topButton'][$key]); foreach ( $temp['topButton'] as $key => $value ){
}else{ if( !isset($authList[$value['href']]) || !$authList[$value['href']] ){
$temp['topButton'][$key]['href'] = url($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']);
$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{
}else{ if( !isset($MenuInfo[$v['href']]) || $MenuInfo[$v['href']] ){
$temp['rightButton'][$k]['href'] = url($v['href']); unset($temp['rightButton'][$k]);
}else{
$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;
} }