From 094181b826763245daef5ad280819a32de5ec3cc Mon Sep 17 00:00:00 2001 From: lkddi Date: Fri, 27 Feb 2026 14:53:45 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E9=98=B2=E6=AD=A2Enter=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=8F=91=E9=80=81=EF=BC=88IME=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=B3=95=E9=98=B2=E7=A9=BF=E9=80=8F+=5FisSending=E9=98=B2?= =?UTF-8?q?=E9=87=8D=E5=85=A5=E9=94=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/chat/partials/scripts.blade.php | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index 8f730ed..f1b7342 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -687,19 +687,39 @@ } }); - // ── 发送消息(Enter 发送) ─────────────────────── - document.getElementById('content').addEventListener('keydown', function(e) { + // ── 发送消息(Enter 发送,防 IME 输入法重复触发)──────── + // 用 isComposing 标记中文输入法的组词状态,组词期间过滤掉 Enter + let _imeComposing = false; + const _contentInput = document.getElementById('content'); + + // 中文/日文等 IME 组词开始 + _contentInput.addEventListener('compositionstart', () => { + _imeComposing = true; + }); + // 组词结束(确认候选词完成),给 10ms 缓冲让 keydown 先被过滤掉 + _contentInput.addEventListener('compositionend', () => { + setTimeout(() => { + _imeComposing = false; + }, 10); + }); + + _contentInput.addEventListener('keydown', function(e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); + // IME 正在组词时(如选候选汉字),不触发发送 + if (_imeComposing) return; sendMessage(e); } }); /** - * 发送聊天消息 + * 发送聊天消息(内带防重入锁,避免快速连按 Enter 重复提交) */ + let _isSending = false; // 发送中防重入标记 async function sendMessage(e) { if (e) e.preventDefault(); + if (_isSending) return; // 上一次还没结束,忽略 + _isSending = true; // 前端禁言检查 if (isMutedUntil > Date.now()) { @@ -763,6 +783,7 @@ console.error(error); } finally { submitBtn.disabled = false; + _isSending = false; // 释放发送锁,允许下次发送 } }