修复概要的一些bug

This commit is contained in:
wanglin2 2022-08-02 08:59:05 +08:00
parent a804a5e2fa
commit 0620d31d0a
4 changed files with 35 additions and 38 deletions

View File

@ -879,18 +879,6 @@ const data5 = {
} }
}, },
"children": [ "children": [
{
"data": {
"text": "子节点"
},
"children": []
},
{
"data": {
"text": "子节点"
},
"children": []
},
{ {
"data": { "data": {
"text": "子节点" "text": "子节点"
@ -905,25 +893,6 @@ const data5 = {
} }
] ]
}, },
{
"data": {
"text": "二级节点2"
},
"children": [
{
"data": {
"text": "子节点"
},
"children": []
},
{
"data": {
"text": "子节点"
},
"children": []
}
]
}
] ]
} }
} }
@ -945,7 +914,7 @@ export default {
...data5, ...data5,
// ...rootData, // ...rootData,
"theme": { "theme": {
"template": "minions", "template": "classic4",
"config": { "config": {
// 自定义配置... // 自定义配置...
} }

View File

@ -208,6 +208,8 @@ class Node {
this.group.remove() this.group.remove()
this.group = null this.group = null
} }
// 概要
this.removeGeneralization()
} }
/** /**
@ -508,6 +510,10 @@ class Node {
let { paddingY } = this.getPaddingVale() let { paddingY } = this.getPaddingVale()
// 创建组 // 创建组
this.group = new G() this.group = new G()
// 概要节点添加一个带所属节点id的类名
if (this.isGeneralization && this.generalizationBelongNode) {
this.group.addClass('generalization_' + this.generalizationBelongNode.uid)
}
this.draw.add(this.group) this.draw.add(this.group)
this.update(true) this.update(true)
// 节点矩形 // 节点矩形
@ -700,7 +706,6 @@ class Node {
this.removeAllEvent() this.removeAllEvent()
this.removeAllNode() this.removeAllNode()
this.removeLine() this.removeLine()
this.removeGeneralization()
// 子节点 // 子节点
if (this.children && this.children.length) { if (this.children && this.children.length) {
asyncRun(this.children.map((item) => { asyncRun(this.children.map((item) => {
@ -844,10 +849,21 @@ class Node {
} }
} }
/**
* javascript comment
* @Author: 王林25
* @Date: 2022-08-01 15:38:52
* @Desc: 更新概要节点
*/
updateGeneralization() {
this.removeGeneralization()
this.createGeneralizationNode()
}
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2022-07-30 08:35:51 * @Date: 2022-07-30 08:35:51
* @Desc: 创建概要节点 * @Desc: 渲染概要节点
*/ */
renderGeneralization() { renderGeneralization() {
if (this.isGeneralization) { if (this.isGeneralization) {
@ -880,9 +896,15 @@ class Node {
this._generalizationLine = null this._generalizationLine = null
} }
if (this._generalizationNode) { if (this._generalizationNode) {
// 删除概要节点时要同步从激活节点里删除
this.renderer.removeActiveNode(this._generalizationNode)
this._generalizationNode.remove() this._generalizationNode.remove()
this._generalizationNode = null this._generalizationNode = null
} }
// hack修复当激活一个节点时创建概要然后立即激活创建的概要节点后会重复创建概要节点并且无法删除的问题
if (this.generalizationBelongNode) {
this.draw.find('.generalization_' + this.generalizationBelongNode.uid).remove()
}
} }
/** /**

View File

@ -119,6 +119,10 @@ export default class TextEdit {
this.renderer.activeNodeList.forEach((node) => { this.renderer.activeNodeList.forEach((node) => {
let str = getStrWithBrFromHtml(this.textEditNode.innerHTML) let str = getStrWithBrFromHtml(this.textEditNode.innerHTML)
this.mindMap.execCommand('SET_NODE_TEXT', node, str) this.mindMap.execCommand('SET_NODE_TEXT', node, str)
if (node.isGeneralization) {
// 概要节点
node.generalizationBelongNode.updateGeneralization()
}
this.mindMap.render() this.mindMap.render()
}) })
this.mindMap.emit('hide_text_edit', this.textEditNode, this.renderer.activeNodeList) this.mindMap.emit('hide_text_edit', this.textEditNode, this.renderer.activeNodeList)

View File

@ -189,6 +189,8 @@ class Base {
* @Author: 王林 * @Author: 王林
* @Date: 2022-07-31 09:14:03 * @Date: 2022-07-31 09:14:03
* @Desc: 获取节点的边界值 * @Desc: 获取节点的边界值
* dir生长方向h水平v垂直
* isLeft是否向左生长
*/ */
getNodeBoundaries(node, dir, isLeft) { getNodeBoundaries(node, dir, isLeft) {
let { generalizationLineMargin, generalizationNodeMargin } = this.mindMap.themeConfig let { generalizationLineMargin, generalizationNodeMargin } = this.mindMap.themeConfig
@ -201,11 +203,11 @@ class Base {
root.children.forEach((child) => { root.children.forEach((child) => {
let {left, right, top, bottom} = walk(child) let {left, right, top, bottom} = walk(child)
// 概要内容的宽度 // 概要内容的宽度
let generalizationWidth = child.checkHasGeneralization() ? child._generalizationNodeWidth + generalizationNodeMargin : 0 let generalizationWidth = child.checkHasGeneralization() && child.nodeData.data.expand ? child._generalizationNodeWidth + generalizationNodeMargin : 0
// 概要内容的高度 // 概要内容的高度
let generalizationHeight = child.checkHasGeneralization() ? child._generalizationNodeHeight + generalizationNodeMargin : 0 let generalizationHeight = child.checkHasGeneralization() && child.nodeData.data.expand ? child._generalizationNodeHeight + generalizationNodeMargin : 0
if (left < _left) { if (left - (dir === 'h' ? generalizationWidth : 0) < _left) {
_left = left - (isLeft ? generalizationWidth : 0) _left = left - (dir === 'h' ? generalizationWidth : 0)
} }
if (right + (dir === 'h' ? generalizationWidth : 0) > _right) { if (right + (dir === 'h' ? generalizationWidth : 0) > _right) {
_right = right + (dir === 'h' ? generalizationWidth : 0) _right = right + (dir === 'h' ? generalizationWidth : 0)