feat : menu list

This commit is contained in:
2024-10-28 11:55:57 +08:00
parent b828d48672
commit c86c6c1baf
6 changed files with 322 additions and 16 deletions

View File

@@ -24,6 +24,17 @@ class MenuCache
#[Inject]
protected AdminMenu $adminMenuModel;
/**
* 菜单
* @var string
*/
protected string $menuKey;
public function __construct()
{
$this->menuKey = AdminRedisKey::adminMenuList();
}
/**
* @return array
* @throws ContainerExceptionInterface
@@ -32,21 +43,30 @@ class MenuCache
*/
public function getMenu(): array
{
$key = AdminRedisKey::adminMenuList();
if ($this->redis->exists($key,'system')) {
return json_decode($this->redis->get($key,'system'),true);
if ($this->redis->exists($this->menuKey,'system')) {
return json_decode($this->redis->get($this->menuKey,'system'),true);
}
$allMenuList = $this->adminMenuModel->getAllMenu();
$data = $this->getDbMenu($allMenuList);
$this->redis->set($key,json_encode($data));
$this->redis->set($this->menuKey,json_encode($data));
return $data;
}
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws RedisException
*/
public function delMenu(): void
{
$this->redis->delete($this->menuKey);
}
/**
* 递归生成合适的数据
* @param array $allMenuList