mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
将扩展中的节点功能迁移到系统项目中;
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace app\admin\service;
|
||||
|
||||
|
||||
use EasyAdmin\auth\Node;
|
||||
use app\admin\service\node\Node;
|
||||
|
||||
class NodeService
|
||||
{
|
||||
|
||||
49
app/admin/service/annotation/ControllerAnnotation.php
Normal file
49
app/admin/service/annotation/ControllerAnnotation.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\service\annotation;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
|
||||
/**
|
||||
* Class ControllerAnnotation
|
||||
*
|
||||
* @Annotation
|
||||
* @Target("CLASS")
|
||||
* @Attributes({
|
||||
* @Attribute("title", type="string"),
|
||||
* })
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class ControllerAnnotation
|
||||
{
|
||||
|
||||
/**
|
||||
* Route group prefix for the controller
|
||||
*
|
||||
* @Required()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title = '';
|
||||
|
||||
/**
|
||||
* 是否开启权限控制
|
||||
* @Enum({true,false})
|
||||
* @var bool
|
||||
*/
|
||||
public $auth = true;
|
||||
|
||||
}
|
||||
44
app/admin/service/annotation/NodeAnotation.php
Normal file
44
app/admin/service/annotation/NodeAnotation.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\service\annotation;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||
|
||||
/**
|
||||
* 创建节点注解类
|
||||
*
|
||||
* @Annotation
|
||||
* @Target({"METHOD","CLASS"})
|
||||
* @Attributes({
|
||||
* @Attribute("time", type = "int")
|
||||
* })
|
||||
*/
|
||||
final class NodeAnotation
|
||||
{
|
||||
|
||||
/**
|
||||
* 节点名称
|
||||
* @Required()
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* 是否开启权限控制
|
||||
* @Enum({true,false})
|
||||
* @var bool
|
||||
*/
|
||||
public $auth = true;
|
||||
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace {{controllerNamespace}};
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
||||
153
app/admin/service/node/Node.php
Normal file
153
app/admin/service/node/Node.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | PHP交流群: 763822524
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 https://mit-license.org
|
||||
// +----------------------------------------------------------------------
|
||||
// | github开源项目:https://github.com/zhongshaofa/EasyAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\service\node;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Doctrine\Common\Annotations\DocParser;
|
||||
use app\admin\service\annotation\ControllerAnnotation;
|
||||
use app\admin\service\annotation\NodeAnotation;
|
||||
use think\helper\Str;
|
||||
|
||||
/**
|
||||
* 节点处理类
|
||||
* Class Node
|
||||
* @package EasyAdmin\auth
|
||||
*/
|
||||
class Node
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string 当前文件夹
|
||||
*/
|
||||
protected $basePath;
|
||||
|
||||
/**
|
||||
* @var string 命名空间前缀
|
||||
*/
|
||||
protected $baseNamespace;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* Node constructor.
|
||||
* @param string $basePath 读取的文件夹
|
||||
* @param string $baseNamespace 读取的命名空间前缀
|
||||
*/
|
||||
public function __construct($basePath, $baseNamespace)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace app\admin\traits;
|
||||
|
||||
use EasyAdmin\annotation\NodeAnotation;
|
||||
use app\admin\service\annotation\NodeAnotation;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,8 +40,9 @@
|
||||
<p><i class="name img-name"></i></p>
|
||||
<p class="desc">{$data.description|default=''}</p>
|
||||
<p class="operation">
|
||||
<a class="start" href="{:__url('admin/Index/index')}"> 后台</a>
|
||||
<a class="start" target="_blank" href="http://doc.ulthon.com/home/read/ulthon_admin/home.html"> 起步 <i class="icon-play"></i></a>
|
||||
|
||||
|
||||
<a class="gitee button-grya" target="_blank" href="https://gitee.com/ulthon/ulthon_admin"><i class="icon-gitee"></i>Gitee</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user