From 90fd2deba04861e0bd265d92e91868a590be2e31 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 20 Jul 2022 14:48:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B6=88=E6=81=AF=E7=B2=98=E8=B4=B4exc?= =?UTF-8?q?el=E5=86=85=E5=AE=B9=E8=87=AA=E5=8A=A8=E8=BD=AC=E6=88=90?= =?UTF-8?q?=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/components/ChatInput/index.vue | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/resources/assets/js/pages/manage/components/ChatInput/index.vue b/resources/assets/js/pages/manage/components/ChatInput/index.vue index 670548725..8800410f6 100755 --- a/resources/assets/js/pages/manage/components/ChatInput/index.vue +++ b/resources/assets/js/pages/manage/components/ChatInput/index.vue @@ -1159,13 +1159,51 @@ export default { }, handlePaste(e) { - const {files} = e.clipboardData; - const postFiles = Array.prototype.slice.call(files).filter(file => !$A.leftExists(file.type, 'image/')); + const files = Array.prototype.slice.call(e.clipboardData.files) + const postFiles = files.filter(file => !$A.leftExists(file.type, 'image/')); if (postFiles.length > 0) { e.preventDefault() - this.$emit('on-file', postFiles) + this.$emit('on-file', files) + } else if (this.pasteRtf(e)) { + e.preventDefault() } }, + + pasteRtf(e) { + if (e && e.clipboardData && e.clipboardData.items) { + const imgHtml = (new DOMParser).parseFromString(e.clipboardData.getData("text/html") || "", "text/html").querySelector("img"); + if (!imgHtml) { + const array = []; + let image = null; + if (e.clipboardData.types && -1 != [].indexOf.call(e.clipboardData.types, "text/rtf") || e.clipboardData.getData("text/rtf")) { + image = e.clipboardData.items[0].getAsFile(); + if (image) { + array.push(image) + } + } else { + for (let s = 0; s < e.clipboardData.items.length; s++) { + image = e.clipboardData.items[s].getAsFile() + if (image) { + array.push(image) + } + } + } + if (array.length > 0) { + array.forEach(image => { + const t = new FileReader; + t.onload = ({target}) => { + const length = this.quill.getSelection(true).index; + this.quill.insertEmbed(length, "image", target.result); + this.quill.setSelection(length + 1) + }; + t.readAsDataURL(image) + }) + return true + } + } + } + return false + }, } }