mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 10:27:44 +08:00
Demo:代码优化
This commit is contained in:
parent
0cfa21d4e6
commit
1bb7e431fb
@ -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)
|
||||
// 去除换行
|
||||
|
||||
@ -237,7 +237,7 @@ mindMap.execCommand(<span class="hljs-string">'INSERT_CHILD_NODE'</spa
|
||||
<span class="hljs-keyword">if</span> (!selection.rangeCount) <span class="hljs-keyword">return</span>
|
||||
selection.deleteFromDocument()<span class="hljs-comment">// 删除当前选区,也就是如果当前用户在输入框中选择了一些文本,会被删除</span>
|
||||
<span class="hljs-comment">// 从剪贴板里取出文本数据</span>
|
||||
<span class="hljs-keyword">let</span> text = (e.clipboardData || <span class="hljs-built_in">window</span>.clipboardData).getData(<span class="hljs-string">'text'</span>)
|
||||
<span class="hljs-keyword">let</span> text = e.clipboardData.getData(<span class="hljs-string">'text'</span>)
|
||||
<span class="hljs-comment">// 调用库提供的getTextFromHtml方法去除格式</span>
|
||||
text = getTextFromHtml(text)
|
||||
<span class="hljs-comment">// 去除换行</span>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user