feat: 消息粘贴excel内容自动转成图片

This commit is contained in:
kuaifan 2022-07-20 14:48:20 +08:00
parent 6b00aad904
commit 90fd2deba0

View File

@ -1159,13 +1159,51 @@ export default {
}, },
handlePaste(e) { handlePaste(e) {
const {files} = e.clipboardData; const files = Array.prototype.slice.call(e.clipboardData.files)
const postFiles = Array.prototype.slice.call(files).filter(file => !$A.leftExists(file.type, 'image/')); const postFiles = files.filter(file => !$A.leftExists(file.type, 'image/'));
if (postFiles.length > 0) { if (postFiles.length > 0) {
e.preventDefault() 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
},
} }
} }
</script> </script>