getKey(); $backup = CleanupBackup::with('files')->find($backupId); if (!$backup) { return $this->response() ->error('备份不存在'); } $files = $backup->files; if ($files->isEmpty()) { return $this->response() ->info('该备份暂无文件'); } $html = '
'; $html .= ''; $html .= ''; $backupTypes = [1 => 'SQL', 2 => 'JSON', 3 => 'CSV']; $compressionTypes = [1 => '无压缩', 2 => 'GZIP', 3 => 'ZIP']; foreach ($files as $file) { $backupType = $backupTypes[$file->backup_type] ?? '未知'; $compressionType = $compressionTypes[$file->compression_type] ?? '未知'; $fileSize = $this->formatBytes($file->file_size); $hash = $file->file_hash ? substr($file->file_hash, 0, 16) . '...' : '-'; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; } $html .= '
表名文件名文件大小文件路径备份类型压缩类型哈希值
{$file->table_name}{$file->file_name}{$fileSize}{$file->file_path}{$backupType}{$compressionType}{$hash}
'; // 添加统计信息 $totalSize = $files->sum('file_size'); $totalFiles = $files->count(); $html .= '
'; $html .= '
'; $html .= '
' . $totalFiles . '
'; $html .= '文件总数'; $html .= '
'; $html .= '
'; $html .= '
' . $this->formatBytes($totalSize) . '
'; $html .= '文件总大小'; $html .= '
'; $html .= '
'; return $this->response() ->success('备份文件列表') ->detail($html); } catch (\Exception $e) { return $this->response() ->error('查看失败:' . $e->getMessage()); } } /** * 格式化字节大小 */ private function formatBytes($bytes) { if ($bytes == 0) return '0 B'; $units = ['B', 'KB', 'MB', 'GB', 'TB']; $base = log($bytes, 1024); $index = floor($base); if ($index >= count($units)) { $index = count($units) - 1; } $size = round(pow(1024, $base - $index), 2); return $size . ' ' . $units[$index]; } /** * 渲染按钮 */ public function render() { return << {$this->title} HTML; } }