Feat:修改节点uid的创建

This commit is contained in:
wanglin2
2023-07-17 09:59:47 +08:00
parent 94230f8ec6
commit adccef5699
6 changed files with 17 additions and 11 deletions

View File

@@ -32,9 +32,6 @@ class MindMap {
this.svg = SVG().addTo(this.el).size(this.width, this.height)
this.draw = this.svg.group()
// 节点id
this.uid = 1
// 初始化主题
this.initTheme()
@@ -238,7 +235,7 @@ class MindMap {
// 获取思维导图数据,节点树、主题、布局等
getData(withConfig) {
let nodeData = this.command.removeDataUid(this.command.getCopyData())
let nodeData = this.command.getCopyData()
let data = {}
if (withConfig) {
data = {

View File

@@ -1,11 +1,11 @@
{
"name": "simple-mind-map",
"version": "0.6.0",
"version": "0.6.7",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "0.6.0",
"version": "0.6.7",
"license": "MIT",
"dependencies": {
"@svgdotjs/svg.js": "^3.0.16",

View File

@@ -89,7 +89,7 @@ class Command {
this.history.shift()
}
this.activeHistoryIndex = this.history.length - 1
this.mindMap.emit('data_change', this.removeDataUid(data))
this.mindMap.emit('data_change', data)
this.mindMap.emit(
'back_forward',
this.activeHistoryIndex,
@@ -110,7 +110,7 @@ class Command {
this.history.length
)
let data = simpleDeepClone(this.history[this.activeHistoryIndex])
this.mindMap.emit('data_change', this.removeDataUid(data))
this.mindMap.emit('data_change', data)
return data
}
}
@@ -125,7 +125,7 @@ class Command {
this.activeHistoryIndex += step
this.mindMap.emit('back_forward', this.activeHistoryIndex, this.history.length)
let data = simpleDeepClone(this.history[this.activeHistoryIndex])
this.mindMap.emit('data_change', this.removeDataUid(data))
this.mindMap.emit('data_change', data)
return data
}
}

View File

@@ -1,4 +1,5 @@
import Node from './Node'
import { createUid } from '../../../utils/index'
// 检查是否存在概要
function checkHasGeneralization () {
@@ -18,7 +19,7 @@ function createGeneralizationNode () {
data: {
data: this.nodeData.data.generalization
},
uid: this.mindMap.uid++,
uid: createUid(),
renderer: this.renderer,
mindMap: this.mindMap,
draw: this.draw,

View File

@@ -1,6 +1,7 @@
import Node from '../core/render/node/Node'
import { CONSTANTS, initRootNodePositionMap } from '../constants/constant'
import Lru from '../utils/Lru'
import { createUid } from '../utils/index'
// 布局基类
class Base {
@@ -101,7 +102,7 @@ class Base {
}
} else {
// 创建新节点
let uid = this.mindMap.uid++
let uid = createUid()
newNode = new Node({
data,
uid,

View File

@@ -1,3 +1,5 @@
import { v4 as uuidv4 } from 'uuid'
// 深度优先遍历树
export const walk = (
root,
@@ -424,3 +426,8 @@ export const getImageSize = src => {
}
})
}
// 创建节点唯一的id
export const createUid = () => {
return uuidv4()
}