feat(tools): 添加 Ulthon Admin 前端静态构建工具

- 新增 `tools:ua:build` 命令,用于合并前端模块文件
- 添加构建配置文件 `ua.build.json` 定义源文件和输出
- 引入基础服务类 `ToolsUaServiceBase` 处理路径和配置读取
- 创建命令基类 `ToolsUaBuildBase` 实现文件合并逻辑
- 注册新命令到 UlthonAdminService 服务容器
- 提供完整的模块化前端代码结构(core、common、table、listen、api、utils)
- 添加详细的使用说明文档 README.md
- 包含示例 Scheme 文件展示功能
This commit is contained in:
augushong
2026-01-30 22:24:44 +08:00
parent 0fad2b7e10
commit 9669bc61a3
14 changed files with 6564 additions and 2936 deletions

View File

@@ -0,0 +1,65 @@
<?php
namespace base\common\command\tools\ua;
use base\common\service\ToolsUaServiceBase;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
class ToolsUaBuildBase extends Command
{
protected function configure()
{
$this->setName('tools:ua:build')
->setDescription('构建 ulthon-admin 静态合并文件')
->addOption('config', null, Option::VALUE_OPTIONAL, '配置文件路径', 'public/static/plugs/ulthon-admin/ua.build.json')
->addOption('help', 'h', Option::VALUE_NONE, '显示帮助信息');
}
protected function execute(Input $input, Output $output)
{
$service = new ToolsUaServiceBase();
$configOption = $input->getOption('config');
$configPath = $service->getConfigPath($configOption);
[$ok, $config] = $service->readConfig($configPath);
if (!$ok) {
$output->writeln($config);
return 1;
}
if (!isset($config['sources']) || !is_array($config['sources']) || count($config['sources']) === 0) {
$output->writeln('配置文件 sources 不能为空');
return 1;
}
if (!isset($config['output']) || !$config['output']) {
$output->writeln('配置文件 output 不能为空');
return 1;
}
$baseDir = dirname($configPath);
$outputPath = $service->resolvePath($config['output'], $baseDir);
$contents = [];
foreach ($config['sources'] as $source) {
if (!is_string($source) || $source === '') {
$output->writeln('sources 中存在无效路径');
return 1;
}
$sourcePath = $service->resolvePath($source, $baseDir);
if (!is_file($sourcePath)) {
$output->writeln('源文件不存在: ' . $sourcePath);
return 1;
}
$contents[] = file_get_contents($sourcePath);
}
$final = implode("\n\n", $contents);
$outputDir = dirname($outputPath);
if (!is_dir($outputDir)) {
mkdir($outputDir, 0755, true);
}
file_put_contents($outputPath, $final);
$output->writeln('构建完成: ' . $outputPath);
$output->writeln('源文件数量: ' . count($contents));
$output->writeln('输出大小: ' . strlen($final));
return 0;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace base\common\service;
use think\facade\App;
class ToolsUaServiceBase
{
public function getConfigPath($configPath)
{
if ($this->isAbsolutePath($configPath)) {
return $configPath;
}
$root = App::getRootPath();
return rtrim($root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($configPath, DIRECTORY_SEPARATOR);
}
public function readConfig($configPath)
{
if (!is_file($configPath)) {
return [false, '配置文件不存在: ' . $configPath];
}
$content = file_get_contents($configPath);
$data = json_decode($content, true);
if (!$data || !is_array($data)) {
return [false, '配置文件JSON格式不正确: ' . $configPath];
}
return [true, $data];
}
public function resolvePath($path, $baseDir)
{
if ($this->isAbsolutePath($path)) {
return $path;
}
return rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
}
public function isAbsolutePath($path)
{
if ($path === '' || $path === null) {
return false;
}
if ($path[0] === '/' || $path[0] === '\\') {
return true;
}
return preg_match('/^[a-zA-Z]:[\\\\\\/]/', $path) === 1;
}
}

View File

@@ -9,6 +9,7 @@ use app\common\command\tools\db\ToolsDbExecute;
use app\common\command\tools\db\ToolsDbInfo;
use app\common\command\tools\db\ToolsDbQuery;
use app\common\command\tools\db\ToolsDbTable;
use app\common\command\tools\ua\ToolsUaBuild;
use app\common\command\Test;
use app\common\event\AdminLoginSuccess\LogEvent;
use app\common\event\AdminLoginType\DemoEvent;
@@ -64,6 +65,7 @@ class UlthonAdminService extends Service
ToolsDbInfo::class,
ToolsDbDesc::class,
ToolsDbCount::class,
ToolsUaBuild::class,
]);
// 绑定标识容器