From ef6fd7bfbc89b90fd1f108adf8cc9f98e68c42cc Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 12 Jul 2022 09:50:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=89=A9=E5=B1=95=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=8A=9F=E8=83=BD=E8=BF=81=E7=A7=BB=E5=88=B0?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=A1=B9=E7=9B=AE=E4=B8=AD=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/debug/Log.php | 4 +- app/admin/controller/mall/Cate.php | 4 +- app/admin/controller/mall/Goods.php | 4 +- app/admin/controller/mall/Tag.php | 4 +- app/admin/controller/system/Admin.php | 4 +- app/admin/controller/system/Auth.php | 4 +- app/admin/controller/system/Config.php | 4 +- app/admin/controller/system/Menu.php | 4 +- app/admin/controller/system/Node.php | 4 +- app/admin/controller/system/Quick.php | 4 +- app/admin/controller/system/Uploadfile.php | 4 +- app/admin/service/NodeService.php | 2 +- .../annotation/ControllerAnnotation.php | 49 ++++++ .../service/annotation/NodeAnotation.php | 44 +++++ .../curd/templates/controller/controller.code | 4 +- app/admin/service/node/Node.php | 153 ++++++++++++++++++ app/admin/traits/Curd.php | 2 +- view/index/welcome.html | 3 +- 18 files changed, 274 insertions(+), 27 deletions(-) create mode 100644 app/admin/service/annotation/ControllerAnnotation.php create mode 100644 app/admin/service/annotation/NodeAnotation.php create mode 100644 app/admin/service/node/Node.php diff --git a/app/admin/controller/debug/Log.php b/app/admin/controller/debug/Log.php index 18f7e45..403f39d 100644 --- a/app/admin/controller/debug/Log.php +++ b/app/admin/controller/debug/Log.php @@ -3,8 +3,8 @@ namespace app\admin\controller\debug; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use think\App; /** diff --git a/app/admin/controller/mall/Cate.php b/app/admin/controller/mall/Cate.php index 7844542..b3453c3 100644 --- a/app/admin/controller/mall/Cate.php +++ b/app/admin/controller/mall/Cate.php @@ -7,8 +7,8 @@ namespace app\admin\controller\mall; use app\admin\model\MallCate; use app\admin\traits\Curd; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use think\App; /** diff --git a/app/admin/controller/mall/Goods.php b/app/admin/controller/mall/Goods.php index b4612f6..b4dcc0a 100644 --- a/app/admin/controller/mall/Goods.php +++ b/app/admin/controller/mall/Goods.php @@ -7,8 +7,8 @@ namespace app\admin\controller\mall; use app\admin\model\MallGoods; use app\admin\traits\Curd; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; diff --git a/app/admin/controller/mall/Tag.php b/app/admin/controller/mall/Tag.php index 4c00dd7..4978110 100644 --- a/app/admin/controller/mall/Tag.php +++ b/app/admin/controller/mall/Tag.php @@ -3,8 +3,8 @@ namespace app\admin\controller\mall; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use think\App; /** diff --git a/app/admin/controller/system/Admin.php b/app/admin/controller/system/Admin.php index 9418dc1..cbdd35b 100644 --- a/app/admin/controller/system/Admin.php +++ b/app/admin/controller/system/Admin.php @@ -8,8 +8,8 @@ use app\admin\model\SystemAdmin; use app\admin\service\TriggerService; use app\common\constants\AdminConstant; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use think\App; /** diff --git a/app/admin/controller/system/Auth.php b/app/admin/controller/system/Auth.php index f28024b..52b6e2a 100644 --- a/app/admin/controller/system/Auth.php +++ b/app/admin/controller/system/Auth.php @@ -8,8 +8,8 @@ use app\admin\model\SystemAuth; use app\admin\model\SystemAuthNode; use app\admin\service\TriggerService; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use think\App; /** diff --git a/app/admin/controller/system/Config.php b/app/admin/controller/system/Config.php index eca54b7..01bb8f1 100644 --- a/app/admin/controller/system/Config.php +++ b/app/admin/controller/system/Config.php @@ -7,8 +7,8 @@ namespace app\admin\controller\system; use app\admin\model\SystemConfig; use app\admin\service\TriggerService; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use think\App; /** diff --git a/app/admin/controller/system/Menu.php b/app/admin/controller/system/Menu.php index 9af9e7c..d6bb41a 100644 --- a/app/admin/controller/system/Menu.php +++ b/app/admin/controller/system/Menu.php @@ -7,8 +7,8 @@ use app\admin\model\SystemMenu; use app\admin\model\SystemNode; use app\admin\service\TriggerService; use app\common\constants\MenuConstant; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use app\common\controller\AdminController; use think\App; diff --git a/app/admin/controller/system/Node.php b/app/admin/controller/system/Node.php index 6f25a30..0fd62e3 100644 --- a/app/admin/controller/system/Node.php +++ b/app/admin/controller/system/Node.php @@ -7,8 +7,8 @@ namespace app\admin\controller\system; use app\admin\model\SystemNode; use app\admin\service\TriggerService; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use app\admin\service\NodeService; use think\App; diff --git a/app/admin/controller/system/Quick.php b/app/admin/controller/system/Quick.php index 1329404..917eb43 100644 --- a/app/admin/controller/system/Quick.php +++ b/app/admin/controller/system/Quick.php @@ -6,8 +6,8 @@ namespace app\admin\controller\system; use app\admin\model\SystemQuick; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use think\App; /** diff --git a/app/admin/controller/system/Uploadfile.php b/app/admin/controller/system/Uploadfile.php index 87e6888..192bee3 100644 --- a/app/admin/controller/system/Uploadfile.php +++ b/app/admin/controller/system/Uploadfile.php @@ -6,8 +6,8 @@ namespace app\admin\controller\system; use app\admin\model\SystemUploadfile; use app\common\controller\AdminController; -use EasyAdmin\annotation\ControllerAnnotation; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\ControllerAnnotation; +use app\admin\service\annotation\NodeAnotation; use think\App; /** diff --git a/app/admin/service/NodeService.php b/app/admin/service/NodeService.php index 6033bd4..ab32fb7 100644 --- a/app/admin/service/NodeService.php +++ b/app/admin/service/NodeService.php @@ -4,7 +4,7 @@ namespace app\admin\service; -use EasyAdmin\auth\Node; +use app\admin\service\node\Node; class NodeService { diff --git a/app/admin/service/annotation/ControllerAnnotation.php b/app/admin/service/annotation/ControllerAnnotation.php new file mode 100644 index 0000000..fe7405d --- /dev/null +++ b/app/admin/service/annotation/ControllerAnnotation.php @@ -0,0 +1,49 @@ +basePath = $basePath; + $this->baseNamespace = $baseNamespace; + return $this; + } + + /** + * 获取所有节点 + * @return array + * @throws \Doctrine\Common\Annotations\AnnotationException + * @throws \ReflectionException + */ + public function getNodelist() + { + list($nodeList, $controllerList) = [[], $this->getControllerList()]; + + if (!empty($controllerList)) { + AnnotationRegistry::registerLoader('class_exists'); + $parser = new DocParser(); + $parser->setIgnoreNotImportedAnnotations(true); + $reader = new AnnotationReader($parser); + + foreach ($controllerList as $controllerFormat => $controller) { + + // 获取类和方法的注释信息 + $reflectionClass = new \ReflectionClass($controller); + $methods = $reflectionClass->getMethods(); + $actionList = []; + + // 遍历读取所有方法的注释的参数信息 + foreach ($methods as $method) { + // 读取NodeAnotation的注解 + $nodeAnnotation = $reader->getMethodAnnotation($method, NodeAnotation::class); + if (!empty($nodeAnnotation) && !empty($nodeAnnotation->title)) { + $actionTitle = !empty($nodeAnnotation) && !empty($nodeAnnotation->title) ? $nodeAnnotation->title : null; + $actionAuth = !empty($nodeAnnotation) && !empty($nodeAnnotation->auth) ? $nodeAnnotation->auth : false; + $actionList[] = [ + 'node' => $controllerFormat . '/' . $method->name, + 'title' => $actionTitle, + 'is_auth' => $actionAuth, + 'type' => 2, + ]; + } + } + + // 方法非空才读取控制器注解 + if (!empty($actionList)) { + // 读取Controller的注解 + $controllerAnnotation = $reader->getClassAnnotation($reflectionClass, ControllerAnnotation::class); + $controllerTitle = !empty($controllerAnnotation) && !empty($controllerAnnotation->title) ? $controllerAnnotation->title : null; + $controllerAuth = !empty($controllerAnnotation) && !empty($controllerAnnotation->auth) ? $controllerAnnotation->auth : false; + $nodeList[] = [ + 'node' => $controllerFormat, + 'title' => $controllerTitle, + 'is_auth' => $controllerAuth, + 'type' => 1, + ]; + $nodeList = array_merge($nodeList, $actionList); + } + } + } + return $nodeList; + } + + /** + * 获取所有控制器 + * @return array + */ + public function getControllerList() + { + return $this->readControllerFiles($this->basePath); + } + + /** + * 遍历读取控制器文件 + * @param $path + * @return array + */ + protected function readControllerFiles($path) + { + list($list, $temp_list, $dirExplode) = [[], scandir($path), explode($this->basePath, $path)]; + $middleDir = isset($dirExplode[1]) && !empty($dirExplode[1]) ? str_replace('/', '\\', substr($dirExplode[1], 1)) . "\\" : null; + + foreach ($temp_list as $file) { + // 排除根目录和没有开启注解的模块 + if ($file == ".." || $file == ".") { + continue; + } + if (is_dir($path . DIRECTORY_SEPARATOR . $file)) { + // 子文件夹,进行递归 + $childFiles = $this->readControllerFiles($path . DIRECTORY_SEPARATOR . $file); + $list = array_merge($childFiles, $list); + } else { + // 判断是不是控制器 + $fileExplodeArray = explode('.', $file); + if (count($fileExplodeArray) != 2 || end($fileExplodeArray) != 'php') { + continue; + } + // 根目录下的文件 + $className = str_replace('.php', '', $file); + $controllerFormat = str_replace('\\', '.', $middleDir) . Str::snake(lcfirst($className)); + $list[$controllerFormat] = "{$this->baseNamespace}\\{$middleDir}" . $className; + } + } + return $list; + } +} diff --git a/app/admin/traits/Curd.php b/app/admin/traits/Curd.php index 5630120..80f6bd5 100644 --- a/app/admin/traits/Curd.php +++ b/app/admin/traits/Curd.php @@ -3,7 +3,7 @@ namespace app\admin\traits; -use EasyAdmin\annotation\NodeAnotation; +use app\admin\service\annotation\NodeAnotation; /** diff --git a/view/index/welcome.html b/view/index/welcome.html index 4583cdb..76e5044 100644 --- a/view/index/welcome.html +++ b/view/index/welcome.html @@ -40,8 +40,9 @@

{$data.description|default=''}

+ 后台 起步 - + Gitee