From dfc08b2ade3e4fd78da4da29d7c66320f8cf7de4 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 10 Jul 2026 11:56:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(H5):=20=E4=BF=AE=E5=A4=8D=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=E6=97=A0=E6=B3=95=E7=B2=98=E8=B4=B4?= =?UTF-8?q?=E5=9B=BE=E7=89=87/=E6=96=87=E4=BB=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 handleDocPaste 中对 target 的检查 - 添加优先使用 clipboardData.files 的逻辑 - 修复 van-field @paste 在某些 H5 环境下不触发的问题 --- frontend-h5/src/components/chat/InputBar.vue | 24 +++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/frontend-h5/src/components/chat/InputBar.vue b/frontend-h5/src/components/chat/InputBar.vue index 6a582ec..e6b1a55 100644 --- a/frontend-h5/src/components/chat/InputBar.vue +++ b/frontend-h5/src/components/chat/InputBar.vue @@ -172,12 +172,30 @@ onUnmounted(() => { /** * Document 级别粘贴处理(备用方案) * 做什么:捕获 van-field @paste 未处理的文件粘贴 + * 说明:移除 target 检查,让 handleDocPaste 作为后备方案处理所有文件粘贴 */ async function handleDocPaste(event: ClipboardEvent): Promise { - // 如果事件目标是输入框,说明 @paste 已经处理,跳过 - const target = event.target as HTMLElement - if (target.tagName === 'TEXTAREA' || target.isContentEditable) return + // 不再检查 target 是否为 textarea + // 原因:van-field 的 @paste 事件在某些 H5 环境下可能不触发 + // 此时 document 级别的监听可以作为后备方案 + // 优先使用 clipboardData.files(兼容性更好) + const files = event.clipboardData?.files + if (files && files.length > 0) { + event.preventDefault() + console.log('[InputBar] Document级别粘贴检测到文件, 数量:', files.length) + + for (const file of Array.from(files)) { + if (file.type.startsWith('image/')) { + await handleImageUpload(file) + } else { + await handleFileUpload(file) + } + } + return + } + + // 兼容 clipboardData.items const items = event.clipboardData?.items if (!items) return