Files
ulthon_admin/extend/base/common/command/admin/permission/AdminPermissionNodesBase.php
augushong ad96755ff5 docs(permission): 统一校准权限节点措辞,消除更新节点误解
admin:permission:nodes 是查看型命令(实时扫描注解、不写库、改注解即生效),但文档/注释多处用一键更新/自动更新/生成等动作词描述,导致开发者系统性误以为它是更新权限节点命令。本次校准 8 个文件 10 处误导措辞,并在命令输出末尾追加机制提示。@NodeAnotation 拼写保持不变(框架故意少一个 t)。
2026-08-08 18:21:25 +08:00

100 lines
3.4 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) . ' 个权限节点');
$output->writeln('提示:权限节点由框架动态扫描注解生成,修改 @NodeAnotation 注解后立即生效,无需手动更新。');
} catch (\Exception $e) {
$output->error('获取权限节点失败: ' . $e->getMessage());
return 1;
}
}
}