From 3d9d172fa0af44f4f3068ce24ba353c92c0dcb67 Mon Sep 17 00:00:00 2001 From: panda <710280076@qq.com> Date: Mon, 16 Sep 2024 21:32:52 +0800 Subject: [PATCH] =?UTF-8?q?'=E5=A4=84=E7=90=86=E9=9D=9Ehttps=E4=B8=8Bnavig?= =?UTF-8?q?ator.clipboard=E6=96=B9=E6=B3=95=E6=97=A0=E6=B3=95=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E9=BB=8F=E8=B4=B4=E5=A4=96=E9=83=A8=E6=96=87=E6=9C=AC?= =?UTF-8?q?'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/Render.js | 45 +++++++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index dd9dbf9a..ad5f7bb4 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -97,6 +97,7 @@ class Render { this.beingPasteText = '' this.beingPasteImgSize = 0 this.currentBeingPasteType = '' + this.pasteData = { text: null, img: null} // 节点高亮框 this.highlightBoxNode = null this.highlightBoxNodeStyle = null @@ -131,8 +132,14 @@ class Render { } } + // 解绑事件 + unBindEvent() { + window.removeEventListener('paste', this.handlePaste) + } + // 绑定事件 bindEvent() { + console.log('------------------------') // 画布点击事件清除当前激活节点列表 this.mindMap.on('draw_click', e => { this.clearActiveNodeListOnDrawClick(e, 'click') @@ -161,6 +168,14 @@ class Render { }) }) } + // 处理非https下的复制黏贴问题 + if(!navigator.clipboard) { + this.handlePaste = this.handlePaste.bind(this) + window.addEventListener('paste', this.handlePaste) + this.mindMap.on('beforeDestroy', () => { + this.unBindEvent() + }) + } } // 性能模式,懒加载节点 @@ -415,7 +430,7 @@ class Render { }) // 粘贴节点 this.mindMap.keyCommand.addShortcut('Control+v', () => { - this.paste() + if(navigator.clipboard) this.paste() }) // 根节点居中显示 this.mindMap.keyCommand.addShortcut('Control+Enter', () => { @@ -1118,6 +1133,28 @@ class Render { }) } + // 非https下复制黏贴,获取内容方法 + handlePaste(event){ + const clipboardData = event.clipboardData || event.originalEvent.clipboardData || window.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() + } + } + // 复制的文本处理逻辑 + if (isText) this.pasteData.text = clipboardData.getData('text') + console.log(this.pasteData.text,'===-=-=-dasd') + this.paste() + } + // 粘贴 async paste() { const { @@ -1131,7 +1168,7 @@ class Render { let img = null if (!disabledClipboard) { try { - const res = await getDataFromClipboard() + const res = navigator.clipboard ? await getDataFromClipboard() : this.pasteData text = res.text || '' img = res.img || null } catch (error) { @@ -1565,7 +1602,7 @@ class Render { this.setNodeDataRender(node, data) // 更新了连线的样式 if (lineStyleProps.includes(prop)) { - ;(node.parent || node).renderLine(true) + (node.parent || node).renderLine(true) } } @@ -1586,7 +1623,7 @@ class Render { } }) if (hasLineStyleProps) { - ;(node.parent || node).renderLine(true) + (node.parent || node).renderLine(true) } }