/** * 3D 可视化插件组件 * 后端生成 Plotly HTML,前端通过 iframe 加载 */ import { useState, useEffect } from 'react'; import { Button, Spin, Typography, Modal, Empty } from 'antd'; import { ExpandOutlined, ReloadOutlined } from '@ant-design/icons'; import api from '../../services/api'; const { Text } = Typography; const Visualization3D = ({ code = '' }) => { const [htmlUrl, setHtmlUrl] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [fullscreen, setFullscreen] = useState(false); const generate = async (codeToRun) => { const targetCode = codeToRun || code; if (!targetCode) return; setLoading(true); setError(null); try { const response = await api.post('/visualization/3d-surface', { code: targetCode }); if (response.success) { // html_url 是相对于后端的路径,需要加上后端地址 setHtmlUrl(response.html_url); } else { setError(response.message || '生成失败'); } } catch (e) { setError(e.message || '请求失败'); } finally { setLoading(false); } }; // 当 code 变化时自动生成 useEffect(() => { if (code) generate(code); }, [code]); return (
3D 可视化
{htmlUrl && ( )}
{loading ? (
) : error ? (
{error}} />
) : htmlUrl ? (