You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import InfoGroup from '@/components/InfoGroup';
  2. import { getFileReq } from '@/services/file';
  3. import { to } from '@/utils/promise';
  4. import { Button, Image } from 'antd';
  5. import { useEffect, useMemo, useState } from 'react';
  6. import styles from './index.less';
  7. type ExperimentResultProps = {
  8. fileUrl?: string;
  9. imageUrl?: string;
  10. modelPath?: string;
  11. };
  12. function ExperimentResult({ fileUrl, imageUrl, modelPath }: ExperimentResultProps) {
  13. const [result, setResult] = useState<string | undefined>('');
  14. const images = useMemo(() => {
  15. if (imageUrl) {
  16. return imageUrl.split(',').map((item) => item.trim());
  17. }
  18. return [];
  19. }, [imageUrl]);
  20. useEffect(() => {
  21. // 获取实验运行历史记录
  22. const getResultFile = async () => {
  23. const [res] = await to(getFileReq(fileUrl));
  24. if (res) {
  25. setResult(res as any as string);
  26. }
  27. };
  28. if (fileUrl) {
  29. getResultFile();
  30. }
  31. }, [fileUrl]);
  32. return (
  33. <div className={styles['experiment-result']}>
  34. <InfoGroup title="实验结果" height={420} width="100%">
  35. <div className={styles['experiment-result__text']}>{result}</div>
  36. </InfoGroup>
  37. <InfoGroup title="可视化结果" style={{ margin: '16px 0' }}>
  38. <div className={styles['experiment-result__images']}>
  39. <Image.PreviewGroup
  40. preview={{
  41. onChange: (current, prev) =>
  42. console.log(`current index: ${current}, prev index: ${prev}`),
  43. }}
  44. >
  45. {images.map((item) => (
  46. <Image
  47. key={item}
  48. className={styles['experiment-result__images__item']}
  49. src={item}
  50. height={248}
  51. draggable={false}
  52. alt=""
  53. />
  54. ))}
  55. </Image.PreviewGroup>
  56. </div>
  57. </InfoGroup>
  58. {modelPath && (
  59. <div className={styles['experiment-result__download']}>
  60. <span style={{ marginRight: '12px', color: '#606b7a' }}>文件名</span>
  61. <span>save_model.joblib</span>
  62. <Button
  63. type="primary"
  64. className={styles['experiment-result__download__btn']}
  65. onClick={() => {
  66. window.location.href = modelPath;
  67. }}
  68. >
  69. 模型下载
  70. </Button>
  71. </div>
  72. )}
  73. </div>
  74. );
  75. }
  76. export default ExperimentResult;