优化代码
This commit is contained in:
parent
c36338a794
commit
5d49d985c0
@ -132,11 +132,6 @@ class Render {
|
||||
}
|
||||
}
|
||||
|
||||
// 解绑事件
|
||||
unBindEvent() {
|
||||
window.removeEventListener('paste', this.handlePaste)
|
||||
}
|
||||
|
||||
// 绑定事件
|
||||
bindEvent() {
|
||||
// 画布点击事件清除当前激活节点列表
|
||||
@ -172,7 +167,7 @@ class Render {
|
||||
this.handlePaste = this.handlePaste.bind(this)
|
||||
window.addEventListener('paste', this.handlePaste)
|
||||
this.mindMap.on('beforeDestroy', () => {
|
||||
this.unBindEvent()
|
||||
window.removeEventListener('paste', this.handlePaste)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -419,7 +414,7 @@ class Render {
|
||||
this.mindMap.keyCommand.addShortcut('Control+Down', () => {
|
||||
this.mindMap.execCommand('DOWN_NODE')
|
||||
})
|
||||
// 复制节点、
|
||||
// 复制节点
|
||||
this.mindMap.keyCommand.addShortcut('Control+c', () => {
|
||||
this.copy()
|
||||
})
|
||||
@ -1134,22 +1129,23 @@ class Render {
|
||||
|
||||
// 非https下复制黏贴,获取内容方法
|
||||
handlePaste(event) {
|
||||
const clipboardData = event.clipboardData || event.originalEvent.clipboardData || window.clipboardData
|
||||
const { disabledClipboard } = this.mindMap.opt
|
||||
if (disabledClipboard) return
|
||||
const clipboardData =
|
||||
event.clipboardData || event.originalEvent.clipboardData
|
||||
const items = clipboardData.items
|
||||
const clipboardType = items && items.length ? items[0].type : ''
|
||||
const isImg = clipboardType.indexOf('image') > -1
|
||||
const isText = clipboardType.indexOf('text') > -1
|
||||
this.pasteData = { img: null, text: null}
|
||||
|
||||
// 复制的图片处理逻辑
|
||||
if (isImg) {
|
||||
for (let index in items) {
|
||||
const item = items[index]
|
||||
if (item.kind === 'file') this.pasteData.img = item.getAsFile()
|
||||
let img = null
|
||||
let text = ''
|
||||
Array.from(items).forEach(item => {
|
||||
if (item.type.indexOf('image') > -1) {
|
||||
img = item.getAsFile()
|
||||
}
|
||||
if (item.type.indexOf('text') > -1) {
|
||||
text = clipboardData.getData('text')
|
||||
}
|
||||
// 复制的文本处理逻辑
|
||||
if (isText) this.pasteData.text = clipboardData.getData('text')
|
||||
})
|
||||
this.pasteData.img = img
|
||||
this.pasteData.text = text
|
||||
this.paste()
|
||||
}
|
||||
|
||||
@ -1166,7 +1162,9 @@ class Render {
|
||||
let img = null
|
||||
if (!disabledClipboard) {
|
||||
try {
|
||||
const res = navigator.clipboard ? await getDataFromClipboard() : this.pasteData
|
||||
const res = navigator.clipboard
|
||||
? await getDataFromClipboard()
|
||||
: this.pasteData
|
||||
text = res.text || ''
|
||||
img = res.img || null
|
||||
} catch (error) {
|
||||
@ -1600,7 +1598,7 @@ class Render {
|
||||
this.setNodeDataRender(node, data)
|
||||
// 更新了连线的样式
|
||||
if (lineStyleProps.includes(prop)) {
|
||||
(node.parent || node).renderLine(true)
|
||||
;(node.parent || node).renderLine(true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1621,7 +1619,7 @@ class Render {
|
||||
}
|
||||
})
|
||||
if (hasLineStyleProps) {
|
||||
(node.parent || node).renderLine(true)
|
||||
;(node.parent || node).renderLine(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user