From 08ea79033c2a075b566a123e518c18883135dad6 Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:54:15 +0800 Subject: [PATCH] feat(admin): add ignoreNode property to skip unnecessary node generation - Add $ignoreNode property to Goods controller to specify methods to ignore - Update Node service to check and skip ignored methods during node generation - This change helps to filter out unnecessary nodes, improving system performance and readability --- app/admin/controller/mall/Goods.php | 6 ++++++ app/admin/service/auth/Node.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/app/admin/controller/mall/Goods.php b/app/admin/controller/mall/Goods.php index 444beb8..6afb6aa 100644 --- a/app/admin/controller/mall/Goods.php +++ b/app/admin/controller/mall/Goods.php @@ -20,6 +20,12 @@ use think\response\Json; class Goods extends AdminController { + /** + * 过滤不需要生成的权限节点 默认 CURD 中会自动生成部分节点 可以在此处过滤 + * @var array[] + */ + protected array $ignoreNode = ['export']; + public function __construct(App $app) { parent::__construct($app); diff --git a/app/admin/service/auth/Node.php b/app/admin/service/auth/Node.php index 10b0571..01667c6 100644 --- a/app/admin/service/auth/Node.php +++ b/app/admin/service/auth/Node.php @@ -67,6 +67,12 @@ class Node // 遍历读取所有方法的注释的参数信息 foreach ($methods as $method) { + + // 忽略的节点 + $properties = $reflectionClass->getDefaultProperties(); + $ignoreNode = $properties['ignoreNode'] ?? []; + if (!empty($ignoreNode)) if (in_array($method->name, $ignoreNode)) continue; + // 读取NodeAnnotation的注解 $nodeAnnotation = $reader->getMethodAnnotation($method, NodeAnnotation::class); if (!empty($nodeAnnotation)) {