From f56644223bd546df243b83c55e7adb6d3f6de33a Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Thu, 30 Apr 2026 14:21:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=97=A5=E5=BF=97=E5=AF=BC?= =?UTF-8?q?=E5=87=BA3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exports/OperationLogExport.php | 37 ++++++++++++++++++------------ app/Models/AdminMenu.php | 4 +++- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/Exports/OperationLogExport.php b/app/Exports/OperationLogExport.php index 412db1d..04ab0bf 100644 --- a/app/Exports/OperationLogExport.php +++ b/app/Exports/OperationLogExport.php @@ -23,15 +23,22 @@ class OperationLogExport implements FromArray, WithHeadings 'created_at' ]; $actionArr = AdminOperationLog::getActionArr(); - AdminOperationLog::all($columns)->each( + AdminOperationLog::query()->orderBy('created_at', 'desc')->select( + $columns + )->take(1)->each( function ($item) use (&$data, &$index, $actionArr) { - $username = AdminUsers::getUsername($item['user_id']); - $item['operation_name'] = $username ?? ''; - $item['action_str'] = $actionArr[$item['action']] ?? - $item['action']; - $description = __('log.' . $item['description']); - if (strpos($description, 'log.') === false) { - $item['description'] = $description; + if ($item['user_id']) { + $username = AdminUsers::getUsername($item['user_id']); + $item['operation_name'] = $username ?? ''; + } + if (isset($actionArr[$item['action']])) { + $item['action_str'] = $actionArr[$item['action']]; + } + if ($item['description']) { + $description = __('log.' . $item['description']); + if (strpos($description, 'log.') === false) { + $item['description'] = $description; + } } $item['main_directory'] = ''; if ($item['sub_directory']) { @@ -47,13 +54,13 @@ class OperationLogExport implements FromArray, WithHeadings } $data[] = [ 'id' => $index, - 'created_at' => $item['created_at'], - 'operation_name' => $item['operation_name'], - 'main_directory' => $item['main_directory'], - 'sub_directory' => $item['sub_directory'], - 'action' => $item['action'], - 'action_str' => $item['action_str'], - 'description' => $item['description'], + 'created_at' => $item['created_at'] ?? '', + 'operation_name' => $item['operation_name'] ?? '', + 'main_directory' => $item['main_directory'] ?? '', + 'sub_directory' => $item['sub_directory'] ?? '', + 'action' => $item['action'] ?? '', + 'action_str' => $item['action_str'] ?? '', + 'description' => $item['description'] ?? '', ]; $index += 1; } diff --git a/app/Models/AdminMenu.php b/app/Models/AdminMenu.php index e099da2..dd45b34 100644 --- a/app/Models/AdminMenu.php +++ b/app/Models/AdminMenu.php @@ -68,7 +68,9 @@ class AdminMenu extends Model public static function getLastParentTitle($parent_id): string { $last_parent_id = self::query()->where('id', $parent_id)->whereNull('deleted_at')->value('parent_id'); - $title = self::getTreeTitle($last_parent_id); + if ($last_parent_id) { + $title = self::getTreeTitle($last_parent_id); + } return empty($title) ? '' : __('menu.' . $title); }