Demo:支持双击节点备注图标进入备注编辑

This commit is contained in:
街角小林
2024-12-06 17:43:24 +08:00
parent 88a6442539
commit c29477ed55
3 changed files with 32 additions and 21 deletions

View File

@@ -614,7 +614,8 @@ export default {
'node_attachmentClick',
'node_attachmentContextmenu',
'demonstrate_jump',
'exit_demonstrate'
'exit_demonstrate',
'node_note_dblclick'
].forEach(event => {
this.mindMap.on(event, (...args) => {
this.$bus.$emit(event, ...args)

View File

@@ -42,7 +42,8 @@ export default {
note: '',
activeNodes: [],
editor: null,
isMobile: isMobile()
isMobile: isMobile(),
appointNode: null
}
},
watch: {
@@ -63,6 +64,10 @@ export default {
methods: {
handleNodeActive(...args) {
this.activeNodes = [...args[1]]
this.updateNoteInfo()
},
updateNoteInfo() {
if (this.activeNodes.length > 0) {
let firstNode = this.activeNodes[0]
this.note = firstNode.getData('note') || ''
@@ -71,19 +76,18 @@ export default {
}
},
handleShowNodeNote() {
handleShowNodeNote(node) {
this.$bus.$emit('startTextEdit')
if (node) {
this.appointNode = node
this.note = node.getData('note') || ''
}
this.dialogVisible = true
this.$nextTick(() => {
this.initEditor()
})
},
/**
* @Author: 王林25
* @Date: 2022-05-09 11:37:05
* @Desc: 初始化编辑器
*/
initEditor() {
if (!this.editor) {
this.editor = new Editor({
@@ -96,25 +100,24 @@ export default {
this.editor.setMarkdown(this.note)
},
/**
* @Author: 王林
* @Date: 2021-06-22 22:08:11
* @Desc: 取消
*/
cancel() {
this.dialogVisible = false
if (this.appointNode) {
this.appointNode = null
this.updateNoteInfo()
}
},
/**
* @Author: 王林
* @Date: 2021-06-06 22:28:20
* @Desc: 确定
*/
confirm() {
this.note = this.editor.getMarkdown()
this.activeNodes.forEach(node => {
node.setNote(this.note)
})
if (this.appointNode) {
this.appointNode.setNote(this.note)
} else {
this.activeNodes.forEach(node => {
node.setNote(this.note)
})
}
this.cancel()
}
}

View File

@@ -234,12 +234,14 @@ export default {
window.addEventListener('resize', this.computeToolbarShowThrottle)
this.$bus.$on('lang_change', this.computeToolbarShowThrottle)
window.addEventListener('beforeunload', this.onUnload)
this.$bus.$on('node_note_dblclick', this.onNodeNoteDblclick)
},
beforeDestroy() {
this.$bus.$off('write_local_file', this.onWriteLocalFile)
window.removeEventListener('resize', this.computeToolbarShowThrottle)
this.$bus.$off('lang_change', this.computeToolbarShowThrottle)
window.removeEventListener('beforeunload', this.onUnload)
this.$bus.$off('node_note_dblclick', this.onNodeNoteDblclick)
},
methods: {
// 计算工具按钮如何显示
@@ -501,6 +503,11 @@ export default {
}
this.$message.warning(this.$t('toolbar.notSupportTip'))
}
},
onNodeNoteDblclick(node, e) {
e.stopPropagation()
this.$bus.$emit('showNodeNote', node)
}
}
}