// 监听节点激活事件
This commit is contained in:
parent
9f48000e83
commit
a15bd11414
@ -6,10 +6,13 @@ import MindMap from "simple-mind-map";
|
|||||||
import ExportPDF from 'simple-mind-map/src/plugins/ExportPDF'
|
import ExportPDF from 'simple-mind-map/src/plugins/ExportPDF'
|
||||||
import ExportXMind from 'simple-mind-map/src/plugins/ExportXMind'
|
import ExportXMind from 'simple-mind-map/src/plugins/ExportXMind'
|
||||||
import Export from 'simple-mind-map/src/plugins/Export'
|
import Export from 'simple-mind-map/src/plugins/Export'
|
||||||
|
import MindMapLayoutPro from 'simple-mind-map/src/plugins/MindMapLayoutPro'
|
||||||
|
|
||||||
|
|
||||||
export function usePlugins(MindMapConstructor: typeof MindMap) {
|
export function usePlugins(MindMapConstructor: typeof MindMap) {
|
||||||
// 注册插件
|
// 注册插件
|
||||||
MindMapConstructor.usePlugin(ExportPDF);
|
MindMapConstructor.usePlugin(ExportPDF);
|
||||||
MindMapConstructor.usePlugin(ExportXMind);
|
MindMapConstructor.usePlugin(ExportXMind);
|
||||||
MindMapConstructor.usePlugin(Export);
|
MindMapConstructor.usePlugin(Export);
|
||||||
|
MindMapConstructor.usePlugin(MindMapLayoutPro)
|
||||||
}
|
}
|
||||||
@ -1,14 +1,15 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { ref } from "vue";
|
import { ref , shallowRef } from "vue";
|
||||||
import { importFile } from "../helpers/import";
|
import { importFile } from "../helpers/import";
|
||||||
import { exportFile } from "../helpers/export";
|
import { exportFile } from "../helpers/export";
|
||||||
import { usePlugins } from "../helpers/usePlugin";
|
import { usePlugins } from "../helpers/usePlugin";
|
||||||
import { insertChildNode } from "../helpers/insertChildNode";
|
import { insertChildNode } from "../helpers/insertChildNode";
|
||||||
import { insertSiblingNode } from "../helpers/insertSiblingNode";
|
import { insertSiblingNode } from "../helpers/insertSiblingNode";
|
||||||
|
|
||||||
|
import type MindMapNode from "simple-mind-map/types/src/core/render/node/MindMapNode";
|
||||||
|
|
||||||
import MindMap from "simple-mind-map";
|
import MindMap from "simple-mind-map";
|
||||||
|
|
||||||
// 使用 defineStore 创建 store
|
|
||||||
export const useMindMapStore = defineStore(
|
export const useMindMapStore = defineStore(
|
||||||
"mindMapStore",
|
"mindMapStore",
|
||||||
() => {
|
() => {
|
||||||
@ -16,12 +17,17 @@ export const useMindMapStore = defineStore(
|
|||||||
|
|
||||||
const mindMapData = ref(null);
|
const mindMapData = ref(null);
|
||||||
|
|
||||||
|
// 激活状态节点
|
||||||
|
const activeNodes = shallowRef<MindMapNode[]>([])
|
||||||
|
|
||||||
|
|
||||||
usePlugins(MindMap);
|
usePlugins(MindMap);
|
||||||
|
|
||||||
function initMindMap(container: HTMLElement) {
|
function initMindMap(container: HTMLElement) {
|
||||||
mindMapInstance = new MindMap({
|
mindMapInstance = new MindMap({
|
||||||
el: container,
|
el: container,
|
||||||
data : null,
|
data : null,
|
||||||
|
layout: 'mindMap',
|
||||||
fit: false,
|
fit: false,
|
||||||
nodeTextEditZIndex: 1000,
|
nodeTextEditZIndex: 1000,
|
||||||
nodeNoteTooltipZIndex: 1000,
|
nodeNoteTooltipZIndex: 1000,
|
||||||
@ -30,10 +36,18 @@ export const useMindMapStore = defineStore(
|
|||||||
demonstrateConfig: {
|
demonstrateConfig: {
|
||||||
openBlankMode: true
|
openBlankMode: true
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 监听节点激活事件
|
||||||
|
mindMapInstance?.on('node_active', (_ : MindMapNode, activeNodeList : MindMapNode[]) => {
|
||||||
|
activeNodes.value = activeNodeList
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 因为避免使用响应对象
|
// 因为避免使用响应对象
|
||||||
function getMindMapInstance (): MindMap | null {
|
function getMindMapInstance (): MindMap | null {
|
||||||
return mindMapInstance;
|
return mindMapInstance;
|
||||||
|
|||||||
4
web3/packages/mind-map/src/types/index.d.ts
vendored
4
web3/packages/mind-map/src/types/index.d.ts
vendored
@ -22,4 +22,8 @@ declare module 'simple-mind-map/src/parse/markdown' {
|
|||||||
import markdown from 'simple-mind-map/types/src/parse/markdown';
|
import markdown from 'simple-mind-map/types/src/parse/markdown';
|
||||||
export default markdown;
|
export default markdown;
|
||||||
}
|
}
|
||||||
|
declare module 'simple-mind-map/src/plugins/MindMapLayoutPro' {
|
||||||
|
import MindMapLayoutPro from 'simple-mind-map/types/src/plugins/MindMapLayoutPro';
|
||||||
|
export default MindMapLayoutPro;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user