import React from 'react'; import { Modal, Button, Space, Descriptions, Tabs, Card, Typography, message } from 'antd'; import { ProxyLog } from '@/types/proxy'; const { Text, Paragraph } = Typography; interface LogDetailProps { log: ProxyLog | null; onClose: () => void; } export const LogDetail: React.FC = ({ log, onClose }) => { const renderHttpRequest = (log: ProxyLog) => { if (!log) return ''; // 构建请求头 const headers = Object.entries(log.requestHeaders || {}) .map(([key, value]) => `${key}: ${value}`) .join('\n'); // 构建完整的 HTTP 请求 return `${log.method || 'GET'} ${log.url} ${log.protocol || 'HTTP/1.1'} ${headers} ${log.requestBody || ''}`; }; const renderHttpResponse = (log: ProxyLog) => { if (!log || !log.responseHeaders) return ''; // 构建响应头 const headers = Object.entries(log.responseHeaders) .map(([key, value]) => `${key}: ${value}`) .join('\n'); // 构建完整的 HTTP 响应 return `HTTP/1.1 ${log.status === 'success' ? '200 OK' : '500 Error'} ${headers} ${log.responseBody || ''}`; }; const handleCopyRaw = () => { if (!log) return; navigator.clipboard.writeText(renderHttpRequest(log)) .then(() => message.success('已复制到剪贴板')) .catch(() => message.error('复制失败')); }; const formatProxyInfo = (log: ProxyLog) => { if (!log) return ''; return `${log.proxyName}${log.host ? ` - ${log.host}:${log.port}` : ''}`; }; return ( 复制原始数据 , ]} > {log && ( {new Date(log.timestamp).toLocaleString()} {formatProxyInfo(log)} {log.status === 'success' ? '成功' : '失败'} {log.timing?.duration}ms {log.errorMessage && ( {log.errorMessage} )}
                                            {renderHttpRequest(log)}
                                        
) }, { key: 'response', label: '响应数据', children: (
                                            {renderHttpResponse(log)}
                                        
) }, { key: 'timing', label: '性能数据', children: ( {new Date(log.timing?.startTime || 0).toLocaleString()} {new Date(log.timing?.endTime || 0).toLocaleString()} {log.timing?.duration}ms {log.ip || '-'} {log.protocol || '-'} {log.fromCache ? '是' : '否'} ) } ]} />
)}
); };