diff --git a/app/admin/middleware/SystemLog.php b/app/admin/middleware/SystemLog.php index cb3af7b..4ae2812 100644 --- a/app/admin/middleware/SystemLog.php +++ b/app/admin/middleware/SystemLog.php @@ -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, diff --git a/public/static/admin/js/system/log.js b/public/static/admin/js/system/log.js index 37d7e9d..d5c43bb 100644 --- a/public/static/admin/js/system/log.js +++ b/public/static/admin/js/system/log.js @@ -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 = '