From 1bb7e431fb7030de79b373ca54bb702c6885c4d9 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Fri, 29 Dec 2023 22:04:56 +0800 Subject: [PATCH] =?UTF-8?q?Demo:=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Doc/zh/course12/index.md | 2 +- web/src/pages/Doc/zh/course12/index.vue | 2 +- web/src/pages/Edit/components/Outline.vue | 17 +++-------------- web/src/pages/Edit/components/OutlineEdit.vue | 17 +++-------------- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/web/src/pages/Doc/zh/course12/index.md b/web/src/pages/Doc/zh/course12/index.md index 97a72afd..3842b7d5 100644 --- a/web/src/pages/Doc/zh/course12/index.md +++ b/web/src/pages/Doc/zh/course12/index.md @@ -287,7 +287,7 @@ onPaste(e) { if (!selection.rangeCount) return selection.deleteFromDocument()// 删除当前选区,也就是如果当前用户在输入框中选择了一些文本,会被删除 // 从剪贴板里取出文本数据 - let text = (e.clipboardData || window.clipboardData).getData('text') + let text = e.clipboardData.getData('text') // 调用库提供的getTextFromHtml方法去除格式 text = getTextFromHtml(text) // 去除换行 diff --git a/web/src/pages/Doc/zh/course12/index.vue b/web/src/pages/Doc/zh/course12/index.vue index e8b68667..8ccdbd71 100644 --- a/web/src/pages/Doc/zh/course12/index.vue +++ b/web/src/pages/Doc/zh/course12/index.vue @@ -237,7 +237,7 @@ mindMap.execCommand('INSERT_CHILD_NODE'if (!selection.rangeCount) return selection.deleteFromDocument()// 删除当前选区,也就是如果当前用户在输入框中选择了一些文本,会被删除 // 从剪贴板里取出文本数据 - let text = (e.clipboardData || window.clipboardData).getData('text') + let text = e.clipboardData.getData('text') // 调用库提供的getTextFromHtml方法去除格式 text = getTextFromHtml(text) // 去除换行 diff --git a/web/src/pages/Edit/components/Outline.vue b/web/src/pages/Edit/components/Outline.vue index c6ba3b30..0e7d663e 100644 --- a/web/src/pages/Edit/components/Outline.vue +++ b/web/src/pages/Edit/components/Outline.vue @@ -41,9 +41,9 @@ import { mapState } from 'vuex' import { nodeRichTextToTextWithWrap, textToNodeRichTextWithWrap, - getTextFromHtml, createUid, - htmlEscape + htmlEscape, + handleInputPasteText } from 'simple-mind-map/src/utils' // 大纲树 @@ -212,18 +212,7 @@ export default { // 拦截粘贴事件 onPaste(e) { - e.preventDefault() - const selection = window.getSelection() - if (!selection.rangeCount) return - selection.deleteFromDocument() - let text = (e.clipboardData || window.clipboardData).getData('text') - // 去除格式 - text = getTextFromHtml(text) - // 去除换行 - text = text.replaceAll(/\n/g, '') - const node = document.createTextNode(text) - selection.getRangeAt(0).insertNode(node) - selection.collapseToEnd() + handleInputPasteText(e) }, // 生成唯一的key diff --git a/web/src/pages/Edit/components/OutlineEdit.vue b/web/src/pages/Edit/components/OutlineEdit.vue index aea3eea2..1ab514fd 100644 --- a/web/src/pages/Edit/components/OutlineEdit.vue +++ b/web/src/pages/Edit/components/OutlineEdit.vue @@ -52,10 +52,10 @@ import { mapState, mapMutations } from 'vuex' import { nodeRichTextToTextWithWrap, textToNodeRichTextWithWrap, - getTextFromHtml, createUid, simpleDeepClone, - htmlEscape + htmlEscape, + handleInputPasteText } from 'simple-mind-map/src/utils' import { storeData } from '@/api' @@ -211,18 +211,7 @@ export default { // 拦截粘贴事件 onPaste(e) { - e.preventDefault() - const selection = window.getSelection() - if (!selection.rangeCount) return - selection.deleteFromDocument() - let text = (e.clipboardData || window.clipboardData).getData('text') - // 去除格式 - text = getTextFromHtml(text) - // 去除换行 - text = text.replaceAll(/\n/g, '') - const node = document.createTextNode(text) - selection.getRangeAt(0).insertNode(node) - selection.collapseToEnd() + handleInputPasteText(e) }, // 生成唯一的key