Commit 8df9d589 authored by 吴永生#A02208's avatar 吴永生#A02208

fix: 拖拽生成数据

parent 11a35e35
...@@ -21,7 +21,7 @@ const theme = createTheme({ ...@@ -21,7 +21,7 @@ const theme = createTheme({
MuiMenu: { MuiMenu: {
styleOverrides: { styleOverrides: {
root: { root: {
maxHeight: "260px", // maxHeight: "260px",
overflowY: "scroll", overflowY: "scroll",
}, },
}, },
...@@ -87,7 +87,9 @@ const MyMenu = (props: IMyMenuProps) => { ...@@ -87,7 +87,9 @@ const MyMenu = (props: IMyMenuProps) => {
key={index} key={index}
> >
<span>{option.label}</span> <span>{option.label}</span>
{value === option.value && <CheckIcon />} {value === option.value && (
<CheckIcon sx={{ marginLeft: "12px" }} />
)}
</MenuItem> </MenuItem>
); );
})} })}
......
...@@ -155,7 +155,7 @@ const Flow = (props: IProps) => { ...@@ -155,7 +155,7 @@ const Flow = (props: IProps) => {
const lineArr: IEdge[] = []; const lineArr: IEdge[] = [];
tasks?.length && tasks?.length &&
tasks.forEach((item) => { tasks.forEach((item) => {
lineArr.push(...item.edges); item.edges?.length && lineArr.push(...item.edges);
}); });
/** 所有的输入节点ID */ /** 所有的输入节点ID */
const isInput = lineArr?.some((item) => item.target === id); const isInput = lineArr?.some((item) => item.target === id);
...@@ -223,6 +223,7 @@ const Flow = (props: IProps) => { ...@@ -223,6 +223,7 @@ const Flow = (props: IProps) => {
const val: any = []; const val: any = [];
tasks?.length && tasks?.length &&
tasks.forEach((item) => { tasks.forEach((item) => {
console.log(item, "item");
val.push({ val.push({
id: item.id, id: item.id,
type: item.type === "BATCH" ? "batchNode" : "flowNode", type: item.type === "BATCH" ? "batchNode" : "flowNode",
...@@ -249,7 +250,10 @@ const Flow = (props: IProps) => { ...@@ -249,7 +250,10 @@ const Flow = (props: IProps) => {
padding: isFlowNode(item.id) ? "20px" : "12px 20px", padding: isFlowNode(item.id) ? "20px" : "12px 20px",
}, },
}, },
position: { x: Number(item.position.x), y: Number(item.position.y) }, position: {
x: Number(item.position?.x) || 0,
y: Number(item.position?.y) || 0,
},
...(item.type === "BATCH" ? { style: { zIndex: -1 } } : {}), ...(item.type === "BATCH" ? { style: { zIndex: -1 } } : {}),
...(item.parentNode ? { parentNode: item.parentNode } : {}), ...(item.parentNode ? { parentNode: item.parentNode } : {}),
...(item.type === "BATCH" ? { extent: "parent" } : {}), ...(item.type === "BATCH" ? { extent: "parent" } : {}),
...@@ -270,13 +274,14 @@ const Flow = (props: IProps) => { ...@@ -270,13 +274,14 @@ const Flow = (props: IProps) => {
const val: ILine[] = []; const val: ILine[] = [];
tasks?.length && tasks?.length &&
tasks.forEach((item) => { tasks.forEach((item) => {
item.edges.forEach((every) => { item?.edges?.length &&
const newLine = { item?.edges.forEach((every) => {
...every, const newLine = {
batchId: item.parentNode ? item.parentNode : item.id, ...every,
}; batchId: item.parentNode ? item.parentNode : item.id,
val.push(newLine); };
}, []); val.push(newLine);
}, []);
}); });
return val.map((item: ILine) => { return val.map((item: ILine) => {
const newSelectId = selectedNodeId ? selectedNodeId : inSideNodeId; const newSelectId = selectedNodeId ? selectedNodeId : inSideNodeId;
...@@ -340,7 +345,7 @@ const Flow = (props: IProps) => { ...@@ -340,7 +345,7 @@ const Flow = (props: IProps) => {
<ReactFlow <ReactFlow
nodes={nodes} nodes={nodes}
edges={edges} edges={edges}
fitView={flowType === "default" ? false : true} fitView={flowType === "default" ? true : false}
proOptions={{ hideAttribution: true, account: "" }} proOptions={{ hideAttribution: true, account: "" }}
nodeTypes={nodeTypes} nodeTypes={nodeTypes}
onPaneClick={handlePaneClick} onPaneClick={handlePaneClick}
......
...@@ -12,7 +12,6 @@ import useMyRequest from "@/hooks/useMyRequest"; ...@@ -12,7 +12,6 @@ import useMyRequest from "@/hooks/useMyRequest";
import { IResponse } from "@/api/http"; import { IResponse } from "@/api/http";
import { fetchOperatorList } from "@/api/workbench_api"; import { fetchOperatorList } from "@/api/workbench_api";
import { useStores } from "@/store"; import { useStores } from "@/store";
import { uuid } from "@/utils/util";
import styles from "./index.module.css"; import styles from "./index.module.css";
import MyMenu from "@/components/mui/MyMenu"; import MyMenu from "@/components/mui/MyMenu";
...@@ -25,19 +24,66 @@ import MyMenu from "@/components/mui/MyMenu"; ...@@ -25,19 +24,66 @@ import MyMenu from "@/components/mui/MyMenu";
* @FilePath: /bkunyun/src/views/WorkFlowEdit/components/OperatorList/index.tsx * @FilePath: /bkunyun/src/views/WorkFlowEdit/components/OperatorList/index.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
let count = 1;
const OperatorItem = (props: IOperatorItemProps) => { const OperatorItem = (props: IOperatorItemProps) => {
const { const {
info: { title, description, tags }, info: { title, description, tags },
setTemplateConfigInfo, setTemplateConfigInfo,
templateConfigInfo, templateConfigInfo,
setOperatorListData,
operatorListData,
info,
} = props; } = props;
const [isDragStyle, setIsDragStyle] = useState<boolean>(false); const [isDragStyle, setIsDragStyle] = useState<boolean>(false);
/** 拖拽开始 */ /** 拖拽开始 */
const onDragStart = useCallback(() => { const onDragStart = useCallback(() => {
setIsDragStyle(true); setIsDragStyle(true);
count++;
}, []); }, []);
/** 通过id查找相对的批流数组 */
const getBatchFlowArr = useCallback(
(id: string) => {
const newVal = operatorListData.filter((item) => {
return item.id === id || item.parentNode === id;
});
return newVal;
},
[operatorListData]
);
/** 生成批流副本 */
const getCopyBatchFlowArr = useCallback(
(arr: ITask[], x: number, y: number) => {
const newVal = arr.map((item) => {
const newEdges =
item?.edges &&
item?.edges.map((every) => {
return {
...every,
source: `${every.source}_${count}`,
target: `${every.target}_${count}`,
};
});
return {
...item,
id: `${item.id}_${count}`,
parentNode: item.parentNode ? `${item.parentNode}_${count}` : "",
position: {
x: item.type === "BATCH" ? x : item.position?.x,
y: item.type === "BATCH" ? y : item.position?.y,
},
edges: newEdges.length ? newEdges : item?.edges,
};
});
return newVal;
},
[]
);
/** 拖拽结束 */ /** 拖拽结束 */
const onDragEnd = useCallback( const onDragEnd = useCallback(
(e: React.DragEvent<HTMLDivElement>) => { (e: React.DragEvent<HTMLDivElement>) => {
...@@ -54,27 +100,25 @@ const OperatorItem = (props: IOperatorItemProps) => { ...@@ -54,27 +100,25 @@ const OperatorItem = (props: IOperatorItemProps) => {
clientX < lowerRightX && clientX < lowerRightX &&
clientY < lowerRightY clientY < lowerRightY
) { ) {
console.log( const batchFlowArr = getBatchFlowArr(info.id);
const newBatchFlowArr = getCopyBatchFlowArr(
batchFlowArr,
clientX - upperLeftPointX, clientX - upperLeftPointX,
clientY - upperLeftPointY, clientY - upperLeftPointY
"0000000"
); );
const newVal = [ const newVal = cloneDeep(templateConfigInfo);
...cloneDeep(templateConfigInfo), newVal.push(...newBatchFlowArr);
{
...props.info,
uuid: uuid(),
position: {
x: clientX - upperLeftPointX,
y: clientY - upperLeftPointY,
},
},
];
setTemplateConfigInfo(newVal); setTemplateConfigInfo(newVal);
} }
setIsDragStyle(false); setIsDragStyle(false);
}, },
[props.info, setTemplateConfigInfo, templateConfigInfo] [
getBatchFlowArr,
getCopyBatchFlowArr,
info.id,
setTemplateConfigInfo,
templateConfigInfo,
]
); );
return ( return (
...@@ -152,7 +196,6 @@ const OperatorList = observer((props: IOperatorListProps) => { ...@@ -152,7 +196,6 @@ const OperatorList = observer((props: IOperatorListProps) => {
}); });
} }
}; };
return ( return (
<div className={styles.operatorListBox}> <div className={styles.operatorListBox}>
<div className={styles.searchBox}> <div className={styles.searchBox}>
...@@ -169,12 +212,14 @@ const OperatorList = observer((props: IOperatorListProps) => { ...@@ -169,12 +212,14 @@ const OperatorList = observer((props: IOperatorListProps) => {
</div> </div>
<div className={styles.listBox}> <div className={styles.listBox}>
{operatorListData {operatorListData
// .filter((item) => item.type === "BATCH") .filter((item) => item.type === "BATCH")
.map((item) => { .map((item) => {
return ( return (
<OperatorItem <OperatorItem
key={item.id} key={item.id}
info={item} info={item}
setOperatorListData={setOperatorListData}
operatorListData={operatorListData}
templateConfigInfo={templateConfigInfo} templateConfigInfo={templateConfigInfo}
setTemplateConfigInfo={setTemplateConfigInfo} setTemplateConfigInfo={setTemplateConfigInfo}
/> />
......
...@@ -4,14 +4,16 @@ import { ITask } from "@/views/Project/ProjectSubmitWork/interface" ...@@ -4,14 +4,16 @@ import { ITask } from "@/views/Project/ProjectSubmitWork/interface"
* @Author: 吴永生#A02208 yongsheng.wu@wholion.com * @Author: 吴永生#A02208 yongsheng.wu@wholion.com
* @Date: 2022-07-06 15:32:11 * @Date: 2022-07-06 15:32:11
* @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com * @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com
* @LastEditTime: 2022-07-07 16:22:08 * @LastEditTime: 2022-07-08 16:05:21
* @FilePath: /bkunyun/src/views/WorkFlowEdit/components/OperatorList/interface.ts * @FilePath: /bkunyun/src/views/WorkFlowEdit/components/OperatorList/interface.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
export interface IOperatorItemProps { export interface IOperatorItemProps {
info: ITask info: ITask
setTemplateConfigInfo: (val: ITask[]) => void; setTemplateConfigInfo: (val: ITask[]) => void;
templateConfigInfo: ITask[] templateConfigInfo: ITask[];
setOperatorListData: (val: ITask[]) => void;
operatorListData: ITask[]
} }
export interface IOperatorListProps { export interface IOperatorListProps {
......
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