日志获取注解标题

This commit is contained in:
wolfcode
2023-11-07 17:23:22 +08:00
parent 67f0c4ce53
commit 7d89af4291
2 changed files with 29 additions and 11 deletions

View File

@@ -2,10 +2,12 @@
namespace app\admin\middleware;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\SystemLogService;
use app\Request;
use app\admin\service\tool\CommonTool;
use think\facade\Log;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\DocParser;
/**
* 系统操作日志中间件
@@ -38,19 +40,34 @@ class SystemLog
$method = strtolower($request->method());
$url = $request->url();
trace([
'url' => $url,
'method' => $method,
'params' => $params,
],
'requestDebugInfo'
);
if (env('APP_DEBUG')) {
trace(['url' => $url, 'method' => $method, 'params' => $params,], 'requestDebugInfo');
}
if ($request->isAjax()) {
if (in_array($method, ['post', 'put', 'delete'])) {
$title = '';
try {
$pathInfo = $request->pathinfo();
$pathInfoExp = explode('/', $pathInfo);
$pathInfoExp = explode('.', $pathInfoExp[0] ?? '');
$_controller = $pathInfoExp[0] ?? '';
$_action = strtolower($pathInfoExp[1] ?? '');
if ($_controller && $_action) {
$className = "app\admin\controller\\{$_controller}\\{$_action}";
$reflectionClass = new \ReflectionClass($className);
$parser = new DocParser();
$parser->setIgnoreNotImportedAnnotations(true);
$reader = new AnnotationReader($parser);
$controllerAnnotation = $reader->getClassAnnotation($reflectionClass, ControllerAnnotation::class);
$title = $controllerAnnotation->title;
}
} catch (\Throwable $exception) {
}
$ip = CommonTool::getRealIp();
$data = [
'admin_id' => session('admin.id'),
'title' => $title,
'url' => $url,
'method' => $method,
'ip' => $ip,

View File

@@ -16,7 +16,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
toolbar: ['refresh', 'export'],
cols: [[
{field: 'id', width: 80, title: 'ID', search: false},
{field: 'month', title: '日志月份', hide: true, search: 'time', timeType: 'month', searchValue: util.toDateString(new Date(), 'yyyy-MM')},
{field: 'month', width: 80, title: '日志月份', hide: true, search: 'time', timeType: 'month', searchValue: util.toDateString(new Date(), 'yyyy-MM')},
{
field: 'admin.username', width: 100, title: '后台用户', search: false, templet: function (res) {
let admin = res.admin
@@ -24,8 +24,9 @@ define(["jquery", "easy-admin"], function ($, ea) {
}
},
{field: 'method', width: 100, title: '请求方法'},
{field: 'title', width: 180, title: '请求标题'},
{field: 'ip', width: 150, title: 'IP地址'},
{field: 'url', minWidth: 100, title: '路由地址', align: "left"},
{field: 'url', minWidth: 150, title: '路由地址', align: "left"},
{
field: 'content', minWidth: 200, title: '操作内容', align: "left", templet: function (res) {
let html = '<div class="layui-colla-item">' +
@@ -35,7 +36,7 @@ define(["jquery", "easy-admin"], function ($, ea) {
return '<div class="layui-collapse" lay-accordion>' + html + '</div>'
}
},
{field: 'create_time', width: 200, title: '创建时间', search: 'range'},
{field: 'create_time', minWidth: 100, title: '创建时间', search: 'range'},
]],
done: function () {
layui.element.render('collapse')