Browse Source

feat: iframe 添加 loading

pull/113/head
cp3hnu 1 year ago
parent
commit
57042d280f
5 changed files with 77 additions and 21 deletions
  1. +11
    -2
      react-ui/src/components/FullScreenFrame/index.tsx
  2. +5
    -0
      react-ui/src/components/IFramePage/index.less
  3. +57
    -0
      react-ui/src/components/IFramePage/index.tsx
  4. +2
    -4
      react-ui/src/pages/Application/index.tsx
  5. +2
    -15
      react-ui/src/pages/DatasetPreparation/DatasetAnnotation/index.tsx

+ 11
- 2
react-ui/src/components/FullScreenFrame/index.tsx View File

@@ -5,12 +5,21 @@ type FullScreenFrameProps = {
url: string;
className?: string;
style?: React.CSSProperties;
onload?: () => void;
onerror?: () => void;
};

function FullScreenFrame({ url, className, style }: FullScreenFrameProps) {
function FullScreenFrame({ url, className, style, onload, onerror }: FullScreenFrameProps) {
return (
<div className={classNames('kf-full-screen-frame', className ?? '')} style={style}>
{url && <iframe src={url} className="kf-full-screen-frame__iframe"></iframe>}
{url && (
<iframe
src={url}
className="kf-full-screen-frame__iframe"
onLoad={onload}
onError={onerror}
></iframe>
)}
</div>
);
}


+ 5
- 0
react-ui/src/components/IFramePage/index.less View File

@@ -0,0 +1,5 @@
.kf-iframe-page {
position: relative;
width: 100%;
height: 100%;
}

+ 57
- 0
react-ui/src/components/IFramePage/index.tsx View File

@@ -0,0 +1,57 @@
import FullScreenFrame from '@/components/FullScreenFrame';
import KFSpin from '@/components/KFSpin';
import { getLabelStudioUrl } from '@/services/developmentEnvironment';
import { to } from '@/utils/promise';
import classNames from 'classnames';
import { useEffect, useState } from 'react';
import './index.less';

export enum IframePageType {
DatasetAnnotation = 'DatasetAnnotation', // 数据标注
AppDevelopment = 'AppDevelopment', // 应用开发
}

const getRequestAPI = (type: IframePageType): (() => Promise<any>) => {
switch (type) {
case IframePageType.DatasetAnnotation:
return getLabelStudioUrl;
case IframePageType.AppDevelopment:
return () => Promise.resolve({ code: 200, data: 'http://172.20.32.181:30080/' });
}
};

type IframePageProps = {
type: IframePageType;
className?: string;
style?: React.CSSProperties;
};

function IframePage({ type, className, style }: IframePageProps) {
const [iframeUrl, setIframeUrl] = useState('');
const [loading, setLoading] = useState(false);
useEffect(() => {
requestIframeUrl();
}, []);
const requestIframeUrl = async () => {
setLoading(true);
const [res] = await to(getRequestAPI(type)());
if (res && res.data) {
setIframeUrl(res.data);
} else {
setLoading(false);
}
};

const hideLoading = () => {
setLoading(false);
};

return (
<div className={classNames('kf-iframe-page', className)} style={style}>
{loading && <KFSpin />}
<FullScreenFrame url={iframeUrl} onload={hideLoading} onerror={hideLoading} />
</div>
);
}

export default IframePage;

+ 2
- 4
react-ui/src/pages/Application/index.tsx View File

@@ -1,9 +1,7 @@
import FullScreenFrame from '@/components/FullScreenFrame';
import { useState } from 'react';
import IframePage, { IframePageType } from '@/components/IFramePage';

function Application() {
const [iframeUrl] = useState('http://172.20.32.181:30080/');
return <FullScreenFrame url={iframeUrl}></FullScreenFrame>;
return <IframePage type={IframePageType.AppDevelopment}></IframePage>;
}

export default Application;

+ 2
- 15
react-ui/src/pages/DatasetPreparation/DatasetAnnotation/index.tsx View File

@@ -1,20 +1,7 @@
import FullScreenFrame from '@/components/FullScreenFrame';
import { getLabelStudioUrl } from '@/services/developmentEnvironment';
import { to } from '@/utils/promise';
import { useEffect, useState } from 'react';
import IframePage, { IframePageType } from '@/components/IFramePage';

function DatasetAnnotation() {
const [iframeUrl, setIframeUrl] = useState('');
useEffect(() => {
requestIframeUrl();
}, []);
const requestIframeUrl = async () => {
const [res] = await to(getLabelStudioUrl());
if (res && res.data) {
setIframeUrl(res.data);
}
};
return <FullScreenFrame url={iframeUrl} />;
return <IframePage type={IframePageType.DatasetAnnotation}></IframePage>;
}

export default DatasetAnnotation;

Loading…
Cancel
Save