diff --git a/web/src/api/fileUploadAndDownload.js b/web/src/api/fileUploadAndDownload.js index 0f260b639..a749b4c97 100644 --- a/web/src/api/fileUploadAndDownload.js +++ b/web/src/api/fileUploadAndDownload.js @@ -64,4 +64,20 @@ export const uploadFile = (data) => { method: "post", data, }); -}; \ No newline at end of file +}; + +/** + * 上传文件(FormData):粘贴图片等场景使用,noSave=1 不保存进媒体库 + * @param data FormData + * @returns {*} + */ +export const uploadAttachment = (data) => { + return service({ + url: '/fileUploadAndDownload/upload?noSave=1', + method: 'post', + data, + headers: { + 'Content-Type': 'multipart/form-data' + } + }) +} \ No newline at end of file diff --git a/web/src/components/selectImage/selectComponent.vue b/web/src/components/selectImage/selectComponent.vue index 18cc64ab5..7cafaa16a 100644 --- a/web/src/components/selectImage/selectComponent.vue +++ b/web/src/components/selectImage/selectComponent.vue @@ -27,16 +27,23 @@ :preview-src-list="srcList" fit="cover" /> +
{ emits('chooseItem') @@ -83,4 +90,28 @@ const srcList = computed(() => { return imgUrl.value ? [imgUrl.value] : [] }) + + // 粘贴图片:必须在事件回调内同步提取文件,异步后 clipboardData 会失效 + const onPaste = (e) => { + const clipboardData = e.clipboardData + const files = [] + if (clipboardData?.items) { + for (let i = 0; i < clipboardData.items.length; i++) { + const item = clipboardData.items[i] + if (item.kind === 'file' && item.type.startsWith('image/')) { + const file = item.getAsFile() + if (file) files.push(file) + } + } + } + // items 为空时兜底(部分场景只有 files) + if (!files.length && clipboardData?.files) { + for (const file of clipboardData.files) { + if (file.type.startsWith('image/')) files.push(file) + } + } + if (!files.length) return // 非图片内容交给浏览器默认行为 + e.preventDefault() + files.forEach((file) => emits('pasteFile', file)) + } diff --git a/web/src/components/selectImage/selectImage.vue b/web/src/components/selectImage/selectImage.vue index 012878da2..650f8d420 100644 --- a/web/src/components/selectImage/selectImage.vue +++ b/web/src/components/selectImage/selectImage.vue @@ -1,6 +1,6 @@