mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
99 lines
3.2 KiB
PHP
99 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace base\common\command\admin\permission;
|
|
|
|
use app\common\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Input\Option;
|
|
use think\console\Output;
|
|
use app\admin\service\NodeService;
|
|
|
|
/**
|
|
* admin:permission:nodes command - 查看权限节点
|
|
*/
|
|
class AdminPermissionNodesBase extends Command
|
|
{
|
|
/**
|
|
* 配置命令参数
|
|
*/
|
|
protected function configure()
|
|
{
|
|
parent::configure();
|
|
|
|
// 指令配置
|
|
$this->setName('admin:permission:nodes')
|
|
->setDescription('查看权限节点')
|
|
->addOption('level', null, Option::VALUE_OPTIONAL, '按级别过滤 (1=控制器, 2=方法)')
|
|
->addOption('module', null, Option::VALUE_OPTIONAL, '按模块过滤');
|
|
}
|
|
|
|
/**
|
|
* 执行命令
|
|
*
|
|
* @param Input $input
|
|
* @param Output $output
|
|
* @return int
|
|
* @throws \Doctrine\Common\Annotations\AnnotationException
|
|
* @throws \ReflectionException
|
|
*/
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
try {
|
|
// 获取所有权限节点
|
|
$nodeService = new NodeService();
|
|
$nodeList = $nodeService->getNodelist();
|
|
|
|
// 过滤条件
|
|
$filterLevel = $input->getOption('level');
|
|
$filterModule = $input->getOption('module');
|
|
|
|
// 应用过滤
|
|
$filteredNodes = $nodeList;
|
|
if ($filterLevel !== null) {
|
|
$level = (int)$filterLevel;
|
|
$filteredNodes = array_filter($filteredNodes, function ($node) use ($level) {
|
|
return isset($node['type']) && $node['type'] === $level;
|
|
});
|
|
}
|
|
|
|
if ($filterModule !== null) {
|
|
$filteredNodes = array_filter($filteredNodes, function ($node) use ($filterModule) {
|
|
return isset($node['module']) && $node['module'] === $filterModule;
|
|
});
|
|
}
|
|
|
|
// 重新索引数组
|
|
$filteredNodes = array_values($filteredNodes);
|
|
|
|
// 输出表头
|
|
$output->info('权限节点列表');
|
|
$output->writeln('================================');
|
|
|
|
if (empty($filteredNodes)) {
|
|
$output->comment('没有找到符合条件的权限节点');
|
|
return 0;
|
|
}
|
|
|
|
// 输出权限节点信息
|
|
foreach ($filteredNodes as $node) {
|
|
$levelText = $node['type'] == 1 ? '控制器' : '方法';
|
|
$authText = isset($node['auth']) && $node['auth'] ? '是' : '否';
|
|
|
|
$output->info('节点: ' . ($node['node'] ?? ''));
|
|
$output->comment(' 标题: ' . ($node['title'] ?? ''));
|
|
$output->comment(' 级别: ' . $levelText . ' (' . ($node['type'] ?? 0) . ')');
|
|
$output->comment(' 模块: ' . ($node['module'] ?? ''));
|
|
$output->comment(' 需要授权: ' . $authText);
|
|
$output->writeln('--------------------------------');
|
|
}
|
|
|
|
$output->info('总计: ' . count($filteredNodes) . ' 个权限节点');
|
|
|
|
} catch (\Exception $e) {
|
|
$output->error('获取权限节点失败: ' . $e->getMessage());
|
|
return 1;
|
|
}
|
|
}
|
|
} |