Feat:walk方法增加祖先列表回调参数

This commit is contained in:
街角小林 2024-08-13 10:57:01 +08:00
parent 13a1f989c3
commit 1620a013ba
8 changed files with 26 additions and 19 deletions

View File

@ -32,8 +32,8 @@ class CatalogOrganization extends Base {
walk(
this.renderer.renderTree,
null,
(cur, parent, isRoot, layerIndex) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
(cur, parent, isRoot, layerIndex, index, ancestors) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
// 根节点定位在画布中心位置
if (isRoot) {
this.setNodeCenter(newNode)

View File

@ -36,9 +36,9 @@ class Fishbone extends Base {
walk(
this.renderer.renderTree,
null,
(node, parent, isRoot, layerIndex, index) => {
(node, parent, isRoot, layerIndex, index, ancestors) => {
// 创建节点
let newNode = this.createNode(node, parent, isRoot, layerIndex)
let newNode = this.createNode(node, parent, isRoot, layerIndex, index, ancestors)
// 根节点定位在画布中心位置
if (isRoot) {
this.setNodeCenter(newNode)

View File

@ -35,8 +35,8 @@ class LogicalStructure extends Base {
walk(
this.renderer.renderTree,
null,
(cur, parent, isRoot, layerIndex) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
(cur, parent, isRoot, layerIndex, index, ancestors) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
newNode.sortIndex = sortIndex
sortIndex++
// 根节点定位在画布中心位置

View File

@ -34,8 +34,8 @@ class MindMap extends Base {
walk(
this.renderer.renderTree,
null,
(cur, parent, isRoot, layerIndex, index) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
(cur, parent, isRoot, layerIndex, index, ancestors) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
// 根节点定位在画布中心位置
if (isRoot) {
this.setNodeCenter(newNode)

View File

@ -33,8 +33,8 @@ class OrganizationStructure extends Base {
walk(
this.renderer.renderTree,
null,
(cur, parent, isRoot, layerIndex) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
(cur, parent, isRoot, layerIndex, index, ancestors) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
// 根节点定位在画布中心位置
if (isRoot) {
this.setNodeCenter(newNode)

View File

@ -34,8 +34,8 @@ class Timeline extends Base {
walk(
this.renderer.renderTree,
null,
(cur, parent, isRoot, layerIndex, index) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
(cur, parent, isRoot, layerIndex, index, ancestors) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
// 根节点定位在画布中心位置
if (isRoot) {
this.setNodeCenter(newNode)

View File

@ -34,8 +34,8 @@ class VerticalTimeline extends Base {
walk(
this.renderer.renderTree,
null,
(cur, parent, isRoot, layerIndex, index) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex)
(cur, parent, isRoot, layerIndex, index, ancestors) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex, index, ancestors)
// 根节点定位在画布中心位置
if (isRoot) {
this.setNodeCenter(newNode)

View File

@ -14,11 +14,12 @@ export const walk = (
afterCallback,
isRoot,
layerIndex = 0,
index = 0
index = 0,
ancestors = []
) => {
let stop = false
if (beforeCallback) {
stop = beforeCallback(root, parent, isRoot, layerIndex, index)
stop = beforeCallback(root, parent, isRoot, layerIndex, index, ancestors)
}
if (!stop && root.children && root.children.length > 0) {
let _layerIndex = layerIndex + 1
@ -30,11 +31,13 @@ export const walk = (
afterCallback,
false,
_layerIndex,
nodeIndex
nodeIndex,
[...ancestors, root]
)
})
}
afterCallback && afterCallback(root, parent, isRoot, layerIndex, index)
afterCallback &&
afterCallback(root, parent, isRoot, layerIndex, index, ancestors)
}
// 广度优先遍历树
@ -948,7 +951,11 @@ export const addDataToAppointNodes = (appointNodes, data = {}) => {
// 给指定的节点列表树数据添加uid会修改原数据
// createNewId默认为false即如果节点不存在uid的话会创建新的uid。如果传true那么无论节点数据原来是否存在uid都会创建新的uid
export const createUidForAppointNodes = (appointNodes, createNewId = false, handle = null) => {
export const createUidForAppointNodes = (
appointNodes,
createNewId = false,
handle = null
) => {
const walk = list => {
list.forEach(node => {
if (!node.data) {