title($this->title) ->description('系统概览') ->body($this->buildDashboard()); } /** * 构建仪表板内容 * * @return Row */ protected function buildDashboard(): Row { return new Row(function (Row $row) { $adminService = new AdminService(); $dashboardData = $adminService->getDashboardData(); // 第一行:统计卡片 $row->column(12, function ($column) use ($dashboardData) { $column->append(new StatisticsWidget($dashboardData['statistics'])); }); // 第二行:系统状态和快捷操作 $row->column(8, function ($column) use ($dashboardData) { $column->append(new SystemStatusWidget($dashboardData['system'])); }); $row->column(4, function ($column) use ($dashboardData) { $column->append(new QuickActionsWidget()); }); // 第三行:系统警报(如果有) if (!empty($dashboardData['alerts'])) { $row->column(12, function ($column) use ($dashboardData) { $column->append($this->buildAlertsWidget($dashboardData['alerts'])); }); } // 第四行:最近操作 if (!empty($dashboardData['recent_actions'])) { $row->column(12, function ($column) use ($dashboardData) { $column->append($this->buildRecentActionsWidget($dashboardData['recent_actions'])); }); } }); } /** * 构建警报小部件 * * @param array $alerts * @return string */ protected function buildAlertsWidget(array $alerts): string { $html = '
'; $html .= '

系统警报

'; $html .= '
'; foreach ($alerts as $alert) { $type = $alert['type']; $title = $alert['title']; $message = $alert['message']; $timestamp = $alert['timestamp']->format('Y-m-d H:i:s'); $html .= "
"; $html .= "{$title}
"; $html .= "{$message}
"; $html .= "{$timestamp}"; $html .= "
"; } $html .= '
'; return $html; } /** * 构建最近操作小部件 * * @param array $actions * @return string */ protected function buildRecentActionsWidget(array $actions): string { $html = '
'; $html .= '

最近操作

'; $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($actions as $action) { $html .= ''; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ''; } $html .= ''; $html .= '
操作管理员时间IP地址
{$action['description']}{$action['admin_name']}{$action['timestamp']}{$action['ip_address']}
'; $html .= '
'; $html .= '
'; return $html; } /** * 获取系统状态API * * @return \Illuminate\Http\JsonResponse */ #[Get('admin/api/system-status')] public function getSystemStatus() { try { $status = $this->adminService->getSystemStatus(); return response()->json([ 'status' => 'success', 'data' => $status, ]); } catch (\Exception $e) { return response()->json([ 'status' => 'error', 'message' => $e->getMessage(), ], 500); } } /** * 刷新仪表板数据API * * @return \Illuminate\Http\JsonResponse */ #[Get('admin/api/dashboard/refresh')] public function refreshDashboard() { try { // 清理仪表板缓存 cache()->forget('admin.dashboard.data'); // 获取新数据 $data = $this->adminService->getDashboardData(); return response()->json([ 'status' => 'success', 'message' => '仪表板数据已刷新', 'data' => $data, ]); } catch (\Exception $e) { return response()->json([ 'status' => 'error', 'message' => $e->getMessage(), ], 500); } } }