|
|
|
@ -6,6 +6,13 @@ import { useSelector, useDispatch } from 'react-redux';
|
|
|
|
|
|
|
|
|
|
|
|
const TabPane = Tabs.TabPane;
|
|
|
|
const TabPane = Tabs.TabPane;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface LogMessage {
|
|
|
|
|
|
|
|
id: number;
|
|
|
|
|
|
|
|
type: string;
|
|
|
|
|
|
|
|
message: string;
|
|
|
|
|
|
|
|
timestamp: string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface LogBarProps {
|
|
|
|
interface LogBarProps {
|
|
|
|
a?: string;
|
|
|
|
a?: string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -39,7 +46,7 @@ const LogBar: React.FC<LogBarProps> = () => {
|
|
|
|
const resizeBoxRef = useRef<HTMLDivElement>(null); // 引用 ResizeBox 容器
|
|
|
|
const resizeBoxRef = useRef<HTMLDivElement>(null); // 引用 ResizeBox 容器
|
|
|
|
const { logBarStatus } = useSelector((state) => state.ideContainer);
|
|
|
|
const { logBarStatus } = useSelector((state) => state.ideContainer);
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
const [validationLogs, setValidationLogs] = useState<LogMessage[]>([]);
|
|
|
|
|
|
|
|
|
|
|
|
// 处理 Tab 点击事件
|
|
|
|
// 处理 Tab 点击事件
|
|
|
|
const handleTabClick = (key: string) => {
|
|
|
|
const handleTabClick = (key: string) => {
|
|
|
|
@ -56,7 +63,6 @@ const LogBar: React.FC<LogBarProps> = () => {
|
|
|
|
|
|
|
|
|
|
|
|
// 当 collapsed 状态改变时,直接更新元素的样式
|
|
|
|
// 当 collapsed 状态改变时,直接更新元素的样式
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
|
|
|
|
if (resizeBoxRef.current) {
|
|
|
|
if (resizeBoxRef.current) {
|
|
|
|
resizeBoxRef.current.style.height = logBarStatus ? '250px' : '0px';
|
|
|
|
resizeBoxRef.current.style.height = logBarStatus ? '250px' : '0px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -76,6 +82,59 @@ const LogBar: React.FC<LogBarProps> = () => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 监听日志消息事件
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
const handleLogMessage = (event: CustomEvent) => {
|
|
|
|
|
|
|
|
const { type, message, timestamp } = event.detail;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是校验类型的消息且当前校验日志tab可见,则添加到校验日志中
|
|
|
|
|
|
|
|
if (type === 'validation') {
|
|
|
|
|
|
|
|
const newLog: LogMessage = {
|
|
|
|
|
|
|
|
id: Date.now(),
|
|
|
|
|
|
|
|
type,
|
|
|
|
|
|
|
|
message,
|
|
|
|
|
|
|
|
timestamp
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setValidationLogs(prev => [...prev, newLog]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 自动切换到校验日志tab并展开logBar
|
|
|
|
|
|
|
|
setActiveTab('2');
|
|
|
|
|
|
|
|
dispatch(updateLogBarStatus(true));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加事件监听器
|
|
|
|
|
|
|
|
document.addEventListener('logMessage', handleLogMessage as EventListener);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 清理事件监听器
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
|
|
document.removeEventListener('logMessage', handleLogMessage as EventListener);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}, [dispatch]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染校验日志内容
|
|
|
|
|
|
|
|
const renderValidationLogs = () => {
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<div style={{ padding: '10px', maxHeight: '200px', overflowY: 'auto' }}>
|
|
|
|
|
|
|
|
{validationLogs.length === 0 ? (
|
|
|
|
|
|
|
|
<p>暂无校验日志</p>
|
|
|
|
|
|
|
|
) : (
|
|
|
|
|
|
|
|
validationLogs.map(log => (
|
|
|
|
|
|
|
|
<div key={log.id} style={{ marginBottom: '8px', padding: '4px', borderBottom: '1px solid #eee' }}>
|
|
|
|
|
|
|
|
<div style={{ fontSize: '12px', color: '#999' }}>
|
|
|
|
|
|
|
|
{new Date(log.timestamp).toLocaleString()}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
|
|
|
|
|
|
|
|
{log.message}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<ResizeBox
|
|
|
|
<ResizeBox
|
|
|
|
@ -94,7 +153,7 @@ const LogBar: React.FC<LogBarProps> = () => {
|
|
|
|
>
|
|
|
|
>
|
|
|
|
{tabs.map((x) => (
|
|
|
|
{tabs.map((x) => (
|
|
|
|
<TabPane destroyOnHide key={x.key} title={x.title}>
|
|
|
|
<TabPane destroyOnHide key={x.key} title={x.title}>
|
|
|
|
{x.content}
|
|
|
|
{x.key === '2' ? renderValidationLogs() : x.content}
|
|
|
|
</TabPane>
|
|
|
|
</TabPane>
|
|
|
|
))}
|
|
|
|
))}
|
|
|
|
</Tabs>
|
|
|
|
</Tabs>
|
|
|
|
|