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.7 kB

1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import FullScreenFrame from '@/components/FullScreenFrame';
  2. import KFSpin from '@/components/KFSpin';
  3. import { getLabelStudioUrl } from '@/services/developmentEnvironment';
  4. import { generateSign } from '@/utils';
  5. import { to } from '@/utils/promise';
  6. import SessionStorage from '@/utils/sessionStorage';
  7. import { useModel } from '@umijs/max';
  8. import classNames from 'classnames';
  9. import { useEffect, useState } from 'react';
  10. import { createPortal } from 'react-dom';
  11. import './index.less';
  12. export enum IframePageType {
  13. DatasetAnnotation = 'DatasetAnnotation', // 数据标注
  14. AppDevelopment = 'AppDevelopment', // 应用开发
  15. DevEnv = 'DevEnv', // 开发环境
  16. GitLink = 'GitLink',
  17. }
  18. const getRequestAPI = (type: IframePageType, loginName: string): (() => Promise<any>) => {
  19. switch (type) {
  20. case IframePageType.DatasetAnnotation:
  21. return getLabelStudioUrl;
  22. case IframePageType.AppDevelopment: {
  23. // return () => Promise.resolve({ code: 200, data: 'http://172.20.32.185:30080/' });
  24. const sign = generateSign(loginName);
  25. return () =>
  26. Promise.resolve({
  27. code: 200,
  28. data: `http://10.43.107.27:24078/uap/nudt/sso/login?name=${loginName}&sign=${sign}`,
  29. });
  30. }
  31. case IframePageType.DevEnv:
  32. return () =>
  33. Promise.resolve({
  34. code: 200,
  35. data: SessionStorage.getItem(SessionStorage.editorUrlKey) || '',
  36. });
  37. case IframePageType.GitLink:
  38. return () => Promise.resolve({ code: 200, data: 'http://172.20.32.201:4000' });
  39. }
  40. };
  41. type IframePageProps = {
  42. type: IframePageType;
  43. className?: string;
  44. style?: React.CSSProperties;
  45. };
  46. function IframePage({ type, className, style }: IframePageProps) {
  47. const [iframeUrl, setIframeUrl] = useState('');
  48. const [loading, setLoading] = useState(false);
  49. const { initialState } = useModel('@@initialState');
  50. const { currentUser } = initialState || {};
  51. useEffect(() => {
  52. requestIframeUrl();
  53. return () => {
  54. if (type === IframePageType.DevEnv) {
  55. SessionStorage.removeItem(SessionStorage.editorUrlKey);
  56. }
  57. };
  58. }, []);
  59. const requestIframeUrl = async () => {
  60. setLoading(true);
  61. const [res] = await to(getRequestAPI(type, currentUser?.userName || '')());
  62. if (res && res.data) {
  63. setIframeUrl(res.data);
  64. } else {
  65. setLoading(false);
  66. }
  67. };
  68. const hideLoading = () => {
  69. setLoading(false);
  70. };
  71. return (
  72. <div className={classNames('kf-iframe-page', className)} style={style}>
  73. {loading && createPortal(<KFSpin size="large" />, document.body)}
  74. <FullScreenFrame url={iframeUrl} onload={hideLoading} onerror={hideLoading} />
  75. </div>
  76. );
  77. }
  78. export default IframePage;