mirror of
				https://gitee.com/zoujingli/ThinkAdmin.git
				synced 2025-10-31 04:02:07 +08:00 
			
		
		
		
	[更新]权限节点刷新机制
This commit is contained in:
		
							parent
							
								
									fa522c8e83
								
							
						
					
					
						commit
						1adba1fbf0
					
				| @ -39,6 +39,39 @@ class Node { | |||||||
|         return false; |         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 |      * @return array | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ | |||||||
| // +----------------------------------------------------------------------
 | // +----------------------------------------------------------------------
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | use app\admin\model\Node as NodeModal; | ||||||
| use think\Config; | use think\Config; | ||||||
| use think\Db; | use think\Db; | ||||||
| use Wechat\Loader; | use Wechat\Loader; | ||||||
| @ -73,18 +74,7 @@ function decode($string) { | |||||||
|  * @return bool |  * @return bool | ||||||
|  */ |  */ | ||||||
| function auth($node) { | function auth($node) { | ||||||
|     $nodes = cache('need_access_node'); |     return NodeModal::checkAuthNode($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')); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user