Feat:1.优化代码:提取各处获取节点概要数据的兼容代码;2.演示插件支持概要;3.expandToNodeUid方法支持概要节点;4.findNodeByUid方法支持概要节点

This commit is contained in:
街角小林
2024-05-10 09:51:58 +08:00
parent 706b2ee65d
commit d60f30d97e
6 changed files with 90 additions and 55 deletions

View File

@@ -30,7 +30,8 @@ import {
createSmmFormatData,
checkSmmFormatData,
checkIsNodeStyleDataKey,
removeRichTextStyes
removeRichTextStyes,
formatGetNodeGeneralization
} from '../../utils'
import { shapeList } from './node/Shape'
import { lineStyleProps } from '../../themes/default'
@@ -992,18 +993,13 @@ class Render {
const _hasCustomStyles = this._handleRemoveCustomStyles(node.data)
if (_hasCustomStyles) hasCustomStyles = true
// 不要忘记概要节点
let generalization = node.data.generalization
if (generalization) {
generalization = Array.isArray(generalization)
? generalization
: [generalization]
if (generalization.length > 0) {
generalization.forEach(generalizationData => {
const _hasCustomStyles =
this._handleRemoveCustomStyles(generalizationData)
if (_hasCustomStyles) hasCustomStyles = true
})
}
const generalizationList = formatGetNodeGeneralization(node.data)
if (generalizationList.length > 0) {
generalizationList.forEach(generalizationData => {
const _hasCustomStyles =
this._handleRemoveCustomStyles(generalizationData)
if (_hasCustomStyles) hasCustomStyles = true
})
}
})
}
@@ -1840,14 +1836,24 @@ class Render {
return
}
let parentsList = []
let isGeneralization = false
const cache = {}
bfsWalk(this.renderTree, (node, parent) => {
if (node.data.uid === uid) {
parentsList = parent ? [...cache[parent.data.uid], parent] : []
return 'stop'
} else {
cache[node.data.uid] = parent ? [...cache[parent.data.uid], parent] : []
}
const generalizationList = formatGetNodeGeneralization(node.data)
generalizationList.forEach(item => {
if (item.uid === uid) {
parentsList = parent ? [...cache[parent.data.uid], parent] : []
isGeneralization = true
}
})
if (isGeneralization) {
return 'stop'
}
cache[node.data.uid] = parent ? [...cache[parent.data.uid], parent] : []
})
let needRender = false
parentsList.forEach(node => {
@@ -1856,6 +1862,18 @@ class Render {
node.data.expand = true
}
})
// 如果是展开到概要节点,那么父节点下的所有节点都需要开
if (isGeneralization) {
const lastNode = parentsList[parentsList.length - 1]
if (lastNode) {
walk(lastNode, null, node => {
if (!node.data.expand) {
needRender = true
node.data.expand = true
}
})
}
}
if (needRender) {
this.mindMap.render(callback)
} else {
@@ -1871,6 +1889,17 @@ class Render {
res = node
return true
}
// 概要节点
let isGeneralization = false
;(node._generalizationList || []).forEach(item => {
if (item.generalizationNode.getData('uid') === uid) {
res = item.generalizationNode
isGeneralization = true
}
})
if (isGeneralization) {
return true
}
})
return res
}

View File

@@ -3,7 +3,8 @@ import {
getNodeTreeBoundingRect,
fullscrrenEvent,
fullScreen,
exitFullScreen
exitFullScreen,
formatGetNodeGeneralization
} from '../utils/index'
import { keyMap } from '../core/command/keyMap'
@@ -215,7 +216,11 @@ class Demonstrate {
// 如果该节点实例不存在,那么先展开到该节点
if (!node) {
this.mindMap.renderer.expandToNodeUid(uid, () => {
this.jump(index)
const node = this.mindMap.renderer.findNodeByUid(uid)
// 展开后还是没找到,那么就别进入了,否则会死循环
if (node) {
this.jump(index)
}
})
return
}
@@ -284,6 +289,19 @@ class Demonstrate {
type: 'node',
node
})
// 添加概要步骤
const generalizationList = formatGetNodeGeneralization(node.data)
generalizationList.forEach(item => {
// 没有uid的直接过滤掉否则会死循环
if (item.uid) {
this.stepList.push({
type: 'node',
node: {
data: item
}
})
}
})
if (node.children.length > 1) {
this.stepList.push({
type: 'children',

View File

@@ -8,7 +8,8 @@ import {
getVisibleColorFromTheme,
isUndef,
checkSmmFormatData,
removeHtmlNodeByClass
removeHtmlNodeByClass,
formatGetNodeGeneralization
} from '../utils'
import { CONSTANTS } from '../constants/constant'
@@ -651,13 +652,9 @@ class RichText {
node.data.text = getTextFromHtml(node.data.text)
}
// 概要
let generalization =
node.data && node.data.generalization ? node.data.generalization : []
generalization = Array.isArray(generalization)
? generalization
: [generalization]
if (generalization.length > 0) {
generalization.forEach(item => {
if (node.data) {
const generalizationList = formatGetNodeGeneralization(node.data)
generalizationList.forEach(item => {
item.richText = false
item.text = getTextFromHtml(item.text)
})
@@ -682,13 +679,9 @@ class RichText {
root.data.resetRichText = true
}
// 概要
let generalization =
root.data && root.data.generalization ? root.data.generalization : []
generalization = Array.isArray(generalization)
? generalization
: [generalization]
if (generalization.length > 0) {
generalization.forEach(item => {
if (root.data) {
const generalizationList = formatGetNodeGeneralization(root.data)
generalizationList.forEach(item => {
item.richText = true
item.resetRichText = true
})

View File

@@ -157,16 +157,10 @@ export const copyRenderTree = (tree, root, removeActiveState = false) => {
tree.data = simpleDeepClone(root.data)
if (removeActiveState) {
tree.data.isActive = false
const generalization = tree.data.generalization
if (generalization) {
if (Array.isArray(generalization)) {
generalization.forEach(item => {
item.isActive = false
})
} else {
generalization.isActive = false
}
}
const generalizationList = formatGetNodeGeneralization(tree.data)
generalizationList.forEach(item => {
item.isActive = false
})
}
tree.children = []
if (root.children && root.children.length > 0) {
@@ -1472,3 +1466,13 @@ export const createForeignObjectNode = ({ el, width, height }) => {
foreignObject.add(el)
return foreignObject
}
// 格式化获取节点的概要数据
export const formatGetNodeGeneralization = data => {
const generalization = data.generalization
if (generalization) {
return Array.isArray(generalization) ? generalization : [generalization]
} else {
return []
}
}

File diff suppressed because one or more lines are too long

View File

@@ -789,7 +789,7 @@ export default {
if (this.mindMap.cooperate && this.$route.query.userName) {
this.mindMap.cooperate.setProvider(null, {
roomName: 'demo-room',
signalingList: ['ws://10.16.83.118:4444']
signalingList: ['ws://localhost:4444']
})
this.mindMap.cooperate.setUserInfo({
id: Math.random(),