Demo:代码优化
This commit is contained in:
parent
0cfa21d4e6
commit
1bb7e431fb
@ -287,7 +287,7 @@ onPaste(e) {
|
|||||||
if (!selection.rangeCount) return
|
if (!selection.rangeCount) return
|
||||||
selection.deleteFromDocument()// 删除当前选区,也就是如果当前用户在输入框中选择了一些文本,会被删除
|
selection.deleteFromDocument()// 删除当前选区,也就是如果当前用户在输入框中选择了一些文本,会被删除
|
||||||
// 从剪贴板里取出文本数据
|
// 从剪贴板里取出文本数据
|
||||||
let text = (e.clipboardData || window.clipboardData).getData('text')
|
let text = e.clipboardData.getData('text')
|
||||||
// 调用库提供的getTextFromHtml方法去除格式
|
// 调用库提供的getTextFromHtml方法去除格式
|
||||||
text = getTextFromHtml(text)
|
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>
|
<span class="hljs-keyword">if</span> (!selection.rangeCount) <span class="hljs-keyword">return</span>
|
||||||
selection.deleteFromDocument()<span class="hljs-comment">// 删除当前选区,也就是如果当前用户在输入框中选择了一些文本,会被删除</span>
|
selection.deleteFromDocument()<span class="hljs-comment">// 删除当前选区,也就是如果当前用户在输入框中选择了一些文本,会被删除</span>
|
||||||
<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>
|
<span class="hljs-comment">// 调用库提供的getTextFromHtml方法去除格式</span>
|
||||||
text = getTextFromHtml(text)
|
text = getTextFromHtml(text)
|
||||||
<span class="hljs-comment">// 去除换行</span>
|
<span class="hljs-comment">// 去除换行</span>
|
||||||
|
|||||||
@ -41,9 +41,9 @@ import { mapState } from 'vuex'
|
|||||||
import {
|
import {
|
||||||
nodeRichTextToTextWithWrap,
|
nodeRichTextToTextWithWrap,
|
||||||
textToNodeRichTextWithWrap,
|
textToNodeRichTextWithWrap,
|
||||||
getTextFromHtml,
|
|
||||||
createUid,
|
createUid,
|
||||||
htmlEscape
|
htmlEscape,
|
||||||
|
handleInputPasteText
|
||||||
} from 'simple-mind-map/src/utils'
|
} from 'simple-mind-map/src/utils'
|
||||||
|
|
||||||
// 大纲树
|
// 大纲树
|
||||||
@ -212,18 +212,7 @@ export default {
|
|||||||
|
|
||||||
// 拦截粘贴事件
|
// 拦截粘贴事件
|
||||||
onPaste(e) {
|
onPaste(e) {
|
||||||
e.preventDefault()
|
handleInputPasteText(e)
|
||||||
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()
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 生成唯一的key
|
// 生成唯一的key
|
||||||
|
|||||||
@ -52,10 +52,10 @@ import { mapState, mapMutations } from 'vuex'
|
|||||||
import {
|
import {
|
||||||
nodeRichTextToTextWithWrap,
|
nodeRichTextToTextWithWrap,
|
||||||
textToNodeRichTextWithWrap,
|
textToNodeRichTextWithWrap,
|
||||||
getTextFromHtml,
|
|
||||||
createUid,
|
createUid,
|
||||||
simpleDeepClone,
|
simpleDeepClone,
|
||||||
htmlEscape
|
htmlEscape,
|
||||||
|
handleInputPasteText
|
||||||
} from 'simple-mind-map/src/utils'
|
} from 'simple-mind-map/src/utils'
|
||||||
import { storeData } from '@/api'
|
import { storeData } from '@/api'
|
||||||
|
|
||||||
@ -211,18 +211,7 @@ export default {
|
|||||||
|
|
||||||
// 拦截粘贴事件
|
// 拦截粘贴事件
|
||||||
onPaste(e) {
|
onPaste(e) {
|
||||||
e.preventDefault()
|
handleInputPasteText(e)
|
||||||
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()
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 生成唯一的key
|
// 生成唯一的key
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user