|
@@ -1,9 +1,6 @@
|
|
|
import { Graph, Cell, Node, Edge, EventArgs } from "@antv/x6";
|
|
|
import { BorderSize, StructureType, TopicType } from "@/enum";
|
|
|
-import {
|
|
|
- addTopic,
|
|
|
- updateTopic,
|
|
|
-} from "@/pages/mindmap/mindMap";
|
|
|
+import { addTopic, updateTopic } from "@/pages/mindmap/mindMap";
|
|
|
import { cellStyle, MindMapProjectInfo, TopicItem } from "@/types";
|
|
|
import { Dnd } from "@antv/x6-plugin-dnd";
|
|
|
import { selectTopic } from "@/utils/mindmapHander";
|
|
@@ -11,7 +8,7 @@ import { uuid } from "@/utils";
|
|
|
import { getTheme } from "@/pages/mindmap/theme";
|
|
|
import { traverseNode } from "@/utils/mindmapHander";
|
|
|
import { EditMindMapElement, AddMindMapElement } from "@/api/systemDesigner";
|
|
|
-import { debounce, isEqual } from "lodash-es"
|
|
|
+import { debounce, isEqual } from "lodash-es";
|
|
|
|
|
|
enum positionType {
|
|
|
left = "left",
|
|
@@ -29,7 +26,12 @@ let currentShadowNode: Node | undefined;
|
|
|
|
|
|
export const bindMindMapEvents = (
|
|
|
graph: Graph,
|
|
|
- setMindProjectInfo?: (info: MindMapProjectInfo) => void,
|
|
|
+ setMindProjectInfo?: (
|
|
|
+ info: MindMapProjectInfo,
|
|
|
+ init?: boolean,
|
|
|
+ isSetting?: boolean,
|
|
|
+ ignoreRender?: boolean
|
|
|
+ ) => void,
|
|
|
setSelectedCell?: (cell: Cell[]) => void,
|
|
|
dndRef?: React.MutableRefObject<Dnd | undefined>
|
|
|
) => {
|
|
@@ -172,14 +174,20 @@ export const bindMindMapEvents = (
|
|
|
// 双击画布空白-新增自由主题
|
|
|
graph.on("blank:dblclick", (args) => {
|
|
|
if (setMindProjectInfo) {
|
|
|
- const topic = addTopic(TopicType.branch, setMindProjectInfo, graph, undefined, {
|
|
|
- x: args.x,
|
|
|
- y: args.y,
|
|
|
+ const topic = addTopic(
|
|
|
+ TopicType.branch,
|
|
|
setMindProjectInfo,
|
|
|
- type: TopicType.branch,
|
|
|
- label: "自由主题",
|
|
|
- borderSize: BorderSize.medium,
|
|
|
- });
|
|
|
+ graph,
|
|
|
+ undefined,
|
|
|
+ {
|
|
|
+ x: args.x,
|
|
|
+ y: args.y,
|
|
|
+ setMindProjectInfo,
|
|
|
+ type: TopicType.branch,
|
|
|
+ label: "自由主题",
|
|
|
+ borderSize: BorderSize.medium,
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
selectTopic(graph, topic);
|
|
|
}
|
|
@@ -190,7 +198,7 @@ export const bindMindMapEvents = (
|
|
|
*/
|
|
|
graph.on("node:change:data", (args) => {
|
|
|
const { current, previous } = args;
|
|
|
- console.log('数据变更:', current, previous)
|
|
|
+ console.log("数据变更:", current, previous);
|
|
|
// 收折子项 setMindProjectInfo更新会重新渲染
|
|
|
if (current.collapsed !== previous.collapsed) {
|
|
|
setMindProjectInfo &&
|
|
@@ -204,7 +212,12 @@ export const bindMindMapEvents = (
|
|
|
}
|
|
|
if (current?.links && current.links.length !== previous?.links?.length) {
|
|
|
setMindProjectInfo &&
|
|
|
- updateTopic(args.cell.id, { links: current.links }, setMindProjectInfo, graph);
|
|
|
+ updateTopic(
|
|
|
+ args.cell.id,
|
|
|
+ { links: current.links },
|
|
|
+ setMindProjectInfo,
|
|
|
+ graph
|
|
|
+ );
|
|
|
}
|
|
|
if (current?.border !== previous?.border) {
|
|
|
setMindProjectInfo &&
|
|
@@ -243,16 +256,26 @@ export const bindMindMapEvents = (
|
|
|
graph
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 本地缓存更新不会重新渲染
|
|
|
if (args.cell.id.includes("-border")) {
|
|
|
- updateTopic(args.current.origin, { border: current }, (info) => {
|
|
|
- sessionStorage.setItem("mindMapProjectInfo", JSON.stringify(info));
|
|
|
- }, graph);
|
|
|
+ updateTopic(
|
|
|
+ args.current.origin,
|
|
|
+ { border: current },
|
|
|
+ (info) => {
|
|
|
+ setMindProjectInfo?.(info, false, false, true);
|
|
|
+ },
|
|
|
+ graph
|
|
|
+ );
|
|
|
} else {
|
|
|
- updateTopic(args.cell.id, current, (info) => {
|
|
|
- sessionStorage.setItem("mindMapProjectInfo", JSON.stringify(info));
|
|
|
- }, graph);
|
|
|
+ updateTopic(
|
|
|
+ args.cell.id,
|
|
|
+ current,
|
|
|
+ (info) => {
|
|
|
+ setMindProjectInfo?.(info, false, false, true);
|
|
|
+ },
|
|
|
+ graph
|
|
|
+ );
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -261,29 +284,36 @@ export const bindMindMapEvents = (
|
|
|
fixedWidth: true,
|
|
|
width: args.node.size().width,
|
|
|
height: args.node.size().height,
|
|
|
- })
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- graph.on("node:change:position", debounce((args) => {
|
|
|
- const { current } = args;
|
|
|
- if (args.cell.isNode() && !args.cell.data?.parentId && args.cell.data.type !== TopicType.main) {
|
|
|
- updateTopic(
|
|
|
- args.cell.id,
|
|
|
- { ...args.cell.data, x: current?.x, y: current?.y },
|
|
|
- (info) => {
|
|
|
- // localStorage.setItem("minMapProjectInfo", JSON.stringify(info));
|
|
|
- setMindProjectInfo && setMindProjectInfo(info);
|
|
|
- },
|
|
|
- graph
|
|
|
- );
|
|
|
- EditMindMapElement({
|
|
|
- ...args.cell.data,
|
|
|
- ...args.current,
|
|
|
- graphId: sessionStorage.getItem("projectId"),
|
|
|
- tools: ''
|
|
|
- });
|
|
|
- }
|
|
|
- }, 500));
|
|
|
+ graph.on(
|
|
|
+ "node:change:position",
|
|
|
+ debounce((args) => {
|
|
|
+ const { current } = args;
|
|
|
+ if (
|
|
|
+ args.cell.isNode() &&
|
|
|
+ !args.cell.data?.parentId &&
|
|
|
+ args.cell.data.type !== TopicType.main
|
|
|
+ ) {
|
|
|
+ updateTopic(
|
|
|
+ args.cell.id,
|
|
|
+ { ...args.cell.data, x: current?.x, y: current?.y },
|
|
|
+ (info) => {
|
|
|
+ // localStorage.setItem("minMapProjectInfo", JSON.stringify(info));
|
|
|
+ setMindProjectInfo && setMindProjectInfo(info);
|
|
|
+ },
|
|
|
+ graph
|
|
|
+ );
|
|
|
+ EditMindMapElement({
|
|
|
+ ...args.cell.data,
|
|
|
+ ...args.current,
|
|
|
+ graphId: sessionStorage.getItem("projectId"),
|
|
|
+ tools: "",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, 500)
|
|
|
+ );
|
|
|
|
|
|
/**
|
|
|
* 连接线更改
|
|
@@ -320,7 +350,6 @@ export const bindMindMapEvents = (
|
|
|
);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
};
|
|
|
|
|
|
const canBeFreeNode = (x: number, y: number, node: Node): boolean => {
|