|
@@ -2,7 +2,6 @@ import { Graph, Cell, Node, Edge, EventArgs } from "@antv/x6";
|
|
|
import { BorderSize, StructureType, TopicType } from "@/enum";
|
|
|
import {
|
|
|
addTopic,
|
|
|
- getMindMapProjectByLocal,
|
|
|
updateTopic,
|
|
|
} from "@/pages/mindmap/mindMap";
|
|
|
import { cellStyle, MindMapProjectInfo, TopicItem } from "@/types";
|
|
@@ -174,7 +173,7 @@ export const bindMindMapEvents = (
|
|
|
// 双击画布空白-新增自由主题
|
|
|
graph.on("blank:dblclick", (args) => {
|
|
|
if (setMindProjectInfo) {
|
|
|
- const topic = addTopic(TopicType.branch, setMindProjectInfo, undefined, {
|
|
|
+ const topic = addTopic(TopicType.branch, setMindProjectInfo, graph, undefined, {
|
|
|
x: args.x,
|
|
|
y: args.y,
|
|
|
setMindProjectInfo,
|
|
@@ -192,27 +191,28 @@ export const bindMindMapEvents = (
|
|
|
*/
|
|
|
graph.on("node:change:data", (args) => {
|
|
|
const { current, previous } = args;
|
|
|
- console.log("修改数据:", args);
|
|
|
// 收折子项 setMindProjectInfo更新会重新渲染
|
|
|
if (current.collapsed !== previous.collapsed) {
|
|
|
setMindProjectInfo &&
|
|
|
updateTopic(
|
|
|
args.cell.id,
|
|
|
{ collapsed: current.collapsed },
|
|
|
- setMindProjectInfo
|
|
|
+ setMindProjectInfo,
|
|
|
+ graph
|
|
|
);
|
|
|
return;
|
|
|
}
|
|
|
if (current?.links && current.links.length !== previous?.links?.length) {
|
|
|
setMindProjectInfo &&
|
|
|
- updateTopic(args.cell.id, { links: current.links }, setMindProjectInfo);
|
|
|
+ updateTopic(args.cell.id, { links: current.links }, setMindProjectInfo, graph);
|
|
|
}
|
|
|
if (current?.border !== previous?.border) {
|
|
|
setMindProjectInfo &&
|
|
|
updateTopic(
|
|
|
args.cell.id,
|
|
|
{ border: current.border },
|
|
|
- setMindProjectInfo
|
|
|
+ setMindProjectInfo,
|
|
|
+ graph
|
|
|
);
|
|
|
}
|
|
|
if (current?.summary !== previous?.summary) {
|
|
@@ -220,7 +220,8 @@ export const bindMindMapEvents = (
|
|
|
updateTopic(
|
|
|
args.cell.id,
|
|
|
{ summary: current.summary },
|
|
|
- setMindProjectInfo
|
|
|
+ setMindProjectInfo,
|
|
|
+ graph
|
|
|
);
|
|
|
}
|
|
|
if (current?.extraModules !== previous?.extraModules) {
|
|
@@ -228,23 +229,23 @@ export const bindMindMapEvents = (
|
|
|
updateTopic(
|
|
|
args.cell.id,
|
|
|
{ extraModules: current.extraModules },
|
|
|
- setMindProjectInfo
|
|
|
+ setMindProjectInfo,
|
|
|
+ graph
|
|
|
);
|
|
|
}
|
|
|
// 本地缓存更新不会重新渲染
|
|
|
if (args.cell.id.includes("-border")) {
|
|
|
updateTopic(args.current.origin, { border: current }, (info) => {
|
|
|
sessionStorage.setItem("mindMapProjectInfo", JSON.stringify(info));
|
|
|
- });
|
|
|
+ }, graph);
|
|
|
} else {
|
|
|
updateTopic(args.cell.id, current, (info) => {
|
|
|
sessionStorage.setItem("mindMapProjectInfo", JSON.stringify(info));
|
|
|
- });
|
|
|
+ }, graph);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
graph.on("node:resized", (args) => {
|
|
|
- console.log('修改完成:', args)
|
|
|
args.node.setData({
|
|
|
fixedWidth: true,
|
|
|
width: args.node.size().width,
|
|
@@ -261,7 +262,8 @@ export const bindMindMapEvents = (
|
|
|
(info) => {
|
|
|
// localStorage.setItem("minMapProjectInfo", JSON.stringify(info));
|
|
|
setMindProjectInfo && setMindProjectInfo(info);
|
|
|
- }
|
|
|
+ },
|
|
|
+ graph
|
|
|
);
|
|
|
EditMindMapElement({
|
|
|
...args.cell.data,
|
|
@@ -309,16 +311,16 @@ export const bindMindMapEvents = (
|
|
|
});
|
|
|
|
|
|
// 修改主题 传给后端
|
|
|
- graph.on("node:change:*", (args: EventArgs["node:change:*"]) => {
|
|
|
- const graphId = sessionStorage.getItem("projectId");
|
|
|
- if(graphId && !args.current?.parentId && args.key === "data") {
|
|
|
- EditMindMapElement({
|
|
|
- ...args.current,
|
|
|
- graphId,
|
|
|
- tools: ''
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
+ // graph.on("node:change:*", (args: EventArgs["node:change:*"]) => {
|
|
|
+ // const graphId = sessionStorage.getItem("projectId");
|
|
|
+ // if(graphId && !args.current?.parentId && args.key === "data") {
|
|
|
+ // EditMindMapElement({
|
|
|
+ // ...args.current,
|
|
|
+ // graphId,
|
|
|
+ // tools: ''
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
};
|
|
|
|
|
|
const canBeFreeNode = (x: number, y: number, node: Node): boolean => {
|
|
@@ -445,7 +447,8 @@ const setIndicator = (
|
|
|
addIndicator(x, y, graph, targetNode, atPosition);
|
|
|
}
|
|
|
} else {
|
|
|
- const mindProjectInfo = getMindMapProjectByLocal();
|
|
|
+ // @ts-ignore
|
|
|
+ const mindProjectInfo = graph.extendAttr.getMindProjectInfo();
|
|
|
if (mindProjectInfo?.structure === StructureType.left) {
|
|
|
addIndicator(x, y, graph, targetNode, atPosition);
|
|
|
}
|
|
@@ -467,7 +470,8 @@ const setIndicator = (
|
|
|
addIndicator(x, y, graph, targetNode, atPosition);
|
|
|
}
|
|
|
} else {
|
|
|
- const mindProjectInfo = getMindMapProjectByLocal();
|
|
|
+ // @ts-ignore
|
|
|
+ const mindProjectInfo = graph.extendAttr.getMindProjectInfo();
|
|
|
if (mindProjectInfo?.structure === StructureType.right) {
|
|
|
addIndicator(x, y, graph, targetNode, atPosition);
|
|
|
}
|
|
@@ -554,7 +558,8 @@ const handleSwitchPosition = (
|
|
|
position?: { x: number; y: number },
|
|
|
graph?: Graph
|
|
|
) => {
|
|
|
- const mindmapProjectInfo = getMindMapProjectByLocal();
|
|
|
+ // @ts-ignore
|
|
|
+ const mindmapProjectInfo: MindMapProjectInfo = graph.extendAttr.getMindProjectInfo();
|
|
|
if (!mindmapProjectInfo) return;
|
|
|
|
|
|
// 找到要拖拽的节点并删除
|