import React, { useRef, useEffect } from 'react'; import { Table, Tag, Button, Tooltip, Empty } from 'antd'; import { ClearOutlined, CloseOutlined, BugOutlined, ClockCircleOutlined } from '@ant-design/icons'; import { useStore } from '../store'; import { normalizeOpacityForPlatform, resolveAppearanceValues } from '../utils/appearance'; interface LogPanelProps { height: number; onClose: () => void; onResizeStart: (e: React.MouseEvent) => void; } const LogPanel: React.FC = ({ height, onClose, onResizeStart }) => { const sqlLogs = useStore(state => state.sqlLogs); const clearSqlLogs = useStore(state => state.clearSqlLogs); const theme = useStore(state => state.theme); const appearance = useStore(state => state.appearance); const darkMode = theme === 'dark'; const resolvedAppearance = resolveAppearanceValues(appearance); const opacity = normalizeOpacityForPlatform(resolvedAppearance.opacity); // Background Helper const getBg = (darkHex: string) => { if (!darkMode) return `rgba(255, 255, 255, ${opacity})`; const hex = darkHex.replace('#', ''); const r = parseInt(hex.substring(0, 2), 16); const g = parseInt(hex.substring(2, 4), 16); const b = parseInt(hex.substring(4, 6), 16); return `rgba(${r}, ${g}, ${b}, ${opacity})`; }; const bgMain = getBg('#1d1d1d'); const shellOpacity = darkMode ? Math.max(0.18, opacity * 0.82) : Math.max(0.28, opacity * 0.92); const shellOpacityStrong = darkMode ? Math.max(0.22, opacity * 0.9) : Math.max(0.34, opacity * 0.96); const panelDividerColor = darkMode ? `rgba(255,255,255,${Math.max(0.04, opacity * 0.10)})` : `rgba(0,0,0,${Math.max(0.04, opacity * 0.08)})`; const panelMutedTextColor = darkMode ? 'rgba(255,255,255,0.62)' : 'rgba(0,0,0,0.58)'; const panelShellBg = darkMode ? `linear-gradient(180deg, rgba(15,20,30,${shellOpacity}) 0%, rgba(9,13,22,${shellOpacityStrong}) 100%)` : `linear-gradient(180deg, rgba(255,255,255,${shellOpacityStrong}) 0%, rgba(246,248,252,${shellOpacity}) 100%)`; const panelAccentColor = darkMode ? '#ffd666' : '#1677ff'; const panelShadow = darkMode ? `0 12px 28px rgba(0,0,0,${Math.max(0.05, opacity * 0.18)})` : `0 12px 24px rgba(15,23,42,${Math.max(0.02, opacity * 0.08)})`; const logScrollbarThumb = darkMode ? `rgba(255, 255, 255, ${Math.max(0.18, opacity * 0.34)})` : `rgba(0, 0, 0, ${Math.max(0.12, opacity * 0.26)})`; const logScrollbarThumbHover = darkMode ? `rgba(255, 255, 255, ${Math.max(0.28, opacity * 0.48)})` : `rgba(0, 0, 0, ${Math.max(0.18, opacity * 0.36)})`; const columns = [ { title: 'Time', dataIndex: 'timestamp', width: 80, render: (ts: number) => {new Date(ts).toLocaleTimeString()} }, { title: 'Status', dataIndex: 'status', width: 70, render: (status: string) => ( {status === 'success' ? 'OK' : 'ERR'} ) }, { title: 'Duration', dataIndex: 'duration', width: 70, render: (d: number) => 1000 ? 'orange' : 'inherit', fontSize: '12px' }}>{d}ms }, { title: 'SQL / Message', dataIndex: 'sql', render: (text: string, record: any) => (
{text}
{record.message &&
{record.message}
} {record.affectedRows !== undefined &&
Affected: {record.affectedRows}
}
) } ]; return (
{/* Resize Handle */}
{/* Toolbar */}
SQL 执行日志
记录执行状态、耗时与错误信息,便于快速回溯。
{/* List */}
{sqlLogs.length === 0 ? (
暂无 SQL 执行日志} />
) : ( )} ); }; export default LogPanel;