修改编辑器复制错误

This commit is contained in:
jacky 2024-05-23 12:01:24 +08:00
parent cc61263c97
commit 2406ad3b16
1 changed files with 12 additions and 12 deletions

View File

@ -80,7 +80,7 @@ const customPaste = (editor, event, callback) => {
// //
loadingShow.value = true loadingShow.value = true
let htmlData = event.clipboardData.getData('text/html') // html let htmlData = event.clipboardData.getData('text/html') // html
// console.log(htmlData) console.log(htmlData)
if (htmlData == "") { if (htmlData == "") {
htmlData = event.clipboardData.getData('text/plain') // html htmlData = event.clipboardData.getData('text/plain') // html
// console.log(htmlData) // console.log(htmlData)
@ -96,10 +96,11 @@ const customPaste = (editor, event, callback) => {
// htmlimgsrc // htmlimgsrc
const imgSrcs = htmlData.match(/<img [^>]*src=['"]([^'"]+)[^>]*>/g); const imgSrcs = htmlData.match(/<img [^>]*src=['"]([^'"]+)[^>]*>/g);
if (imgSrcs && Array.isArray(imgSrcs) && imgSrcs.length) {
//
// console.log('imgSrcs', imgSrcs) // console.log('imgSrcs', imgSrcs)
if (rtfData !== "") { if (rtfData !== "") {
// word // word
if (imgSrcs && Array.isArray(imgSrcs) && imgSrcs.length) {
// rtf // rtf
const rtfImageData = extractImageDataFromRtf(rtfData); const rtfImageData = extractImageDataFromRtf(rtfData);
// //
@ -111,9 +112,7 @@ const customPaste = (editor, event, callback) => {
loadingShow.value = false loadingShow.value = false
callback(false) callback(false)
} }
}
} else { } else {
if (imgSrcs && Array.isArray(imgSrcs) && imgSrcs.length) {
convertImgToBase64(imgSrcs).then(imgList => { convertImgToBase64(imgSrcs).then(imgList => {
imgList.forEach(item => { imgList.forEach(item => {
htmlData = htmlData.replace(item.src, item.tar) htmlData = htmlData.replace(item.src, item.tar)
@ -124,12 +123,13 @@ const customPaste = (editor, event, callback) => {
loadingShow.value = false loadingShow.value = false
callback(false) callback(false)
}) })
}
} else { } else {
//
editor.dangerouslyInsertHtml(htmlData); editor.dangerouslyInsertHtml(htmlData);
loadingShow.value = false loadingShow.value = false
callback(false) callback(false)
} }
}
event.preventDefault() event.preventDefault()
} }