Fix:修复缩放画布时图标浮层和备注浮层和节点脱离的问题
This commit is contained in:
parent
211fa183d3
commit
9a7f827301
@ -74,6 +74,7 @@ class Node {
|
|||||||
this._tagData = null
|
this._tagData = null
|
||||||
this._noteData = null
|
this._noteData = null
|
||||||
this.noteEl = null
|
this.noteEl = null
|
||||||
|
this.noteContentIsShow = false
|
||||||
this._expandBtn = null
|
this._expandBtn = null
|
||||||
this._lastExpandBtnType = null
|
this._lastExpandBtnType = null
|
||||||
this._showExpandBtn = false
|
this._showExpandBtn = false
|
||||||
@ -971,6 +972,11 @@ class Node {
|
|||||||
hasCustomStyle() {
|
hasCustomStyle() {
|
||||||
return this.style.hasCustomStyle()
|
return this.style.hasCustomStyle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取节点的尺寸和位置信息,位置信息相对于页面
|
||||||
|
getRect() {
|
||||||
|
return this.group.rbox()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Node
|
export default Node
|
||||||
|
|||||||
@ -307,16 +307,17 @@ function createNoteNode() {
|
|||||||
this.noteEl.innerText = this.getData('note')
|
this.noteEl.innerText = this.getData('note')
|
||||||
}
|
}
|
||||||
node.on('mouseover', () => {
|
node.on('mouseover', () => {
|
||||||
let { left, top } = node.node.getBoundingClientRect()
|
const { left, top } = this.getNoteContentPosition()
|
||||||
if (!this.mindMap.opt.customNoteContentShow) {
|
if (!this.mindMap.opt.customNoteContentShow) {
|
||||||
this.noteEl.style.left = left + 'px'
|
this.noteEl.style.left = left + 'px'
|
||||||
this.noteEl.style.top = top + iconSize + 'px'
|
this.noteEl.style.top = top + 'px'
|
||||||
this.noteEl.style.display = 'block'
|
this.noteEl.style.display = 'block'
|
||||||
} else {
|
} else {
|
||||||
this.mindMap.opt.customNoteContentShow.show(
|
this.mindMap.opt.customNoteContentShow.show(
|
||||||
this.getData('note'),
|
this.getData('note'),
|
||||||
left,
|
left,
|
||||||
top + iconSize
|
top,
|
||||||
|
this
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -334,6 +335,19 @@ function createNoteNode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取节点备注显示位置
|
||||||
|
function getNoteContentPosition() {
|
||||||
|
const iconSize = this.mindMap.themeConfig.iconSize
|
||||||
|
const { scaleY } = this.mindMap.view.getTransformData().transform
|
||||||
|
const iconSizeAddScale = iconSize * scaleY
|
||||||
|
let { left, top } = this._noteData.node.node.getBoundingClientRect()
|
||||||
|
top += iconSizeAddScale
|
||||||
|
return {
|
||||||
|
left,
|
||||||
|
top
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 测量自定义节点内容元素的宽高
|
// 测量自定义节点内容元素的宽高
|
||||||
function measureCustomNodeContentSize(content) {
|
function measureCustomNodeContentSize(content) {
|
||||||
if (!commonCaches.measureCustomNodeContentSizeEl) {
|
if (!commonCaches.measureCustomNodeContentSizeEl) {
|
||||||
@ -368,6 +382,7 @@ export default {
|
|||||||
createHyperlinkNode,
|
createHyperlinkNode,
|
||||||
createTagNode,
|
createTagNode,
|
||||||
createNoteNode,
|
createNoteNode,
|
||||||
|
getNoteContentPosition,
|
||||||
measureCustomNodeContentSize,
|
measureCustomNodeContentSize,
|
||||||
isUseCustomNodeContent
|
isUseCustomNodeContent
|
||||||
}
|
}
|
||||||
|
|||||||
@ -294,8 +294,8 @@ export default {
|
|||||||
nodeTextEditZIndex: 1000,
|
nodeTextEditZIndex: 1000,
|
||||||
nodeNoteTooltipZIndex: 1000,
|
nodeNoteTooltipZIndex: 1000,
|
||||||
customNoteContentShow: {
|
customNoteContentShow: {
|
||||||
show: (content, left, top) => {
|
show: (content, left, top, node) => {
|
||||||
this.$bus.$emit('showNoteContent', content, left, top)
|
this.$bus.$emit('showNoteContent', content, left, top, node)
|
||||||
},
|
},
|
||||||
hide: () => {
|
hide: () => {
|
||||||
// this.$bus.$emit('hideNoteContent')
|
// this.$bus.$emit('hideNoteContent')
|
||||||
@ -380,7 +380,8 @@ export default {
|
|||||||
'generalization_node_contextmenu',
|
'generalization_node_contextmenu',
|
||||||
'painter_start',
|
'painter_start',
|
||||||
'painter_end',
|
'painter_end',
|
||||||
'scrollbar_change'
|
'scrollbar_change',
|
||||||
|
'scale'
|
||||||
].forEach(event => {
|
].forEach(event => {
|
||||||
this.mindMap.on(event, (...args) => {
|
this.mindMap.on(event, (...args) => {
|
||||||
this.$bus.$emit(event, ...args)
|
this.$bus.$emit(event, ...args)
|
||||||
|
|||||||
@ -51,6 +51,7 @@ export default {
|
|||||||
this.mindMap.on('svg_mousedown', this.close)
|
this.mindMap.on('svg_mousedown', this.close)
|
||||||
this.mindMap.on('node_dblclick', this.close)
|
this.mindMap.on('node_dblclick', this.close)
|
||||||
this.mindMap.on('node_active', this.onNodeActive)
|
this.mindMap.on('node_active', this.onNodeActive)
|
||||||
|
this.mindMap.on('scale', this.onScale)
|
||||||
this.$bus.$on('close_node_icon_toolbar', this.close)
|
this.$bus.$on('close_node_icon_toolbar', this.close)
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -62,6 +63,7 @@ export default {
|
|||||||
this.mindMap.off('svg_mousedown', this.close)
|
this.mindMap.off('svg_mousedown', this.close)
|
||||||
this.mindMap.off('node_dblclick', this.close)
|
this.mindMap.off('node_dblclick', this.close)
|
||||||
this.mindMap.off('node_active', this.onNodeActive)
|
this.mindMap.off('node_active', this.onNodeActive)
|
||||||
|
this.mindMap.off('scale', this.onScale)
|
||||||
this.$bus.$off('close_node_icon_toolbar', this.close)
|
this.$bus.$off('close_node_icon_toolbar', this.close)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -75,9 +77,7 @@ export default {
|
|||||||
this.iconList = [...allIconList.find((item) => {
|
this.iconList = [...allIconList.find((item) => {
|
||||||
return item.type === this.iconType
|
return item.type === this.iconType
|
||||||
}).list]
|
}).list]
|
||||||
let rect = node.group.rbox()
|
this.updatePos()
|
||||||
this.style.left = rect.x + 'px'
|
|
||||||
this.style.top = rect.y + rect.height + 'px'
|
|
||||||
this.showNodeIconToolbar = true
|
this.showNodeIconToolbar = true
|
||||||
if (this.activeSidebar === 'nodeIconSidebar') {
|
if (this.activeSidebar === 'nodeIconSidebar') {
|
||||||
this.setActiveSidebar('')
|
this.setActiveSidebar('')
|
||||||
@ -95,6 +95,17 @@ export default {
|
|||||||
this.style.top = 0
|
this.style.top = 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updatePos() {
|
||||||
|
if (!this.node) return
|
||||||
|
const rect = this.node.getRect()
|
||||||
|
this.style.left = rect.x + 'px'
|
||||||
|
this.style.top = rect.y + rect.height + 'px'
|
||||||
|
},
|
||||||
|
|
||||||
|
onScale() {
|
||||||
|
this.updatePos()
|
||||||
|
},
|
||||||
|
|
||||||
onNodeActive(node) {
|
onNodeActive(node) {
|
||||||
if (node === this.node) {
|
if (node === this.node) {
|
||||||
return
|
return
|
||||||
|
|||||||
@ -27,7 +27,8 @@ export default {
|
|||||||
editor: null,
|
editor: null,
|
||||||
show: false,
|
show: false,
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0
|
top: 0,
|
||||||
|
node: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@ -35,6 +36,8 @@ export default {
|
|||||||
this.$bus.$on('hideNoteContent', this.hideNoteContent)
|
this.$bus.$on('hideNoteContent', this.hideNoteContent)
|
||||||
document.body.addEventListener('click', this.hideNoteContent)
|
document.body.addEventListener('click', this.hideNoteContent)
|
||||||
this.$bus.$on('node_active', this.hideNoteContent)
|
this.$bus.$on('node_active', this.hideNoteContent)
|
||||||
|
this.$bus.$on('scale', this.onScale)
|
||||||
|
this.$bus.$on('svg_mousedown', this.hideNoteContent)
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initEditor()
|
this.initEditor()
|
||||||
@ -44,34 +47,37 @@ export default {
|
|||||||
this.$bus.$off('hideNoteContent', this.hideNoteContent)
|
this.$bus.$off('hideNoteContent', this.hideNoteContent)
|
||||||
document.body.removeEventListener('click', this.hideNoteContent)
|
document.body.removeEventListener('click', this.hideNoteContent)
|
||||||
this.$bus.$off('node_active', this.hideNoteContent)
|
this.$bus.$off('node_active', this.hideNoteContent)
|
||||||
|
this.$bus.$off('scale', this.onScale)
|
||||||
|
this.$bus.$off('svg_mousedown', this.hideNoteContent)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
// 显示备注浮层
|
||||||
* @Author: 王林25
|
onShowNoteContent(content, left, top, node) {
|
||||||
* @Date: 2022-11-14 19:56:08
|
this.node = node
|
||||||
* @Desc: 显示备注浮层
|
|
||||||
*/
|
|
||||||
onShowNoteContent(content, left, top) {
|
|
||||||
this.editor.setMarkdown(content)
|
this.editor.setMarkdown(content)
|
||||||
this.left = left
|
this.updateNoteContentPosition(left, top)
|
||||||
this.top = top
|
|
||||||
this.show = true
|
this.show = true
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// 更新位置
|
||||||
* @Author: 王林25
|
updateNoteContentPosition(left, top) {
|
||||||
* @Date: 2022-11-14 19:56:20
|
this.left = left
|
||||||
* @Desc: 隐藏备注浮层
|
this.top = top
|
||||||
*/
|
},
|
||||||
|
|
||||||
|
// 画布缩放事件
|
||||||
|
onScale() {
|
||||||
|
if (!this.node || !this.show) return
|
||||||
|
const { left, top } = this.node.getNoteContentPosition()
|
||||||
|
this.updateNoteContentPosition(left, top)
|
||||||
|
},
|
||||||
|
|
||||||
|
// 隐藏备注浮层
|
||||||
hideNoteContent() {
|
hideNoteContent() {
|
||||||
this.show = false
|
this.show = false
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
// 初始化编辑器
|
||||||
* @Author: 王林25
|
|
||||||
* @Date: 2022-05-09 11:37:05
|
|
||||||
* @Desc: 初始化编辑器
|
|
||||||
*/
|
|
||||||
initEditor() {
|
initEditor() {
|
||||||
if (!this.editor) {
|
if (!this.editor) {
|
||||||
this.editor = new Viewer({
|
this.editor = new Viewer({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user