feat: menu
This commit is contained in:
@@ -10,13 +10,43 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\User;
|
||||
|
||||
use App\Cache\Redis\Admin\MenuCache;
|
||||
use App\Constants\Admin\AuthCode;
|
||||
use App\Exception\AdminException;
|
||||
use App\Model\AdminMenu;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use RedisException;
|
||||
|
||||
class RoleMenuService extends BaseService
|
||||
{
|
||||
public function handle()
|
||||
/**
|
||||
* 注入缓存
|
||||
* @var MenuCache $menuCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected MenuCache $menuCache;
|
||||
|
||||
/**
|
||||
* @var AdminMenu $adminMenuModel
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminMenu $adminMenuModel;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws RedisException
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
return $this->return->success();
|
||||
$data = $this->menuCache->getMenu();
|
||||
|
||||
return $this->return->success('success', ['list' => $data]);
|
||||
}
|
||||
|
||||
public function add()
|
||||
@@ -34,8 +64,40 @@ class RoleMenuService extends BaseService
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function details()
|
||||
/**
|
||||
* 详情
|
||||
* @return array
|
||||
*/
|
||||
public function details(): array
|
||||
{
|
||||
return $this->return->success();
|
||||
$menuId = $this->request->input('menu_id');
|
||||
$res = $this->adminMenuModel->where('id',$menuId)->first();
|
||||
if (!$res) throw new AdminException('角色不存在');
|
||||
$res = $res->toArray();
|
||||
|
||||
//闭包函数获取子集
|
||||
$res = function() use($res,$menuId) {
|
||||
$children = $this->adminMenuModel->where('parent_id',$menuId)->select(['type','value','title','id'])->get();
|
||||
$res['permissionList'] = [];
|
||||
if (!empty($children)) {
|
||||
$children = $children->toArray();
|
||||
if ($children[0]['type'] == AuthCode::MENU_TYPE_LIST) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
foreach ($children as $one)
|
||||
{
|
||||
$res['permissionList'][] = [
|
||||
'id' => $one['id'],
|
||||
'label' => $one['title'],
|
||||
'value' => $one['value'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
};
|
||||
|
||||
return $this->return->success('success',['info' => $res]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user