|
|
@@ -264,12 +264,12 @@ class SysMenuService extends Service
|
|
|
return [true,''];
|
|
|
}
|
|
|
|
|
|
- public function fillMenuButton($button, $menu, $user, $type = 1)
|
|
|
+ public function fillMenuButton1($button, $menu, $user, $type = 1)
|
|
|
{
|
|
|
// 1. 预处理所有按钮池(合并配置中的特殊按钮)
|
|
|
$allButtons = collect($button)->concat(config('specialButton') ?? [])->groupBy('menu_id');
|
|
|
|
|
|
- // 2. 获取权限基础数据(如果是超管,这两个值为空,逻辑依然兼容)
|
|
|
+ // 2. 获取权限基础数据
|
|
|
$isSuper = ($user['is_admin'] == Employee::IS_ADMIN_TWO);
|
|
|
$roleButtons = $isSuper ? [] : (new EmployeeService())->fillRoleButton($user['role_ids'] ?? []);
|
|
|
$allowedMenuIds = $isSuper ? [] : $this->getMenuIDByRoleInList($user);
|
|
|
@@ -310,7 +310,48 @@ class SysMenuService extends Service
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
- private function returnTwo($sysList, $user){
|
|
|
+ public function fillMenuButton($button, $menu, $user, $type = 1)
|
|
|
+ {
|
|
|
+ // 1. 预处理所有按钮池(合并配置中的特殊按钮)
|
|
|
+ $allButtons = collect($button)->concat(config('specialButton') ?? [])->groupBy('menu_id');
|
|
|
+
|
|
|
+ // 2. 获取权限基础数据
|
|
|
+ $roleButtons = (new EmployeeService())->fillRoleButton($user['role_ids'] ?? []);
|
|
|
+ $allowedMenuIds = $this->getMenuIDByRoleInList($user);
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+
|
|
|
+ foreach ($menu as $m) {
|
|
|
+ $menuId = $m['id'];
|
|
|
+
|
|
|
+ // 权限过滤:不在权限内,跳过
|
|
|
+ if (!in_array($menuId, $allowedMenuIds)) continue;
|
|
|
+
|
|
|
+ // 计算当前菜单拥有的按钮
|
|
|
+ // 只返回该角色拥有的按钮数据
|
|
|
+ $myBtnIds = $roleButtons[$menuId] ?? [];
|
|
|
+ $btnPool = collect($allButtons->get($menuId))->keyBy('id');
|
|
|
+ $btns = collect($myBtnIds)->map(fn($id) => $btnPool->get($id))->filter()->values();
|
|
|
+
|
|
|
+ // 3. 根据 type 返回不同的数据结构
|
|
|
+ if ($type == 1) {
|
|
|
+ // 完整模式:保留原菜单所有字段
|
|
|
+ $m['button'] = $btns;
|
|
|
+ $result[] = $m;
|
|
|
+ } else {
|
|
|
+ // 精简模式:只给前端路由用的字段
|
|
|
+ $result[] = [
|
|
|
+ 'id' => $menuId,
|
|
|
+ 'uri' => $m['uri'] ?? '',
|
|
|
+ 'button' => $btns,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function returnTwo1($sysList, $user){
|
|
|
//人员所拥有的菜单
|
|
|
$menu = $this->getMenuIDByRoleInList($user);
|
|
|
|
|
|
@@ -323,6 +364,19 @@ class SysMenuService extends Service
|
|
|
return $this->set_sort_circle($return);;
|
|
|
}
|
|
|
|
|
|
+ private function returnTwo($sysList, $user){
|
|
|
+ //人员所拥有的菜单
|
|
|
+ $menu = $this->getMenuIDByRoleInList($user);
|
|
|
+
|
|
|
+ foreach ($sysList as $key => $value){
|
|
|
+ if($value['state'] <= 0) unset($sysList[$key]);
|
|
|
+ if(! in_array($value['id'], $menu)) unset($sysList[$key]);
|
|
|
+ }
|
|
|
+ $list = array_values($sysList);
|
|
|
+ $return = $this->makeTree(0,$list);
|
|
|
+ return $this->set_sort_circle($return);;
|
|
|
+ }
|
|
|
+
|
|
|
//通过角色获取菜单ID
|
|
|
public function getMenuIDByRoleInList($user){
|
|
|
$role_id = $user['role_ids'] ?? [];
|