mirror of
https://github.com/yangzongzhuan/RuoYi-Vue3.git
synced 2025-09-27 14:52:40 +00:00
富文本复制粘贴图片上传至url
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import axios from 'axios';
|
||||||
import { QuillEditor } from "@vueup/vue-quill";
|
import { QuillEditor } from "@vueup/vue-quill";
|
||||||
import "@vueup/vue-quill/dist/vue-quill.snow.css";
|
import "@vueup/vue-quill/dist/vue-quill.snow.css";
|
||||||
import { getToken } from "@/utils/auth";
|
import { getToken } from "@/utils/auth";
|
||||||
@@ -124,6 +125,7 @@ onMounted(() => {
|
|||||||
quill.format("image", false);
|
quill.format("image", false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
quill.root.addEventListener('paste', handlePasteCapture, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -168,6 +170,29 @@ function handleUploadSuccess(res, file) {
|
|||||||
function handleUploadError() {
|
function handleUploadError() {
|
||||||
proxy.$modal.msgError("图片插入失败");
|
proxy.$modal.msgError("图片插入失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 复制粘贴图片处理
|
||||||
|
function handlePasteCapture(e) {
|
||||||
|
const clipboard = e.clipboardData || window.clipboardData;
|
||||||
|
if (clipboard && clipboard.items) {
|
||||||
|
for (let i = 0; i < clipboard.items.length; i++) {
|
||||||
|
const item = clipboard.items[i];
|
||||||
|
if (item.type.indexOf('image') !== -1) {
|
||||||
|
e.preventDefault();
|
||||||
|
const file = item.getAsFile();
|
||||||
|
insertImage(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertImage(file) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("file", file);
|
||||||
|
axios.post(uploadUrl.value, formData, { headers: { "Content-Type": "multipart/form-data", Authorization: headers.value.Authorization } }).then(res => {
|
||||||
|
handleUploadSuccess(res.data);
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
Reference in New Issue
Block a user