mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 18:42:49 +08:00
feat: 增加动态设置当前账户的权限功能;增加该功能演示效果
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
<div lay-id="layuiminiDemoTabIdContent" class="layui-tab-item">
|
<div
|
||||||
|
lay-id="layuiminiDemoTabIdContent"
|
||||||
|
class="layui-tab-item"
|
||||||
|
>
|
||||||
|
|
||||||
<!-- var的用法,如果变量未声明,则声明,比如a1 -->
|
<!-- var的用法,如果变量未声明,则声明,比如a1 -->
|
||||||
{var name='a1' value='a1' /}
|
{var name='a1' value='a1' /}
|
||||||
@@ -9,4 +12,24 @@
|
|||||||
<!-- 与assign区别,即便其他地方已经定义了a3,此处仍然会被定义 -->
|
<!-- 与assign区别,即便其他地方已经定义了a3,此处仍然会被定义 -->
|
||||||
{assign name='a3' value='a3' /}
|
{assign name='a3' value='a3' /}
|
||||||
{$a3}
|
{$a3}
|
||||||
|
<div class="ul-group-title">
|
||||||
|
动态设置权限
|
||||||
|
</div>
|
||||||
|
<pre>
|
||||||
|
if (date('i') % 2 == 0) {
|
||||||
|
/** @var AuthService $authService */
|
||||||
|
$authService = app(AuthService::class);
|
||||||
|
$authService->disableNode('debug.log/export', false);
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
<p>当分钟数为双数时,禁用指定的权限。</p>
|
||||||
|
<p>
|
||||||
|
日志导出权限:
|
||||||
|
{if auth('debug.log/export') }
|
||||||
|
有权限
|
||||||
|
{else /}
|
||||||
|
无权限
|
||||||
|
{/if}
|
||||||
|
</p>
|
||||||
|
<p>{:date('i')}分</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace base\common\event\AdminMenuTab;
|
namespace base\common\event\AdminMenuTab;
|
||||||
|
|
||||||
|
use app\common\service\AuthService;
|
||||||
use think\facade\Env;
|
use think\facade\Env;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
|
|
||||||
@@ -17,8 +18,15 @@ class DemoEventBase
|
|||||||
$tab_content = View::layout(false)->fetch('index/ext/admin_menu_tab_content_demo');
|
$tab_content = View::layout(false)->fetch('index/ext/admin_menu_tab_content_demo');
|
||||||
}
|
}
|
||||||
|
|
||||||
View::assign('a2','x2');
|
View::assign('a2', 'x2');
|
||||||
View::assign('a3','x3');
|
View::assign('a3', 'x3');
|
||||||
|
|
||||||
|
if (date('i') % 2 == 0) {
|
||||||
|
/** @var AuthService $authService */
|
||||||
|
$authService = app(AuthService::class);
|
||||||
|
$authService->disableNode('debug.log/export', false);
|
||||||
|
}
|
||||||
|
|
||||||
// 事件监听处理
|
// 事件监听处理
|
||||||
return [
|
return [
|
||||||
'view_content' => $content,
|
'view_content' => $content,
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class AuthServiceBase
|
|||||||
|
|
||||||
protected $nodeService;
|
protected $nodeService;
|
||||||
|
|
||||||
|
protected static $dynamicNodeList = [];
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 构造方法
|
* 构造方法
|
||||||
* AuthService constructor.
|
* AuthService constructor.
|
||||||
@@ -64,6 +66,9 @@ class AuthServiceBase
|
|||||||
{
|
{
|
||||||
$this->nodeService = new NodeService();
|
$this->nodeService = new NodeService();
|
||||||
|
|
||||||
|
if(empty($adminId)){
|
||||||
|
$adminId = get_session_admin('id');
|
||||||
|
}
|
||||||
$this->adminId = $adminId;
|
$this->adminId = $adminId;
|
||||||
$this->adminInfo = $this->getAdminInfo();
|
$this->adminInfo = $this->getAdminInfo();
|
||||||
$this->nodeList = $this->getNodeList();
|
$this->nodeList = $this->getNodeList();
|
||||||
@@ -87,6 +92,10 @@ class AuthServiceBase
|
|||||||
*/
|
*/
|
||||||
public function checkNode($node = null)
|
public function checkNode($node = null)
|
||||||
{
|
{
|
||||||
|
if(isset(static::$dynamicNodeList[$node])){
|
||||||
|
return static::$dynamicNodeList[$node];
|
||||||
|
}
|
||||||
|
|
||||||
// 判断是否为超级管理员
|
// 判断是否为超级管理员
|
||||||
if ($this->isSuperAdmin()) {
|
if ($this->isSuperAdmin()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -101,6 +110,7 @@ class AuthServiceBase
|
|||||||
} else {
|
} else {
|
||||||
$node = $this->parseNodeStr($node);
|
$node = $this->parseNodeStr($node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否加入节点控制,优先获取缓存信息
|
// 判断是否加入节点控制,优先获取缓存信息
|
||||||
if (!isset($this->nodeList[$node])) {
|
if (!isset($this->nodeList[$node])) {
|
||||||
return Config::get('admin.default_auth_check');
|
return Config::get('admin.default_auth_check');
|
||||||
@@ -213,4 +223,19 @@ class AuthServiceBase
|
|||||||
|
|
||||||
return $node;
|
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