|
|
|
@@ -1,21 +1,27 @@ |
|
|
|
import { useModal } from '@/hooks'; |
|
|
|
import { getWorkflowById, saveWorkflow } from '@/services/pipeline/index.js'; |
|
|
|
import { to } from '@/utils/promise'; |
|
|
|
import { SaveOutlined } from '@ant-design/icons'; |
|
|
|
import { useEmotionCss } from '@ant-design/use-emotion-css'; |
|
|
|
import G6 from '@antv/g6'; |
|
|
|
import { Button, message } from 'antd'; |
|
|
|
import React, { useEffect, useRef } from 'react'; |
|
|
|
import { useEffect, useRef, useState } from 'react'; |
|
|
|
import { useNavigate, useParams } from 'react-router-dom'; |
|
|
|
import { Icon } from 'umi'; |
|
|
|
import { s8 } from '../../../utils'; |
|
|
|
import Styles from './editPipeline.less'; |
|
|
|
import GlobalParamsDrawer from './globalParamsDrawer'; |
|
|
|
import ModelMenus from './modelMenus'; |
|
|
|
import Props from './props'; |
|
|
|
const editPipeline = (React.FC = () => { |
|
|
|
|
|
|
|
let graph = null; |
|
|
|
|
|
|
|
const EditPipeline = () => { |
|
|
|
const propsRef = useRef(); |
|
|
|
const navgite = useNavigate(); |
|
|
|
// const [contextMenu,setContextMenu]=useState({}) |
|
|
|
let contextMenu = {}; |
|
|
|
const locationParams = useParams(); //新版本获取路由参数接口 |
|
|
|
let graph = null; |
|
|
|
let sourceAnchorIdx, targetAnchorIdx; |
|
|
|
const pipelineContainer = useEmotionCss(() => { |
|
|
|
return { |
|
|
|
@@ -53,6 +59,9 @@ const editPipeline = (React.FC = () => { |
|
|
|
}; |
|
|
|
}); |
|
|
|
const graphRef = useRef(); |
|
|
|
const paramsDrawerRef = useRef(); |
|
|
|
const [paramsDrawerVisible, openParamsDrawer, closeParamsDrawer] = useModal(false); |
|
|
|
const [globalParam, setGlobalParam] = useState([]); |
|
|
|
|
|
|
|
const onDragEnd = (val) => { |
|
|
|
console.log(val, 'eee'); |
|
|
|
@@ -74,35 +83,37 @@ const editPipeline = (React.FC = () => { |
|
|
|
console.log(graph); |
|
|
|
}; |
|
|
|
const formChange = (val) => { |
|
|
|
const data = graph.save(); |
|
|
|
const index = data.nodes.findIndex((item) => { |
|
|
|
return item.id === val.id; |
|
|
|
}); |
|
|
|
data.nodes[index] = val; |
|
|
|
graph.changeData(data); |
|
|
|
graph.render(); |
|
|
|
if (graph) { |
|
|
|
const data = graph.save(); |
|
|
|
const index = data.nodes.findIndex((item) => { |
|
|
|
return item.id === val.id; |
|
|
|
}); |
|
|
|
data.nodes[index] = val; |
|
|
|
graph.changeData(data); |
|
|
|
graph.render(); |
|
|
|
} |
|
|
|
}; |
|
|
|
const savePipeline = (val) => { |
|
|
|
const savePipeline = async (val) => { |
|
|
|
const [res, error] = await to(paramsDrawerRef.current.getFieldsValue()); |
|
|
|
if (error) { |
|
|
|
message.error('全局参数配置有误'); |
|
|
|
return; |
|
|
|
} |
|
|
|
const data = graph.save(); |
|
|
|
console.log(data); |
|
|
|
let params = { |
|
|
|
...locationParams, |
|
|
|
dag: JSON.stringify(data), |
|
|
|
global_param: JSON.stringify(res.global_param), |
|
|
|
}; |
|
|
|
saveWorkflow(params).then((ret) => { |
|
|
|
console.log(ret); |
|
|
|
if (ret.code == 200) { |
|
|
|
message.success('保存成功'); |
|
|
|
setTimeout(() => { |
|
|
|
if (val) { |
|
|
|
navgite({ pathname: `/pipeline` }); |
|
|
|
} |
|
|
|
}, 500); |
|
|
|
} else { |
|
|
|
message.error('保存失败'); |
|
|
|
} |
|
|
|
message.success('保存成功'); |
|
|
|
setTimeout(() => { |
|
|
|
if (val) { |
|
|
|
navgite({ pathname: `/pipeline` }); |
|
|
|
} |
|
|
|
}, 500); |
|
|
|
}); |
|
|
|
console.log(params); |
|
|
|
}; |
|
|
|
const handlerClick = (e) => { |
|
|
|
e.stopPropagation(); |
|
|
|
@@ -258,13 +269,12 @@ const editPipeline = (React.FC = () => { |
|
|
|
}; |
|
|
|
const getFirstWorkflow = (val) => { |
|
|
|
getWorkflowById(val).then((ret) => { |
|
|
|
console.log(ret); |
|
|
|
if (ret.code == 200) { |
|
|
|
if (graph && ret.data && ret.data.dag) { |
|
|
|
getGraphData(JSON.parse(ret.data.dag)); |
|
|
|
} |
|
|
|
if (ret && ret.data) { |
|
|
|
setGlobalParam(ret.data.global_param); |
|
|
|
} |
|
|
|
if (graph && ret.data && ret.data.dag) { |
|
|
|
getGraphData(JSON.parse(ret.data.dag)); |
|
|
|
} |
|
|
|
|
|
|
|
// graph&&graph.data(JSON.parse(ret.dag)) |
|
|
|
// graph.render() |
|
|
|
}); |
|
|
|
@@ -334,7 +344,6 @@ const editPipeline = (React.FC = () => { |
|
|
|
}); |
|
|
|
graph.off('dblclick', handlerClick); |
|
|
|
}; |
|
|
|
console.log(contextMenu); |
|
|
|
}, []); |
|
|
|
const initGraph = () => { |
|
|
|
const fittingString = (str, maxWidth, fontSize) => { |
|
|
|
@@ -601,8 +610,10 @@ const editPipeline = (React.FC = () => { |
|
|
|
}); |
|
|
|
graph.on('dblclick', (e) => { |
|
|
|
console.log(e.item); |
|
|
|
graph.setItemState(e.item, 'nodeClicked', true); |
|
|
|
handlerClick(e); |
|
|
|
if (e.item) { |
|
|
|
graph.setItemState(e.item, 'nodeClicked', true); |
|
|
|
handlerClick(e); |
|
|
|
} |
|
|
|
}); |
|
|
|
graph.on('click', (e) => { |
|
|
|
console.log(e.item); |
|
|
|
@@ -690,11 +701,18 @@ const editPipeline = (React.FC = () => { |
|
|
|
<ModelMenus onParDragEnd={onDragEnd}></ModelMenus> |
|
|
|
<div className={Styles.centerContainer}> |
|
|
|
<div className={Styles.buttonList}> |
|
|
|
<Button |
|
|
|
type="default" |
|
|
|
icon={<Icon icon="local:parameter" style={{ verticalAlign: '-2px' }} />} |
|
|
|
style={{ marginRight: '20px' }} |
|
|
|
onClick={openParamsDrawer} |
|
|
|
> |
|
|
|
全局参数 |
|
|
|
</Button> |
|
|
|
<Button |
|
|
|
type="primary" |
|
|
|
shape="round" |
|
|
|
icon={<SaveOutlined />} |
|
|
|
style={{ marginRight: '20px', background: '#1664ff' }} |
|
|
|
style={{ marginRight: '20px' }} |
|
|
|
onClick={() => { |
|
|
|
savePipeline(false); |
|
|
|
}} |
|
|
|
@@ -703,9 +721,7 @@ const editPipeline = (React.FC = () => { |
|
|
|
</Button> |
|
|
|
<Button |
|
|
|
type="primary" |
|
|
|
shape="round" |
|
|
|
icon={<SaveOutlined />} |
|
|
|
style={{ background: '#1664ff' }} |
|
|
|
onClick={() => { |
|
|
|
savePipeline(true); |
|
|
|
}} |
|
|
|
@@ -716,7 +732,13 @@ const editPipeline = (React.FC = () => { |
|
|
|
<div className={graphStyle} ref={graphRef} id={Styles.graphStyle}></div> |
|
|
|
</div> |
|
|
|
<Props ref={propsRef} onParentChange={formChange}></Props> |
|
|
|
<GlobalParamsDrawer |
|
|
|
ref={paramsDrawerRef} |
|
|
|
open={paramsDrawerVisible} |
|
|
|
globalParam={globalParam} |
|
|
|
onClose={closeParamsDrawer} |
|
|
|
></GlobalParamsDrawer> |
|
|
|
</div> |
|
|
|
); |
|
|
|
}); |
|
|
|
export default editPipeline; |
|
|
|
}; |
|
|
|
export default EditPipeline; |