Feat:1.优化代码:提取各处获取节点概要数据的兼容代码;2.演示插件支持概要;3.expandToNodeUid方法支持概要节点;4.findNodeByUid方法支持概要节点
This commit is contained in:
parent
706b2ee65d
commit
d60f30d97e
@ -30,7 +30,8 @@ import {
|
|||||||
createSmmFormatData,
|
createSmmFormatData,
|
||||||
checkSmmFormatData,
|
checkSmmFormatData,
|
||||||
checkIsNodeStyleDataKey,
|
checkIsNodeStyleDataKey,
|
||||||
removeRichTextStyes
|
removeRichTextStyes,
|
||||||
|
formatGetNodeGeneralization
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import { shapeList } from './node/Shape'
|
import { shapeList } from './node/Shape'
|
||||||
import { lineStyleProps } from '../../themes/default'
|
import { lineStyleProps } from '../../themes/default'
|
||||||
@ -992,18 +993,13 @@ class Render {
|
|||||||
const _hasCustomStyles = this._handleRemoveCustomStyles(node.data)
|
const _hasCustomStyles = this._handleRemoveCustomStyles(node.data)
|
||||||
if (_hasCustomStyles) hasCustomStyles = true
|
if (_hasCustomStyles) hasCustomStyles = true
|
||||||
// 不要忘记概要节点
|
// 不要忘记概要节点
|
||||||
let generalization = node.data.generalization
|
const generalizationList = formatGetNodeGeneralization(node.data)
|
||||||
if (generalization) {
|
if (generalizationList.length > 0) {
|
||||||
generalization = Array.isArray(generalization)
|
generalizationList.forEach(generalizationData => {
|
||||||
? generalization
|
const _hasCustomStyles =
|
||||||
: [generalization]
|
this._handleRemoveCustomStyles(generalizationData)
|
||||||
if (generalization.length > 0) {
|
if (_hasCustomStyles) hasCustomStyles = true
|
||||||
generalization.forEach(generalizationData => {
|
})
|
||||||
const _hasCustomStyles =
|
|
||||||
this._handleRemoveCustomStyles(generalizationData)
|
|
||||||
if (_hasCustomStyles) hasCustomStyles = true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1840,14 +1836,24 @@ class Render {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
let parentsList = []
|
let parentsList = []
|
||||||
|
let isGeneralization = false
|
||||||
const cache = {}
|
const cache = {}
|
||||||
bfsWalk(this.renderTree, (node, parent) => {
|
bfsWalk(this.renderTree, (node, parent) => {
|
||||||
if (node.data.uid === uid) {
|
if (node.data.uid === uid) {
|
||||||
parentsList = parent ? [...cache[parent.data.uid], parent] : []
|
parentsList = parent ? [...cache[parent.data.uid], parent] : []
|
||||||
return 'stop'
|
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
|
let needRender = false
|
||||||
parentsList.forEach(node => {
|
parentsList.forEach(node => {
|
||||||
@ -1856,6 +1862,18 @@ class Render {
|
|||||||
node.data.expand = true
|
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) {
|
if (needRender) {
|
||||||
this.mindMap.render(callback)
|
this.mindMap.render(callback)
|
||||||
} else {
|
} else {
|
||||||
@ -1871,6 +1889,17 @@ class Render {
|
|||||||
res = node
|
res = node
|
||||||
return true
|
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
|
return res
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,8 @@ import {
|
|||||||
getNodeTreeBoundingRect,
|
getNodeTreeBoundingRect,
|
||||||
fullscrrenEvent,
|
fullscrrenEvent,
|
||||||
fullScreen,
|
fullScreen,
|
||||||
exitFullScreen
|
exitFullScreen,
|
||||||
|
formatGetNodeGeneralization
|
||||||
} from '../utils/index'
|
} from '../utils/index'
|
||||||
import { keyMap } from '../core/command/keyMap'
|
import { keyMap } from '../core/command/keyMap'
|
||||||
|
|
||||||
@ -215,7 +216,11 @@ class Demonstrate {
|
|||||||
// 如果该节点实例不存在,那么先展开到该节点
|
// 如果该节点实例不存在,那么先展开到该节点
|
||||||
if (!node) {
|
if (!node) {
|
||||||
this.mindMap.renderer.expandToNodeUid(uid, () => {
|
this.mindMap.renderer.expandToNodeUid(uid, () => {
|
||||||
this.jump(index)
|
const node = this.mindMap.renderer.findNodeByUid(uid)
|
||||||
|
// 展开后还是没找到,那么就别进入了,否则会死循环
|
||||||
|
if (node) {
|
||||||
|
this.jump(index)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -284,6 +289,19 @@ class Demonstrate {
|
|||||||
type: 'node',
|
type: 'node',
|
||||||
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) {
|
if (node.children.length > 1) {
|
||||||
this.stepList.push({
|
this.stepList.push({
|
||||||
type: 'children',
|
type: 'children',
|
||||||
|
|||||||
@ -8,7 +8,8 @@ import {
|
|||||||
getVisibleColorFromTheme,
|
getVisibleColorFromTheme,
|
||||||
isUndef,
|
isUndef,
|
||||||
checkSmmFormatData,
|
checkSmmFormatData,
|
||||||
removeHtmlNodeByClass
|
removeHtmlNodeByClass,
|
||||||
|
formatGetNodeGeneralization
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { CONSTANTS } from '../constants/constant'
|
import { CONSTANTS } from '../constants/constant'
|
||||||
|
|
||||||
@ -651,13 +652,9 @@ class RichText {
|
|||||||
node.data.text = getTextFromHtml(node.data.text)
|
node.data.text = getTextFromHtml(node.data.text)
|
||||||
}
|
}
|
||||||
// 概要
|
// 概要
|
||||||
let generalization =
|
if (node.data) {
|
||||||
node.data && node.data.generalization ? node.data.generalization : []
|
const generalizationList = formatGetNodeGeneralization(node.data)
|
||||||
generalization = Array.isArray(generalization)
|
generalizationList.forEach(item => {
|
||||||
? generalization
|
|
||||||
: [generalization]
|
|
||||||
if (generalization.length > 0) {
|
|
||||||
generalization.forEach(item => {
|
|
||||||
item.richText = false
|
item.richText = false
|
||||||
item.text = getTextFromHtml(item.text)
|
item.text = getTextFromHtml(item.text)
|
||||||
})
|
})
|
||||||
@ -682,13 +679,9 @@ class RichText {
|
|||||||
root.data.resetRichText = true
|
root.data.resetRichText = true
|
||||||
}
|
}
|
||||||
// 概要
|
// 概要
|
||||||
let generalization =
|
if (root.data) {
|
||||||
root.data && root.data.generalization ? root.data.generalization : []
|
const generalizationList = formatGetNodeGeneralization(root.data)
|
||||||
generalization = Array.isArray(generalization)
|
generalizationList.forEach(item => {
|
||||||
? generalization
|
|
||||||
: [generalization]
|
|
||||||
if (generalization.length > 0) {
|
|
||||||
generalization.forEach(item => {
|
|
||||||
item.richText = true
|
item.richText = true
|
||||||
item.resetRichText = true
|
item.resetRichText = true
|
||||||
})
|
})
|
||||||
|
|||||||
@ -157,16 +157,10 @@ export const copyRenderTree = (tree, root, removeActiveState = false) => {
|
|||||||
tree.data = simpleDeepClone(root.data)
|
tree.data = simpleDeepClone(root.data)
|
||||||
if (removeActiveState) {
|
if (removeActiveState) {
|
||||||
tree.data.isActive = false
|
tree.data.isActive = false
|
||||||
const generalization = tree.data.generalization
|
const generalizationList = formatGetNodeGeneralization(tree.data)
|
||||||
if (generalization) {
|
generalizationList.forEach(item => {
|
||||||
if (Array.isArray(generalization)) {
|
item.isActive = false
|
||||||
generalization.forEach(item => {
|
})
|
||||||
item.isActive = false
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
generalization.isActive = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tree.children = []
|
tree.children = []
|
||||||
if (root.children && root.children.length > 0) {
|
if (root.children && root.children.length > 0) {
|
||||||
@ -1472,3 +1466,13 @@ export const createForeignObjectNode = ({ el, width, height }) => {
|
|||||||
foreignObject.add(el)
|
foreignObject.add(el)
|
||||||
return foreignObject
|
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
@ -789,7 +789,7 @@ export default {
|
|||||||
if (this.mindMap.cooperate && this.$route.query.userName) {
|
if (this.mindMap.cooperate && this.$route.query.userName) {
|
||||||
this.mindMap.cooperate.setProvider(null, {
|
this.mindMap.cooperate.setProvider(null, {
|
||||||
roomName: 'demo-room',
|
roomName: 'demo-room',
|
||||||
signalingList: ['ws://10.16.83.118:4444']
|
signalingList: ['ws://localhost:4444']
|
||||||
})
|
})
|
||||||
this.mindMap.cooperate.setUserInfo({
|
this.mindMap.cooperate.setUserInfo({
|
||||||
id: Math.random(),
|
id: Math.random(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user