From 405be2ca99fb31556c09b7e6c90cd3c36d317522 Mon Sep 17 00:00:00 2001 From: zoujing Date: Thu, 14 May 2026 15:20:34 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=20=E4=BF=AE=E5=A4=8D=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=B6=88=E6=81=AF=E5=90=8E=E7=9A=84=E9=94=AE=E7=9B=98?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/ChatMain/ChatInputArea/index.vue | 33 ++++++++++++++-------- src/pages/ChatMain/ChatMainList/index.vue | 28 ++++++++++++------ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/pages/ChatMain/ChatInputArea/index.vue b/src/pages/ChatMain/ChatInputArea/index.vue index a1434b0..10afa9b 100644 --- a/src/pages/ChatMain/ChatInputArea/index.vue +++ b/src/pages/ChatMain/ChatInputArea/index.vue @@ -284,23 +284,31 @@ onUnmounted(() => { resetUI(); }); +const hideKeyboardAfterSend = () => { + isFocused.value = false; + + const textarea = textareaRef.value; + if (textarea && typeof textarea.blur === "function") { + textarea.blur(); + } + + nextTick(() => { + uni.hideKeyboard(); + }); +}; + const sendMessage = () => { if (props.isSessionActive) { // 如果会话进行中,调用停止请求函数 if (props.stopRequest) { props.stopRequest(); } + hideKeyboardAfterSend(); } else { // 否则发送新消息 if (!inputMessage.value.trim()) return; emit("send", inputMessage.value); - - // 发送后保持焦点(可选) - if (props.holdKeyboard && textareaRef.value) { - nextTick(() => { - textareaRef.value.focus(); - }); - } + hideKeyboardAfterSend(); } }; @@ -325,8 +333,9 @@ const handleTouchEnd = () => { const focusInput = () => { isFocused.value = true; nextTick(() => { - if (textareaRef.value) { - textareaRef.value.focus(); + const textarea = textareaRef.value; + if (textarea && typeof textarea.focus === "function") { + textarea.focus(); } }); }; @@ -334,8 +343,10 @@ const focusInput = () => { // 手动失焦输入框 const blurInput = () => { isFocused.value = false; - if (textareaRef.value) { - textareaRef.value.blur(); + + const textarea = textareaRef.value; + if (textarea && typeof textarea.blur === "function") { + textarea.blur(); } nextTick(() => { diff --git a/src/pages/ChatMain/ChatMainList/index.vue b/src/pages/ChatMain/ChatMainList/index.vue index eab5c92..d7e89d7 100644 --- a/src/pages/ChatMain/ChatMainList/index.vue +++ b/src/pages/ChatMain/ChatMainList/index.vue @@ -381,7 +381,10 @@ const hideKeyboardByScroll = () => { holdKeyboardFlag.value = true; isKeyboardShow.value = false; - if (inputAreaRef.value && inputAreaRef.value.blurInput) { + if ( + inputAreaRef.value && + typeof inputAreaRef.value.blurInput === "function" + ) { inputAreaRef.value.blurInput(); } @@ -394,6 +397,21 @@ const hideKeyboardByScroll = () => { // #endif }; +const hideKeyboardAfterSend = () => { + holdKeyboard.value = false; + holdKeyboardFlag.value = true; + isKeyboardShow.value = false; + + if ( + inputAreaRef.value && + typeof inputAreaRef.value.blurInput === "function" + ) { + inputAreaRef.value.blurInput(); + } else { + uni.hideKeyboard(); + } +}; + const handleScrollAreaTouchStart = () => { lastScrollTouchAt = Date.now(); hideKeyboardByScroll(); @@ -476,7 +494,6 @@ const handleReplyInstruct = async (item) => { const sendMessageAction = (inputText) => { console.log("输入消息:", inputText); if (!inputText.trim()) return; - handleNoHideKeyboard(); // 发送消息时,强制开启自动滚动 isAutoScroll.value = true; @@ -484,12 +501,7 @@ const sendMessageAction = (inputText) => { resetMessageState(); sendMessage(inputText); - // 发送消息后保持键盘状态 - if (holdKeyboard.value && inputAreaRef.value) { - setTimeout(() => { - inputAreaRef.value.focusInput(); - }, 100); - } + hideKeyboardAfterSend(); setTimeoutScrollToBottom(true); };