/** * SSACodeModal - V11 R代码模态框 * * 100% 还原 V11 原型图 * 调用后端 API 获取真实执行代码 */ import React, { useEffect, useState } from 'react'; import { X, Download, Loader2 } from 'lucide-react'; import { useSSAStore } from '../stores/ssaStore'; import { useAnalysis } from '../hooks/useAnalysis'; export const SSACodeModal: React.FC = () => { const { codeModalVisible, setCodeModalVisible, executionResult, addToast } = useSSAStore(); const { downloadCode } = useAnalysis(); const [code, setCode] = useState(''); const [isLoading, setIsLoading] = useState(false); useEffect(() => { if (codeModalVisible) { loadCode(); } }, [codeModalVisible]); const loadCode = async () => { setIsLoading(true); try { const result = await downloadCode(); const text = await result.blob.text(); setCode(text); } catch (error) { if (executionResult?.reproducibleCode) { setCode(executionResult.reproducibleCode); } else { setCode('# 暂无可用代码\n# 请先执行分析'); } } finally { setIsLoading(false); } }; if (!codeModalVisible) return null; const handleClose = () => { setCodeModalVisible(false); }; const handleDownload = async () => { try { const result = await downloadCode(); const url = URL.createObjectURL(result.blob); const a = document.createElement('a'); a.href = url; a.download = result.filename; a.click(); URL.revokeObjectURL(url); addToast('R 脚本已下载', 'success'); handleClose(); } catch (error) { addToast('下载失败', 'error'); } }; const handleCopy = () => { navigator.clipboard.writeText(code); addToast('代码已复制', 'success'); }; return (
e.stopPropagation()}>

R R 源代码交付

{isLoading ? (
加载代码中...
) : (
              {code}
            
)}
); }; export default SSACodeModal;