import { useEffect, useState } from 'react'; import { LoadingOutlined } from '@ant-design/icons'; import { Button, Card, Modal, Spin } from 'antd'; import { useTranslation } from 'react-i18next'; import * as api from '@/api/script'; type RunProps = { script: string; setIsRunning: (isRunning: boolean) => void; }; export const Run = ({ script, setIsRunning }: RunProps) => { const { t } = useTranslation(); const [state, setState] = useState(''); const [log, setLog] = useState(''); useEffect(() => { setState('running'); api .runScript(script, 'foreground') .then((rsp) => { if (rsp.code !== 0) { setLog(rsp.msg); setState('failed'); return; } setState('success'); setLog(rsp.data.log); }) .catch(() => { setLog(t('script.runFailed')); setState('failed'); }); }, []); return ( {state === 'running' ? (
} size="large" />
) : ( {log} )}
); };