mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 18:12:50 +08:00
feat: 增加动态设置当前账户的权限功能;增加该功能演示效果
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace base\common\event\AdminMenuTab;
|
||||
|
||||
use app\common\service\AuthService;
|
||||
use think\facade\Env;
|
||||
use think\facade\View;
|
||||
|
||||
@@ -17,8 +18,15 @@ class DemoEventBase
|
||||
$tab_content = View::layout(false)->fetch('index/ext/admin_menu_tab_content_demo');
|
||||
}
|
||||
|
||||
View::assign('a2','x2');
|
||||
View::assign('a3','x3');
|
||||
View::assign('a2', 'x2');
|
||||
View::assign('a3', 'x3');
|
||||
|
||||
if (date('i') % 2 == 0) {
|
||||
/** @var AuthService $authService */
|
||||
$authService = app(AuthService::class);
|
||||
$authService->disableNode('debug.log/export', false);
|
||||
}
|
||||
|
||||
// 事件监听处理
|
||||
return [
|
||||
'view_content' => $content,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user