From 7de94e2ea37803216e5afe9d40e7121c87a5344e Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期四, 24 四月 2025 14:21:14 +0800 Subject: [PATCH] 富文本复制粘贴图片上传至url --- src/components/Editor/index.vue | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/src/components/Editor/index.vue b/src/components/Editor/index.vue index 1bd01ed..c5e2185 100644 --- a/src/components/Editor/index.vue +++ b/src/components/Editor/index.vue @@ -27,6 +27,7 @@ </template> <script setup> +import axios from 'axios'; import { QuillEditor } from "@vueup/vue-quill"; import "@vueup/vue-quill/dist/vue-quill.snow.css"; import { getToken } from "@/utils/auth"; @@ -124,6 +125,7 @@ quill.format("image", false); } }); + quill.root.addEventListener('paste', handlePasteCapture, true); } }); @@ -168,6 +170,29 @@ function handleUploadError() { 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> <style> -- Gitblit v1.9.3