mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]权限节点刷新机制
This commit is contained in:
parent
fa522c8e83
commit
1adba1fbf0
@ -39,6 +39,39 @@ class Node {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取授权节点
|
||||
* @staticvar array $nodes
|
||||
* @return array
|
||||
*/
|
||||
public static function getAuthNode() {
|
||||
static $nodes = [];
|
||||
if (empty($nodes)) {
|
||||
$nodes = cache('need_access_node');
|
||||
if (empty($nodes)) {
|
||||
$nodes = Db::name('SystemNode')->where('is_auth', '1')->column('node');
|
||||
cache('need_access_node', $nodes);
|
||||
}
|
||||
}
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户节点权限
|
||||
* @param string $node
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkAuthNode($node) {
|
||||
$auth_node = strtolower($node);
|
||||
if (session('user.username') === 'admin' || stripos($node, 'admin/index') === 0) {
|
||||
return true;
|
||||
}
|
||||
if (!in_array($auth_node, self::getAuthNode())) {
|
||||
return true;
|
||||
}
|
||||
return in_array($auth_node, (array) session('user.nodes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统代码节点
|
||||
* @return array
|
||||
|
@ -13,6 +13,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
use app\admin\model\Node as NodeModal;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
use Wechat\Loader;
|
||||
@ -73,18 +74,7 @@ function decode($string) {
|
||||
* @return bool
|
||||
*/
|
||||
function auth($node) {
|
||||
$nodes = cache('need_access_node');
|
||||
if (empty($nodes)) {
|
||||
$nodes = Db::name('SystemNode')->where('is_auth', '1')->column('node');
|
||||
cache('need_access_node', $nodes);
|
||||
}
|
||||
if (session('user.username') === 'admin' || stripos($node, 'admin/index') === 0) {
|
||||
return true;
|
||||
}
|
||||
if (!in_array(strtolower($node), array_values($nodes))) {
|
||||
return true;
|
||||
}
|
||||
return in_array(strtolower($node), (array) session('user.nodes'));
|
||||
return NodeModal::checkAuthNode($node);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user