diff --git a/src/components/richtext/rich-edit.vue b/src/components/richtext/rich-edit.vue index 63349e3..6c50f9e 100644 --- a/src/components/richtext/rich-edit.vue +++ b/src/components/richtext/rich-edit.vue @@ -80,7 +80,7 @@ const customPaste = (editor, event, callback) => { // 显示蒙版 loadingShow.value = true let htmlData = event.clipboardData.getData('text/html') // 获取粘贴的 html - // console.log(htmlData) + console.log(htmlData) if (htmlData == "") { htmlData = event.clipboardData.getData('text/plain') // 获取粘贴的 html // console.log(htmlData) @@ -96,10 +96,11 @@ const customPaste = (editor, event, callback) => { // 从html内容中查找粘贴内容中是否有图片元素,并返回img标签的属性src值的集合 const imgSrcs = htmlData.match(/]*src=['"]([^'"]+)[^>]*>/g); - // console.log('imgSrcs', imgSrcs) - if (rtfData !== "") { - // 处理 word 内图片 - if (imgSrcs && Array.isArray(imgSrcs) && imgSrcs.length) { + if (imgSrcs && Array.isArray(imgSrcs) && imgSrcs.length) { + //有图片,处理图片 + // console.log('imgSrcs', imgSrcs) + if (rtfData !== "") { + // 处理 word 内图片 // 从rtf内容中查找图片数据 const rtfImageData = extractImageDataFromRtf(rtfData); // 如果找到 @@ -111,9 +112,7 @@ const customPaste = (editor, event, callback) => { loadingShow.value = false callback(false) } - } - } else { - if (imgSrcs && Array.isArray(imgSrcs) && imgSrcs.length) { + } else { convertImgToBase64(imgSrcs).then(imgList => { imgList.forEach(item => { htmlData = htmlData.replace(item.src, item.tar) @@ -124,11 +123,12 @@ const customPaste = (editor, event, callback) => { loadingShow.value = false callback(false) }) - } else { - editor.dangerouslyInsertHtml(htmlData); - loadingShow.value = false - callback(false) } + } else { + //无图片,直接复制 + editor.dangerouslyInsertHtml(htmlData); + loadingShow.value = false + callback(false) } event.preventDefault() }