feat: 增加动态设置当前账户的权限功能;增加该功能演示效果

This commit is contained in:
augushong
2025-04-21 15:54:07 +08:00
parent 81860e8277
commit c1042ce1c6
3 changed files with 59 additions and 3 deletions

View File

@@ -52,6 +52,8 @@ class AuthServiceBase
protected $nodeService;
protected static $dynamicNodeList = [];
/***
* 构造方法
* AuthService constructor.
@@ -64,6 +66,9 @@ class AuthServiceBase
{
$this->nodeService = new NodeService();
if(empty($adminId)){
$adminId = get_session_admin('id');
}
$this->adminId = $adminId;
$this->adminInfo = $this->getAdminInfo();
$this->nodeList = $this->getNodeList();
@@ -87,6 +92,10 @@ class AuthServiceBase
*/
public function checkNode($node = null)
{
if(isset(static::$dynamicNodeList[$node])){
return static::$dynamicNodeList[$node];
}
// 判断是否为超级管理员
if ($this->isSuperAdmin()) {
return true;
@@ -101,6 +110,7 @@ class AuthServiceBase
} else {
$node = $this->parseNodeStr($node);
}
// 判断是否加入节点控制,优先获取缓存信息
if (!isset($this->nodeList[$node])) {
return Config::get('admin.default_auth_check');
@@ -213,4 +223,19 @@ class AuthServiceBase
return $node;
}
public function disableNode($node, $skipSuperAdmin = true)
{
if($this->isSuperAdmin()){
if($skipSuperAdmin){
return;
}
}
static::$dynamicNodeList[$node] = false;
}
public function enableNode($node)
{
static::$dynamicNodeList[$node] = true;
}
}