import React, { useState, useEffect } from 'react'; import { Spin, Alert, Tabs } from 'antd'; import ReactDiffViewer from 'react-diff-viewer-continued'; import api from '../api'; export default function FileDiff({ filePath, lobsterId }) { const [loading, setLoading] = useState(false); const [diffData, setDiffData] = useState(null); const [error, setError] = useState(null); const loadDiff = async () => { setLoading(true); setError(null); try { const response = await api.get('/diff/', { params: { file_path: filePath, lobster_id: lobsterId } }); if (response.success) { setDiffData(response.data); } else { setError(response.error || '加载失败'); } } catch (err) { setError(err.message || '网络错误'); } finally { setLoading(false); } }; useEffect(() => { if (filePath) { loadDiff(); } }, [filePath]); if (loading) { return ; } if (error) { return ; } if (!diffData) { return ; } const { local_content, db_content, status, diff } = diffData; // 文件不存在的情况 if (!local_content && !db_content) { return ; } if (!local_content) { return ( ); } if (!db_content) { return ( ); } const STATUS_MESSAGES = { consistent: '文件内容一致', local_newer: '本地文件有更新', db_newer: '数据库版本更新', conflict: '文件内容冲突', }; return (
), }, { key: 'local', label: '本地内容', children: (
                {local_content}
              
), }, { key: 'db', label: '数据库内容', children: (
                {db_content}
              
), }, ]} /> ); }