Browse Source

feat: 开发环境编辑器使用iframe

pull/90/head
cp3hnu 1 year ago
parent
commit
b06a502ebe
8 changed files with 51 additions and 32 deletions
  1. +5
    -0
      react-ui/config/routes.ts
  2. +25
    -0
      react-ui/src/pages/DevelopmentEnvironment/Editor/index.tsx
  3. +12
    -3
      react-ui/src/pages/DevelopmentEnvironment/List/index.tsx
  4. +0
    -22
      react-ui/src/pages/DevelopmentEnvironment/index.tsx
  5. +5
    -5
      react-ui/src/pages/Pipeline/editPipeline/index.jsx
  6. +1
    -2
      react-ui/src/services/developmentEnvironment/index.ts
  7. +2
    -0
      react-ui/src/utils/sessionStorage.ts
  8. +1
    -0
      react-ui/tsconfig.json

+ 5
- 0
react-ui/config/routes.ts View File

@@ -119,6 +119,11 @@ export default [
path: 'create', path: 'create',
component: './DevelopmentEnvironment/Create', component: './DevelopmentEnvironment/Create',
}, },
{
name: '编辑器',
path: 'editor',
component: './DevelopmentEnvironment/Editor',
},
], ],
}, },
{ {


+ 25
- 0
react-ui/src/pages/DevelopmentEnvironment/Editor/index.tsx View File

@@ -0,0 +1,25 @@
import { editorUrl, getSessionStorageItem, removeSessionStorageItem } from '@/utils/sessionStorage';
import { useEffect, useState } from 'react';

function DevEditor() {
const [iframeUrl, setIframeUrl] = useState('');
useEffect(() => {
const url = getSessionStorageItem(editorUrl) || '';
setIframeUrl(url);
return () => {
removeSessionStorageItem(editorUrl);
};
}, []);

// const requestJupyterUrl = async () => {
// const [res, error] = await to(getJupyterUrl());
// if (res) {
// setIframeUrl(res.data as string);
// } else {
// console.log(error);
// }
// };

return <iframe style={{ width: '100%', height: '100%', border: 0 }} src={iframeUrl}></iframe>;
}
export default DevEditor;

+ 12
- 3
react-ui/src/pages/DevelopmentEnvironment/List/index.tsx View File

@@ -16,6 +16,7 @@ import {
} from '@/services/developmentEnvironment'; } from '@/services/developmentEnvironment';
import themes from '@/styles/theme.less'; import themes from '@/styles/theme.less';
import { to } from '@/utils/promise'; import { to } from '@/utils/promise';
import { editorUrl, setSessionStorageItem } from '@/utils/sessionStorage';
import { modalConfirm } from '@/utils/ui'; import { modalConfirm } from '@/utils/ui';
import { useNavigate } from '@umijs/max'; import { useNavigate } from '@umijs/max';
import { import {
@@ -128,6 +129,16 @@ function EditorList() {
}); });
}; };


// 跳转编辑器页面
const gotoEditorPage = (e: React.MouseEvent, record: EditorData) => {
e.stopPropagation();
setSessionStorageItem(editorUrl, record.url);
navigate(`/developmentEnvironment/editor`);
setCacheState({
pagination,
});
};

// 分页切换 // 分页切换
const handleTableChange: TableProps['onChange'] = (pagination, filters, sorter, { action }) => { const handleTableChange: TableProps['onChange'] = (pagination, filters, sorter, { action }) => {
if (action === 'paginate') { if (action === 'paginate') {
@@ -143,9 +154,7 @@ function EditorList() {
width: '30%', width: '30%',
render: (text, record) => render: (text, record) =>
record.url ? ( record.url ? (
<a href={record.url} target="_blank" rel="noreferrer">
{text}
</a>
<a onClick={(e) => gotoEditorPage(e, record)}>{text}</a>
) : ( ) : (
<span>{text ?? '--'}</span> <span>{text ?? '--'}</span>
), ),


+ 0
- 22
react-ui/src/pages/DevelopmentEnvironment/index.tsx View File

@@ -1,22 +0,0 @@
import { getJupyterUrl } from '@/services/developmentEnvironment';
import { to } from '@/utils/promise';
import { useEffect, useState } from 'react';

const DevelopmentEnvironment = () => {
const [iframeUrl, setIframeUrl] = useState('');
useEffect(() => {
requestJupyterUrl();
}, []);

const requestJupyterUrl = async () => {
const [res, error] = await to(getJupyterUrl());
if (res) {
setIframeUrl(res.data as string);
} else {
console.log(error);
}
};

return <iframe style={{ width: '100%', height: '100%', border: 0 }} src={iframeUrl}></iframe>;
};
export default DevelopmentEnvironment;

+ 5
- 5
react-ui/src/pages/Pipeline/editPipeline/index.jsx View File

@@ -93,11 +93,11 @@ const EditPipeline = () => {
return; return;
} }


// const [propsRes, propsError] = await to(propsRef.current.getFieldsValue());
// if (propsError) {
// message.error('基本信息必填项需配置');
// return;
// }
const [propsRes, propsError] = await to(propsRef.current.getFieldsValue());
if (propsError) {
message.error('节点必填项必须配置');
return;
}
propsRef.current.propClose(); propsRef.current.propClose();
setTimeout(() => { setTimeout(() => {
const data = graph.save(); const data = graph.save();


+ 1
- 2
react-ui/src/services/developmentEnvironment/index.ts View File

@@ -1,9 +1,8 @@
import { request } from '@umijs/max'; import { request } from '@umijs/max';
// 查询开发环境url // 查询开发环境url
export function getJupyterUrl(params: any) {
export function getJupyterUrl() {
return request(`/api/mmp/jupyter/getURL`, { return request(`/api/mmp/jupyter/getURL`, {
method: 'GET', method: 'GET',
params,
}); });
} }




+ 2
- 0
react-ui/src/utils/sessionStorage.ts View File

@@ -2,6 +2,8 @@
export const mirrorNameKey = 'mirror-name'; export const mirrorNameKey = 'mirror-name';
// 模型部署 // 模型部署
export const modelDeploymentInfoKey = 'model-deployment-info'; export const modelDeploymentInfoKey = 'model-deployment-info';
// 编辑器 url
export const editorUrl = 'editor-url';


export const getSessionStorageItem = (key: string, isObject: boolean = false) => { export const getSessionStorageItem = (key: string, isObject: boolean = false) => {
const jsonStr = sessionStorage.getItem(key); const jsonStr = sessionStorage.getItem(key);


+ 1
- 0
react-ui/tsconfig.json View File

@@ -20,6 +20,7 @@
"noUnusedParameters": true, // 报告未使用的参数错误 "noUnusedParameters": true, // 报告未使用的参数错误
"incremental": true, // 通过读写磁盘上的文件来启用增量编译 "incremental": true, // 通过读写磁盘上的文件来启用增量编译
"noFallthroughCasesInSwitch": true, // 报告switch语句中的fallthrough案例错误 "noFallthroughCasesInSwitch": true, // 报告switch语句中的fallthrough案例错误
"strictNullChecks": true, // 启用严格的null检查
"baseUrl": "./", "baseUrl": "./",
"paths": { "paths": {
"@/*": ["src/*"], "@/*": ["src/*"],


Loading…
Cancel
Save