1.新增菜单后台操作指南,方便管理员查看使用
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\logic\system\SystemAdminGuideLogic;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 后台操作指南控制器
|
||||
*/
|
||||
class SystemAdminGuideController extends BaseController
|
||||
{
|
||||
private SystemAdminGuideLogic $guideLogic;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->guideLogic = new SystemAdminGuideLogic();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取后台操作指南 Markdown 内容
|
||||
*/
|
||||
#[Permission('后台操作指南读取', 'system:admin_guide:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$data = $this->guideLogic->read();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存后台操作指南 Markdown 内容
|
||||
*/
|
||||
#[Permission('后台操作指南保存', 'system:admin_guide:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$content = $request->post('content', '');
|
||||
if (! is_string($content)) {
|
||||
return $this->fail('invalid content');
|
||||
}
|
||||
$data = $this->guideLogic->save($content);
|
||||
return $this->success($data, 'save success');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\logic\system;
|
||||
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
|
||||
/**
|
||||
* 后台操作指南逻辑(读写 server/docs/ADMIN_GUIDE.md)
|
||||
*/
|
||||
class SystemAdminGuideLogic
|
||||
{
|
||||
private const GUIDE_FILENAME = 'ADMIN_GUIDE.md';
|
||||
|
||||
/**
|
||||
* 获取指南 Markdown 文件绝对路径
|
||||
*/
|
||||
public function getFilePath(): string
|
||||
{
|
||||
return base_path() . DIRECTORY_SEPARATOR . 'docs' . DIRECTORY_SEPARATOR . self::GUIDE_FILENAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取指南内容
|
||||
* @return array{content: string, file_path: string, update_time: string|null}
|
||||
*/
|
||||
public function read(): array
|
||||
{
|
||||
$filePath = $this->getFilePath();
|
||||
if (! is_file($filePath)) {
|
||||
throw new ApiException('admin guide file not found');
|
||||
}
|
||||
$content = file_get_contents($filePath);
|
||||
if ($content === false) {
|
||||
throw new ApiException('failed to read admin guide file');
|
||||
}
|
||||
|
||||
return [
|
||||
'content' => $content,
|
||||
'file_path' => 'docs/' . self::GUIDE_FILENAME,
|
||||
'update_time' => date('Y-m-d H:i:s', filemtime($filePath)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存指南内容到 Markdown 文件
|
||||
* @param string $content
|
||||
* @return array{content: string, file_path: string, update_time: string}
|
||||
*/
|
||||
public function save(string $content): array
|
||||
{
|
||||
$filePath = $this->getFilePath();
|
||||
$dir = dirname($filePath);
|
||||
if (! is_dir($dir) && ! mkdir($dir, 0755, true) && ! is_dir($dir)) {
|
||||
throw new ApiException('failed to create docs directory');
|
||||
}
|
||||
|
||||
$result = file_put_contents($filePath, $content, LOCK_EX);
|
||||
if ($result === false) {
|
||||
throw new ApiException('failed to save admin guide file');
|
||||
}
|
||||
|
||||
clearstatcache(true, $filePath);
|
||||
|
||||
return [
|
||||
'content' => $content,
|
||||
'file_path' => 'docs/' . self::GUIDE_FILENAME,
|
||||
'update_time' => date('Y-m-d H:i:s', filemtime($filePath)),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,10 @@ Route::group('/core', function () {
|
||||
Route::delete("/logs/deleteOperLog", [\plugin\saiadmin\app\controller\system\SystemLogController::class, 'deleteOperLog']);
|
||||
fastRoute("email", \plugin\saiadmin\app\controller\system\SystemMailController::class);
|
||||
|
||||
// 后台操作指南
|
||||
Route::get("/adminGuide/read", [\plugin\saiadmin\app\controller\system\SystemAdminGuideController::class, 'read']);
|
||||
Route::post("/adminGuide/save", [\plugin\saiadmin\app\controller\system\SystemAdminGuideController::class, 'save']);
|
||||
|
||||
// 服务管理
|
||||
Route::get("/server/monitor", [\plugin\saiadmin\app\controller\system\SystemServerController::class, 'monitor']);
|
||||
Route::get("/server/cache", [\plugin\saiadmin\app\controller\system\SystemServerController::class, 'cache']);
|
||||
|
||||
Reference in New Issue
Block a user