Commit a624bb6f authored by 吴永生#A02208's avatar 吴永生#A02208

feat: 点击按delete删除线

parent 923c9a71
...@@ -61,24 +61,61 @@ const Flow = (props: IProps) => { ...@@ -61,24 +61,61 @@ const Flow = (props: IProps) => {
const [inSideBatchNodeId, setInSideBatchNodeId] = useState<string>(""); const [inSideBatchNodeId, setInSideBatchNodeId] = useState<string>("");
/** 内部维护的选择的flow节点Id */ /** 内部维护的选择的flow节点Id */
const [inSideFlowNodeId, setInSideFlowNodeId] = useState<string>(""); const [inSideFlowNodeId, setInSideFlowNodeId] = useState<string>("");
/** 选中的线 */
const [selectedEdge, setSelectedEdge] = useState<Edge>();
const Message = useMessage(); const Message = useMessage();
/** 删除批或者线节点 */ /** 原始数据删除线 */
const tasksDeleteLine = useCallback(
(connection: Connection | Edge) => {
const result =
(tasks?.length &&
tasks.map((item) => {
if (item.id === connection.source && item.type === "BATCH") {
const newEdges =
(item.edges?.length &&
item.edges?.filter(
(every) => every.sourceHandle !== connection.sourceHandle
)) ||
[];
return {
...item,
edges: newEdges,
};
} else {
return item;
}
})) ||
[];
return result;
},
[tasks]
);
/** 删除批节点或者线 */
const deleteSelectBatchNode = useCallback( const deleteSelectBatchNode = useCallback(
(e: any) => { (e: any) => {
if (e.keyCode === 8) { if (e.keyCode === 8) {
const val = let val: ITask[] = [];
tasks?.length && /** 删除批节点逻辑 */
tasks.filter((item) => { if (inSideBatchNodeId) {
return ( val =
item.id !== inSideBatchNodeId && (tasks?.length &&
item.parentNode !== inSideBatchNodeId tasks.filter((item) => {
); return (
}); item.id !== inSideBatchNodeId &&
setTasks && setTasks(val || []); item.parentNode !== inSideBatchNodeId
);
})) ||
[];
}
if (selectedEdge) {
val = tasksDeleteLine(selectedEdge);
}
setTasks && setTasks(val);
} }
}, },
[inSideBatchNodeId, setTasks, tasks] [inSideBatchNodeId, selectedEdge, setTasks, tasks, tasksDeleteLine]
); );
/** 监听鼠标按下事件 */ /** 监听鼠标按下事件 */
...@@ -239,6 +276,14 @@ const Flow = (props: IProps) => { ...@@ -239,6 +276,14 @@ const Flow = (props: IProps) => {
return { return {
...item, ...item,
// type: "smoothstep", // type: "smoothstep",
/** 点击线选中 */
...(selectedEdge?.id === item.id
? {
style: { stroke: "#1370FF", strokeWidth: 2 },
animated: true,
}
: {}),
/** 点击batch节点选中 */
...(item?.batchId === newSelectId ...(item?.batchId === newSelectId
? { style: { stroke: "#1370FF" }, animated: true } ? { style: { stroke: "#1370FF" }, animated: true }
: {}), : {}),
...@@ -247,7 +292,7 @@ const Flow = (props: IProps) => { ...@@ -247,7 +292,7 @@ const Flow = (props: IProps) => {
label: item.label ? `(${item.label})` : "", label: item.label ? `(${item.label})` : "",
}; };
}); });
}, [inSideBatchNodeId, selectedBatchNodeId, tasks]); }, [inSideBatchNodeId, selectedBatchNodeId, selectedEdge?.id, tasks]);
/** 设置nodeId方法 */ /** 设置nodeId方法 */
const setNodeIdFun = useCallback( const setNodeIdFun = useCallback(
...@@ -284,6 +329,7 @@ const Flow = (props: IProps) => { ...@@ -284,6 +329,7 @@ const Flow = (props: IProps) => {
: setInSideBatchNodeId(""); : setInSideBatchNodeId("");
setInSideFlowNodeId(""); setInSideFlowNodeId("");
onBatchClick && onBatchClick(""); onBatchClick && onBatchClick("");
setSelectedEdge(undefined);
}; };
/** node节点 */ /** node节点 */
...@@ -335,33 +381,6 @@ const Flow = (props: IProps) => { ...@@ -335,33 +381,6 @@ const Flow = (props: IProps) => {
[] []
); );
/** 原始数据删除线 */
const tasksDeleteLine = useCallback(
(connection: Connection) => {
const result =
(tasks?.length &&
tasks.map((item) => {
if (item.id === connection.source) {
const newEdges =
(item.edges?.length &&
item.edges?.filter(
(every) => every.sourceHandle !== connection.sourceHandle
)) ||
[];
return {
...item,
edges: newEdges,
};
} else {
return item;
}
})) ||
[];
return result;
},
[tasks]
);
/** 获取连接线的端点类型 */ /** 获取连接线的端点类型 */
const getClassType = useCallback( const getClassType = useCallback(
(connection: Connection) => { (connection: Connection) => {
...@@ -438,7 +457,7 @@ const Flow = (props: IProps) => { ...@@ -438,7 +457,7 @@ const Flow = (props: IProps) => {
/** 点击连线 */ /** 点击连线 */
const onEdgeClick = useCallback((e: any, val: Edge) => { const onEdgeClick = useCallback((e: any, val: Edge) => {
console.log(val, "1111"); setSelectedEdge(val);
}, []); }, []);
return ( return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment