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_attachmentClick',
'node_attachmentContextmenu', 'node_attachmentContextmenu',
'demonstrate_jump', 'demonstrate_jump',
'exit_demonstrate' 'exit_demonstrate',
'node_note_dblclick'
].forEach(event => { ].forEach(event => {
this.mindMap.on(event, (...args) => { this.mindMap.on(event, (...args) => {
this.$bus.$emit(event, ...args) this.$bus.$emit(event, ...args)

View File

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

View File

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