changeContentValue() { this.chatText = this.$refs.imChatText.innerHTML; },
chatTextBlur() { window.scroll(0, 0); }, onNewsPaste(event) { let items = event.clipboardData && event.clipboardData.items; let file = null; let fileURL = null; let isJieTu = null; const selection = window.getSelection(); let paste = ""; if (window.clipboardData && window.clipboardData.setData) { paste = window.clipboardData.getData("text"); } else { paste = (event.originalEvent || event).clipboardData.getData("text/plain") || ""; } selection.deleteFromDocument(); if (items && items.length) { let filterItem = items; for (let i = 0; i < filterItem.length; i++) { if (filterItem[i].type.indexOf("image") !== -1) {
file = filterItem[i].getAsFile(); isJieTu = filterItem[i].webkitGetAsEntry(); if (!isJieTu) { event.preventDefault(); const reader = new FileReader(); let that = this; reader.onload = (function () { return function (e) { let fileFlag = that.blobUrlToFlieArr.some( (ele) => { return ele.name == e.target.result; } ); if (!fileFlag) { that.blobUrlToFlieArr = [ ...that.blobUrlToFlieArr, { name: e.target.result, file }, ]; } let imageDomStr = `<img data-info='diaImWeb' src=${e.target.result} class='pasteImgs' />`; let fragment = selection .getRangeAt(0) .createContextualFragment(imageDomStr); selection .getRangeAt(0) .insertNode(fragment.lastChild); }; })(); reader.readAsDataURL(file); } else {
fileURL = URL.createObjectURL(file);
this.blobUrlToFlieArr = [ ...this.blobUrlToFlieArr , { name: fileURL, file }]; let imgDomStr = `<img data-info='diaImWeb' src=${fileURL} class='pasteImgs' />` let fragment = selection.getRangeAt(0).createContextualFragment(imgDomStr); selection.getRangeAt(0).insertNode(fragment.lastChild); } } else { if (filterItem[i].type.indexOf("text/html") !== -1) {
paste = paste.replace(/</g, "<").replace(/>/g, ">"); paste = paste.replace(/\r\n/g, "<br>"); document.execCommand("insertHTML", false, paste); } else { event.preventDefault(); } } } } }
|