mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-08 19:12:48 +08:00
引入格式化工具配置;节点管理新增挂载到控制器注解中的节点;
This commit is contained in:
133
.php-cs-fixer.php
Normal file
133
.php-cs-fixer.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return (new PhpCsFixer\Config())
|
||||||
|
->setRules([
|
||||||
|
'@PSR12:risky' => true,
|
||||||
|
'array_syntax' => ['syntax' => 'short'],
|
||||||
|
'binary_operator_spaces' => [
|
||||||
|
'default' => 'single_space',
|
||||||
|
'operators' => ['=>' => 'single_space'],
|
||||||
|
],
|
||||||
|
'blank_line_after_namespace' => true,
|
||||||
|
'array_indentation' => true,
|
||||||
|
'blank_line_after_opening_tag' => true,
|
||||||
|
'blank_line_before_statement' => [
|
||||||
|
'statements' => ['return'],
|
||||||
|
],
|
||||||
|
'braces' => true,
|
||||||
|
'cast_spaces' => true,
|
||||||
|
'class_attributes_separation' => [
|
||||||
|
'elements' => [
|
||||||
|
'method' => 'one',
|
||||||
|
'trait_import' => 'none',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'class_definition' => true,
|
||||||
|
'concat_space' => [
|
||||||
|
'spacing' => 'one',
|
||||||
|
],
|
||||||
|
'declare_equal_normalize' => true,
|
||||||
|
'elseif' => true,
|
||||||
|
'encoding' => true,
|
||||||
|
'full_opening_tag' => true,
|
||||||
|
'fully_qualified_strict_types' => true,
|
||||||
|
'function_declaration' => true,
|
||||||
|
'function_typehint_space' => true,
|
||||||
|
'heredoc_to_nowdoc' => true,
|
||||||
|
'include' => true,
|
||||||
|
'increment_style' => ['style' => 'post'],
|
||||||
|
'indentation_type' => true,
|
||||||
|
'linebreak_after_opening_tag' => true,
|
||||||
|
'line_ending' => true,
|
||||||
|
'lowercase_cast' => true,
|
||||||
|
'constant_case' => true,
|
||||||
|
'lowercase_keywords' => true,
|
||||||
|
'lowercase_static_reference' => true,
|
||||||
|
'magic_method_casing' => true,
|
||||||
|
'magic_constant_casing' => true,
|
||||||
|
'method_argument_space' => true,
|
||||||
|
'native_function_casing' => true,
|
||||||
|
'no_alias_functions' => true,
|
||||||
|
'no_extra_blank_lines' => [
|
||||||
|
'tokens' => [
|
||||||
|
'extra',
|
||||||
|
'throw',
|
||||||
|
'use',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'no_blank_lines_after_class_opening' => true,
|
||||||
|
'no_blank_lines_after_phpdoc' => true,
|
||||||
|
'no_closing_tag' => true,
|
||||||
|
'no_empty_phpdoc' => true,
|
||||||
|
'no_empty_statement' => true,
|
||||||
|
'no_leading_import_slash' => true,
|
||||||
|
'no_leading_namespace_whitespace' => true,
|
||||||
|
'no_mixed_echo_print' => [
|
||||||
|
'use' => 'echo',
|
||||||
|
],
|
||||||
|
'no_multiline_whitespace_around_double_arrow' => true,
|
||||||
|
'multiline_whitespace_before_semicolons' => [
|
||||||
|
'strategy' => 'no_multi_line',
|
||||||
|
],
|
||||||
|
'no_short_bool_cast' => true,
|
||||||
|
'no_singleline_whitespace_before_semicolons' => true,
|
||||||
|
'no_spaces_after_function_name' => true,
|
||||||
|
'no_spaces_around_offset' => true,
|
||||||
|
'no_spaces_inside_parenthesis' => true,
|
||||||
|
'no_trailing_comma_in_list_call' => true,
|
||||||
|
'no_trailing_comma_in_singleline_array' => true,
|
||||||
|
'no_trailing_whitespace' => true,
|
||||||
|
'no_trailing_whitespace_in_comment' => true,
|
||||||
|
'no_unneeded_control_parentheses' => true,
|
||||||
|
'no_unreachable_default_argument_value' => true,
|
||||||
|
'no_useless_return' => true,
|
||||||
|
'no_whitespace_before_comma_in_array' => true,
|
||||||
|
'no_whitespace_in_blank_line' => true,
|
||||||
|
'normalize_index_brace' => true,
|
||||||
|
'not_operator_with_successor_space' => false,
|
||||||
|
'object_operator_without_whitespace' => true,
|
||||||
|
'ordered_imports' => ['sort_algorithm' => 'alpha'],
|
||||||
|
'phpdoc_indent' => true,
|
||||||
|
'general_phpdoc_tag_rename' => true,
|
||||||
|
'phpdoc_inline_tag_normalizer' => true,
|
||||||
|
'phpdoc_tag_type' => true,
|
||||||
|
'phpdoc_no_access' => true,
|
||||||
|
'phpdoc_no_package' => true,
|
||||||
|
'phpdoc_no_useless_inheritdoc' => true,
|
||||||
|
'phpdoc_scalar' => true,
|
||||||
|
'phpdoc_single_line_var_spacing' => true,
|
||||||
|
'phpdoc_summary' => true,
|
||||||
|
'phpdoc_to_comment' => true,
|
||||||
|
'phpdoc_trim' => true,
|
||||||
|
'phpdoc_types' => true,
|
||||||
|
'phpdoc_var_without_name' => true,
|
||||||
|
'psr_autoloading' => true,
|
||||||
|
'self_accessor' => false,
|
||||||
|
'short_scalar_cast' => true,
|
||||||
|
'simplified_null_return' => false,
|
||||||
|
'single_blank_line_at_eof' => true,
|
||||||
|
'single_blank_line_before_namespace' => true,
|
||||||
|
'single_class_element_per_statement' => true,
|
||||||
|
'single_import_per_statement' => true,
|
||||||
|
'single_line_after_imports' => true,
|
||||||
|
'single_line_comment_style' => [
|
||||||
|
'comment_types' => ['hash'],
|
||||||
|
],
|
||||||
|
'single_quote' => true,
|
||||||
|
'space_after_semicolon' => true,
|
||||||
|
'standardize_not_equals' => true,
|
||||||
|
'switch_case_semicolon_to_colon' => true,
|
||||||
|
'switch_case_space' => true,
|
||||||
|
'ternary_operator_spaces' => true,
|
||||||
|
'trailing_comma_in_multiline' => true,
|
||||||
|
'trim_array_spaces' => true,
|
||||||
|
'unary_operator_spaces' => true,
|
||||||
|
'visibility_required' => [
|
||||||
|
'elements' => ['method', 'property'],
|
||||||
|
],
|
||||||
|
'whitespace_after_comma_in_array' => true,
|
||||||
|
'no_unused_imports' => true,
|
||||||
|
|
||||||
|
])
|
||||||
|
// ->setIndent("\t")
|
||||||
|
->setLineEnding("\n");
|
||||||
@@ -1,32 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace app\admin\controller\system;
|
namespace app\admin\controller\system;
|
||||||
|
|
||||||
|
|
||||||
use app\admin\model\SystemAdmin;
|
use app\admin\model\SystemAdmin;
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
use app\admin\service\TriggerService;
|
use app\admin\service\TriggerService;
|
||||||
use app\common\constants\AdminConstant;
|
use app\common\constants\AdminConstant;
|
||||||
use app\common\controller\AdminController;
|
use app\common\controller\AdminController;
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
|
||||||
use think\App;
|
use think\App;
|
||||||
use think\facade\Validate;
|
use think\facade\Validate;
|
||||||
use think\validate\ValidateRule;
|
use think\validate\ValidateRule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Admin
|
* Class Admin.
|
||||||
* @package app\admin\controller\system
|
|
||||||
* @ControllerAnnotation(title="管理员管理")
|
* @ControllerAnnotation(title="管理员管理")
|
||||||
|
*
|
||||||
|
* @NodeAnotation(title="自定义权限标识符",name="customFlag")
|
||||||
*/
|
*/
|
||||||
class Admin extends AdminController
|
class Admin extends AdminController
|
||||||
{
|
{
|
||||||
|
|
||||||
use \app\admin\traits\Curd;
|
use \app\admin\traits\Curd;
|
||||||
|
|
||||||
protected $sort = [
|
protected $sort = [
|
||||||
'sort' => 'desc',
|
'sort' => 'desc',
|
||||||
'id' => 'desc',
|
'id' => 'desc',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
@@ -37,6 +35,8 @@ class Admin extends AdminController
|
|||||||
|
|
||||||
$this->setDataBrage('count', 10);
|
$this->setDataBrage('count', 10);
|
||||||
$this->setDataBrage('tips', '请谨慎操作');
|
$this->setDataBrage('tips', '请谨慎操作');
|
||||||
|
|
||||||
|
$this->setDataBrage('adminCustomFlag', $this->checkAuth('system.admin/customFlag', false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,13 +59,15 @@ class Admin extends AdminController
|
|||||||
->order($this->sort)
|
->order($this->sort)
|
||||||
->select();
|
->select();
|
||||||
$data = [
|
$data = [
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '',
|
'msg' => '',
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
'data' => $list,
|
'data' => $list,
|
||||||
];
|
];
|
||||||
|
|
||||||
return json($data);
|
return json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,10 +84,7 @@ class Admin extends AdminController
|
|||||||
$post['password'] = password(sysconfig('site', 'site_default_password', '123456'));
|
$post['password'] = password(sysconfig('site', 'site_default_password', '123456'));
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$model_admin = SystemAdmin::where('username', $post['username'])->find();
|
$model_admin = SystemAdmin::where('username', $post['username'])->find();
|
||||||
|
|
||||||
if (!empty($model_admin)) {
|
if (!empty($model_admin)) {
|
||||||
@@ -98,6 +97,7 @@ class Admin extends AdminController
|
|||||||
}
|
}
|
||||||
$save ? $this->success('保存成功') : $this->error('保存失败');
|
$save ? $this->success('保存成功') : $this->error('保存失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +127,7 @@ class Admin extends AdminController
|
|||||||
}
|
}
|
||||||
$row->auth_ids = explode(',', $row->auth_ids);
|
$row->auth_ids = explode(',', $row->auth_ids);
|
||||||
$this->assign('row', $row);
|
$this->assign('row', $row);
|
||||||
|
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +142,7 @@ class Admin extends AdminController
|
|||||||
$this->checkPostRequest();
|
$this->checkPostRequest();
|
||||||
$post = $this->request->post();
|
$post = $this->request->post();
|
||||||
$rule = [
|
$rule = [
|
||||||
'password|登录密码' => 'require',
|
'password|登录密码' => 'require',
|
||||||
'password_again|确认密码' => 'require',
|
'password_again|确认密码' => 'require',
|
||||||
];
|
];
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
@@ -159,6 +160,7 @@ class Admin extends AdminController
|
|||||||
}
|
}
|
||||||
$row->auth_ids = explode(',', $row->auth_ids);
|
$row->auth_ids = explode(',', $row->auth_ids);
|
||||||
$this->assign('row', $row);
|
$this->assign('row', $row);
|
||||||
|
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,9 +194,9 @@ class Admin extends AdminController
|
|||||||
$this->checkPostRequest();
|
$this->checkPostRequest();
|
||||||
$post = $this->request->post();
|
$post = $this->request->post();
|
||||||
$rule = [
|
$rule = [
|
||||||
'id|ID' => 'require',
|
'id|ID' => 'require',
|
||||||
'field|字段' => 'require',
|
'field|字段' => 'require',
|
||||||
'value|值' => 'require',
|
'value|值' => 'require',
|
||||||
];
|
];
|
||||||
$this->validate($post, $rule);
|
$this->validate($post, $rule);
|
||||||
if (!in_array($post['field'], $this->allowModifyFields)) {
|
if (!in_array($post['field'], $this->allowModifyFields)) {
|
||||||
|
|||||||
@@ -12,11 +12,10 @@
|
|||||||
|
|
||||||
namespace app\admin\service\annotation;
|
namespace app\admin\service\annotation;
|
||||||
|
|
||||||
|
|
||||||
use Doctrine\Common\Annotations\Annotation\Attributes;
|
use Doctrine\Common\Annotations\Annotation\Attributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建节点注解类
|
* 创建节点注解类.
|
||||||
*
|
*
|
||||||
* @Annotation
|
* @Annotation
|
||||||
* @Target({"METHOD","CLASS"})
|
* @Target({"METHOD","CLASS"})
|
||||||
@@ -26,19 +25,23 @@ use Doctrine\Common\Annotations\Annotation\Attributes;
|
|||||||
*/
|
*/
|
||||||
final class NodeAnotation
|
final class NodeAnotation
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 节点名称
|
* 节点名称.
|
||||||
* @Required()
|
* @Required()
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $title;
|
public $title;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否开启权限控制
|
* 是否开启权限控制.
|
||||||
* @Enum({true,false})
|
* @Enum({true,false})
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $auth = true;
|
public $auth = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点 一般无需设置.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $name;
|
||||||
}
|
}
|
||||||
@@ -12,20 +12,19 @@
|
|||||||
|
|
||||||
namespace app\admin\service\node;
|
namespace app\admin\service\node;
|
||||||
|
|
||||||
|
use app\admin\service\annotation\ControllerAnnotation;
|
||||||
|
use app\admin\service\annotation\NodeAnotation;
|
||||||
use Doctrine\Common\Annotations\AnnotationReader;
|
use Doctrine\Common\Annotations\AnnotationReader;
|
||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||||
use Doctrine\Common\Annotations\DocParser;
|
use Doctrine\Common\Annotations\DocParser;
|
||||||
use app\admin\service\annotation\ControllerAnnotation;
|
|
||||||
use app\admin\service\annotation\NodeAnotation;
|
|
||||||
use think\helper\Str;
|
use think\helper\Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 节点处理类
|
* 节点处理类
|
||||||
* Class Node
|
* Class Node.
|
||||||
*/
|
*/
|
||||||
class Node
|
class Node
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string 当前文件夹
|
* @var string 当前文件夹
|
||||||
*/
|
*/
|
||||||
@@ -44,13 +43,14 @@ class Node
|
|||||||
*/
|
*/
|
||||||
public function __construct($basePath, $baseNamespace)
|
public function __construct($basePath, $baseNamespace)
|
||||||
{
|
{
|
||||||
$this->basePath = $basePath;
|
$this->basePath = $basePath;
|
||||||
$this->baseNamespace = $baseNamespace;
|
$this->baseNamespace = $baseNamespace;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有节点
|
* 获取所有节点.
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \Doctrine\Common\Annotations\AnnotationException
|
* @throws \Doctrine\Common\Annotations\AnnotationException
|
||||||
* @throws \ReflectionException
|
* @throws \ReflectionException
|
||||||
@@ -66,24 +66,43 @@ class Node
|
|||||||
$reader = new AnnotationReader($parser);
|
$reader = new AnnotationReader($parser);
|
||||||
|
|
||||||
foreach ($controllerList as $controllerFormat => $controller) {
|
foreach ($controllerList as $controllerFormat => $controller) {
|
||||||
|
|
||||||
// 获取类和方法的注释信息
|
// 获取类和方法的注释信息
|
||||||
$reflectionClass = new \ReflectionClass($controller);
|
$reflectionClass = new \ReflectionClass($controller);
|
||||||
$methods = $reflectionClass->getMethods();
|
$methods = $reflectionClass->getMethods();
|
||||||
$actionList = [];
|
$actionList = [];
|
||||||
|
|
||||||
// 遍历读取所有方法的注释的参数信息
|
// 遍历读取所有方法的注释的参数信息
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
// 读取NodeAnotation的注解
|
// 读取NodeAnotation的注解
|
||||||
$nodeAnnotation = $reader->getMethodAnnotation($method, NodeAnotation::class);
|
$nodeAnnotation = $reader->getMethodAnnotation($method, NodeAnotation::class);
|
||||||
if (!empty($nodeAnnotation) && !empty($nodeAnnotation->title)) {
|
if (!empty($nodeAnnotation) && !empty($nodeAnnotation->title)) {
|
||||||
$actionTitle = !empty($nodeAnnotation) && !empty($nodeAnnotation->title) ? $nodeAnnotation->title : null;
|
$actionTitle = !empty($nodeAnnotation) && !empty($nodeAnnotation->title) ? $nodeAnnotation->title : null;
|
||||||
$actionAuth = !empty($nodeAnnotation) && !empty($nodeAnnotation->auth) ? $nodeAnnotation->auth : false;
|
$actionAuth = !empty($nodeAnnotation) && !empty($nodeAnnotation->auth) ? $nodeAnnotation->auth : false;
|
||||||
|
|
||||||
|
$method_name = $nodeAnnotation->name;
|
||||||
|
|
||||||
|
if (empty($method_name)) {
|
||||||
|
$method_name = $method->name;
|
||||||
|
}
|
||||||
|
|
||||||
$actionList[] = [
|
$actionList[] = [
|
||||||
'node' => $controllerFormat . '/' . $method->name,
|
'node' => $controllerFormat . '/' . $method_name,
|
||||||
'title' => $actionTitle,
|
'title' => $actionTitle,
|
||||||
'is_auth' => $actionAuth,
|
'is_auth' => $actionAuth,
|
||||||
'type' => 2,
|
'type' => 2,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取挂载到控制器注解中的节点
|
||||||
|
$nodeAnnotationInController = $reader->getClassAnnotations($reflectionClass);
|
||||||
|
foreach ($nodeAnnotationInController as $nodeAnnotation) {
|
||||||
|
if ($nodeAnnotation instanceof NodeAnotation) {
|
||||||
|
$actionList[] = [
|
||||||
|
'node' => $controllerFormat . '/' . $nodeAnnotation->name,
|
||||||
|
'title' => $nodeAnnotation->title,
|
||||||
|
'is_auth' => $nodeAnnotation->auth,
|
||||||
|
'type' => 2,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,23 +111,24 @@ class Node
|
|||||||
if (!empty($actionList)) {
|
if (!empty($actionList)) {
|
||||||
// 读取Controller的注解
|
// 读取Controller的注解
|
||||||
$controllerAnnotation = $reader->getClassAnnotation($reflectionClass, ControllerAnnotation::class);
|
$controllerAnnotation = $reader->getClassAnnotation($reflectionClass, ControllerAnnotation::class);
|
||||||
$controllerTitle = !empty($controllerAnnotation) && !empty($controllerAnnotation->title) ? $controllerAnnotation->title : null;
|
$controllerTitle = !empty($controllerAnnotation) && !empty($controllerAnnotation->title) ? $controllerAnnotation->title : null;
|
||||||
$controllerAuth = !empty($controllerAnnotation) && !empty($controllerAnnotation->auth) ? $controllerAnnotation->auth : false;
|
$controllerAuth = !empty($controllerAnnotation) && !empty($controllerAnnotation->auth) ? $controllerAnnotation->auth : false;
|
||||||
$nodeList[] = [
|
$nodeList[] = [
|
||||||
'node' => $controllerFormat,
|
'node' => $controllerFormat,
|
||||||
'title' => $controllerTitle,
|
'title' => $controllerTitle,
|
||||||
'is_auth' => $controllerAuth,
|
'is_auth' => $controllerAuth,
|
||||||
'type' => 1,
|
'type' => 1,
|
||||||
];
|
];
|
||||||
$nodeList = array_merge($nodeList, $actionList);
|
$nodeList = array_merge($nodeList, $actionList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $nodeList;
|
return $nodeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有控制器
|
* 获取所有控制器.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getControllerList()
|
public function getControllerList()
|
||||||
@@ -117,20 +137,18 @@ class Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 遍历读取控制器文件
|
* 遍历读取控制器文件.
|
||||||
* @param $path
|
* @param $path
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function readControllerFiles($path)
|
protected function readControllerFiles($path)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
list($list, $temp_list, $dirExplode) = [[], scandir($path), explode($this->basePath, $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)) . "\\" : '';
|
$middleDir = isset($dirExplode[1]) && !empty($dirExplode[1]) ? str_replace('/', '\\', substr($dirExplode[1], 1)) . '\\' : '';
|
||||||
|
|
||||||
foreach ($temp_list as $file) {
|
foreach ($temp_list as $file) {
|
||||||
// 排除根目录和没有开启注解的模块
|
// 排除根目录和没有开启注解的模块
|
||||||
if ($file == ".." || $file == ".") {
|
if ($file == '..' || $file == '.') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DIRECTORY_SEPARATOR . $file)) {
|
if (is_dir($path . DIRECTORY_SEPARATOR . $file)) {
|
||||||
@@ -147,7 +165,6 @@ class Node
|
|||||||
$className = str_replace('.php', '', $file);
|
$className = str_replace('.php', '', $file);
|
||||||
$controllerFormat = str_replace('\\', '.', $middleDir) . Str::snake(lcfirst($className));
|
$controllerFormat = str_replace('\\', '.', $middleDir) . Str::snake(lcfirst($className));
|
||||||
|
|
||||||
|
|
||||||
$list[$controllerFormat] = "{$this->baseNamespace}\\{$middleDir}" . $className;
|
$list[$controllerFormat] = "{$this->baseNamespace}\\{$middleDir}" . $className;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace app\common\controller;
|
namespace app\common\controller;
|
||||||
|
|
||||||
use app\admin\model\SystemAdmin;
|
use app\admin\model\SystemAdmin;
|
||||||
@@ -14,23 +12,21 @@ use think\Model;
|
|||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AdminController
|
* Class AdminController.
|
||||||
* @package app\common\controller
|
|
||||||
*/
|
*/
|
||||||
class AdminController extends BaseController
|
class AdminController extends BaseController
|
||||||
{
|
{
|
||||||
|
|
||||||
use \app\common\traits\JumpTrait;
|
use \app\common\traits\JumpTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前模型
|
* 当前模型.
|
||||||
* @Model
|
* @Model
|
||||||
* @var object
|
* @var object
|
||||||
*/
|
*/
|
||||||
protected $model;
|
protected $model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段排序
|
* 字段排序.
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $sort = [
|
protected $sort = [
|
||||||
@@ -38,7 +34,7 @@ class AdminController extends BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 允许修改的字段
|
* 允许修改的字段.
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $allowModifyFields = [
|
protected $allowModifyFields = [
|
||||||
@@ -51,31 +47,31 @@ class AdminController extends BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不导出的字段信息
|
* 不导出的字段信息.
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $noExportFields = ['delete_time', 'update_time'];
|
protected $noExportFields = ['delete_time', 'update_time'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下拉选择条件
|
* 下拉选择条件.
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $selectWhere = [];
|
protected $selectWhere = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否关联查询
|
* 是否关联查询.
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
protected $relationSearch = false;
|
protected $relationSearch = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板布局, false取消
|
* 模板布局, false取消.
|
||||||
* @var string|bool
|
* @var string|bool
|
||||||
*/
|
*/
|
||||||
protected $layout = 'layout/default';
|
protected $layout = 'layout/default';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为演示环境
|
* 是否为演示环境.
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
protected $isDemo = false;
|
protected $isDemo = false;
|
||||||
@@ -94,20 +90,20 @@ class AdminController extends BaseController
|
|||||||
protected $batchValidate = false;
|
protected $batchValidate = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出文件的名称,支持中文,为空则获取模型名称
|
* 导出文件的名称,支持中文,为空则获取模型名称.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $exportFileName = null;
|
protected $exportFileName = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前登陆的管理员
|
* 当前登陆的管理员.
|
||||||
* @var SystemAdmin
|
* @var SystemAdmin
|
||||||
*/
|
*/
|
||||||
protected $sessionAdmin;
|
protected $sessionAdmin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化方法
|
* 初始化方法.
|
||||||
*/
|
*/
|
||||||
protected function initialize()
|
protected function initialize()
|
||||||
{
|
{
|
||||||
@@ -137,7 +133,6 @@ class AdminController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function assign($name, $value = null, $isAppendToDataBrage = false)
|
public function assign($name, $value = null, $isAppendToDataBrage = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($isAppendToDataBrage) {
|
if ($isAppendToDataBrage) {
|
||||||
$this->dataBrage[$name] = $value;
|
$this->dataBrage[$name] = $value;
|
||||||
}
|
}
|
||||||
@@ -146,21 +141,20 @@ class AdminController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析和获取模板内容 用于输出
|
* 解析和获取模板内容 用于输出.
|
||||||
* @param string $template
|
* @param string $template
|
||||||
* @param array $vars
|
* @param array $vars
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function fetch($template = '', $vars = [])
|
public function fetch($template = '', $vars = [])
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->assign('data_brage', json_encode($this->dataBrage));
|
$this->assign('data_brage', json_encode($this->dataBrage));
|
||||||
|
|
||||||
return $this->app->view->fetch($template, $vars);
|
return $this->app->view->fetch($template, $vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置dataBrage数据
|
* 设置dataBrage数据.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
@@ -174,7 +168,7 @@ class AdminController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重写验证规则
|
* 重写验证规则.
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param array|string $validate
|
* @param array|string $validate
|
||||||
* @param array $message
|
* @param array $message
|
||||||
@@ -184,7 +178,6 @@ class AdminController extends BaseController
|
|||||||
public function validate(array $data, $validate, array $message = [], bool $batch = null)
|
public function validate(array $data, $validate, array $message = [], bool $batch = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$message = array_merge($this->validateMessage, $message);
|
$message = array_merge($this->validateMessage, $message);
|
||||||
|
|
||||||
if (is_null($batch)) {
|
if (is_null($batch)) {
|
||||||
@@ -200,7 +193,7 @@ class AdminController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->validateRule->failException(true)->check($data);
|
$this->validateRule->failException(true)->check($data);
|
||||||
} else if (is_array($this->validateRule)) {
|
} elseif (is_array($this->validateRule)) {
|
||||||
parent::validate($data, $this->validateRule, $message, $batch);
|
parent::validate($data, $this->validateRule, $message, $batch);
|
||||||
} else {
|
} else {
|
||||||
parent::validate($data, $validate, $message, $batch);
|
parent::validate($data, $validate, $message, $batch);
|
||||||
@@ -208,11 +201,12 @@ class AdminController extends BaseController
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建请求参数
|
* 构建请求参数.
|
||||||
* @param array $excludeFields 忽略构建搜索的字段
|
* @param array $excludeFields 忽略构建搜索的字段
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -290,11 +284,12 @@ class AdminController extends BaseController
|
|||||||
$where[] = [$key, $op, "%{$val}"];
|
$where[] = [$key, $op, "%{$val}"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [$page, $limit, $where, $excludes, $request_options, $group];
|
return [$page, $limit, $where, $excludes, $request_options, $group];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下拉选择列表
|
* 下拉选择列表.
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function selectList()
|
public function selectList()
|
||||||
@@ -308,7 +303,7 @@ class AdminController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化视图参数
|
* 初始化视图参数.
|
||||||
*/
|
*/
|
||||||
private function viewInit()
|
private function viewInit()
|
||||||
{
|
{
|
||||||
@@ -323,33 +318,38 @@ class AdminController extends BaseController
|
|||||||
$adminModuleName = config('app.admin_alias_name');
|
$adminModuleName = config('app.admin_alias_name');
|
||||||
$isSuperAdmin = session('admin.id') == AdminConstant::SUPER_ADMIN_ID ? true : false;
|
$isSuperAdmin = session('admin.id') == AdminConstant::SUPER_ADMIN_ID ? true : false;
|
||||||
$data = [
|
$data = [
|
||||||
'adminModuleName' => $adminModuleName,
|
'adminModuleName' => $adminModuleName,
|
||||||
'thisController' => parse_name($thisController),
|
'thisController' => parse_name($thisController),
|
||||||
'thisAction' => $thisAction,
|
'thisAction' => $thisAction,
|
||||||
'thisRequest' => parse_name("{$thisModule}/{$thisController}/{$thisAction}"),
|
'thisRequest' => parse_name("{$thisModule}/{$thisController}/{$thisAction}"),
|
||||||
'thisControllerJsPath' => "{$thisControllerJsPath}",
|
'thisControllerJsPath' => "{$thisControllerJsPath}",
|
||||||
'autoloadJs' => $autoloadJs,
|
'autoloadJs' => $autoloadJs,
|
||||||
'isSuperAdmin' => $isSuperAdmin,
|
'isSuperAdmin' => $isSuperAdmin,
|
||||||
'version' => env('app_debug') ? time() : sysconfig('site', 'site_version')
|
'version' => env('app_debug') ? time() : sysconfig('site', 'site_version'),
|
||||||
];
|
];
|
||||||
|
|
||||||
View::assign($data);
|
View::assign($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测权限
|
* 检测权限.
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
private function checkAuth()
|
protected function checkAuth($currentNode = null, $haltRequest = true)
|
||||||
{
|
{
|
||||||
$adminConfig = config('admin');
|
$adminConfig = config('admin');
|
||||||
$adminId = session('admin.id');
|
$adminId = session('admin.id');
|
||||||
$expireTime = session('admin.expire_time');
|
$expireTime = session('admin.expire_time');
|
||||||
/** @var AuthService $authService */
|
/** @var AuthService $authService */
|
||||||
$authService = app(AuthService::class, ['adminId' => $adminId]);
|
$authService = app(AuthService::class, ['adminId' => $adminId]);
|
||||||
|
|
||||||
$currentNode = $authService->getCurrentNode();
|
$currentNode = $authService->getCurrentNode();
|
||||||
|
if (is_null($currentNode)) {
|
||||||
|
$currentNode = $authService->getCurrentNode();
|
||||||
|
}
|
||||||
|
|
||||||
$currentController = parse_name(app()->request->controller());
|
$currentController = parse_name(app()->request->controller());
|
||||||
|
|
||||||
// 验证登录
|
// 验证登录
|
||||||
@@ -372,7 +372,14 @@ class AdminController extends BaseController
|
|||||||
!in_array($currentNode, $adminConfig['no_auth_node'])
|
!in_array($currentNode, $adminConfig['no_auth_node'])
|
||||||
) {
|
) {
|
||||||
$check = $authService->checkNode($currentNode);
|
$check = $authService->checkNode($currentNode);
|
||||||
!$check && $this->error('无权限访问');
|
|
||||||
|
if ($haltRequest) {
|
||||||
|
if (!$check) {
|
||||||
|
$this->error('无权限访问');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $check;
|
||||||
|
}
|
||||||
|
|
||||||
// 判断是否为演示环境
|
// 判断是否为演示环境
|
||||||
if (env('adminsystem.is_demo', false) && app()->request->isPost()) {
|
if (env('adminsystem.is_demo', false) && app()->request->isPost()) {
|
||||||
@@ -380,11 +387,11 @@ class AdminController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$model_admin = SystemAdmin::autoCache('read',$adminId)->find($adminId);
|
$model_admin = SystemAdmin::autoCache('read', $adminId)->find($adminId);
|
||||||
|
|
||||||
$this->sessionAdmin = $model_admin;
|
$this->sessionAdmin = $model_admin;
|
||||||
|
|
||||||
$this->assign('session_admin',$model_admin);
|
$this->assign('session_admin', $model_admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -393,7 +400,7 @@ class AdminController extends BaseController
|
|||||||
protected function checkPostRequest()
|
protected function checkPostRequest()
|
||||||
{
|
{
|
||||||
if (!$this->request->isPost()) {
|
if (!$this->request->isPost()) {
|
||||||
$this->error("当前请求不合法!");
|
$this->error('当前请求不合法!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
|
|||||||
var authList = ea.getDataBrage('auth_list', []);
|
var authList = ea.getDataBrage('auth_list', []);
|
||||||
var count = ea.getDataBrage('count', 0);
|
var count = ea.getDataBrage('count', 0);
|
||||||
var tips = ea.getDataBrage('tips', '');
|
var tips = ea.getDataBrage('tips', '');
|
||||||
|
var tips = ea.getDataBrage('adminCustomFlag');
|
||||||
|
|
||||||
console.log(authList);
|
console.log(authList);
|
||||||
console.log(count);
|
console.log(count);
|
||||||
|
|||||||
Reference in New Issue
Block a user