feat: 修复发送消息后的键盘处理

This commit is contained in:
2026-05-14 15:20:34 +08:00
parent e453a78212
commit 405be2ca99
2 changed files with 42 additions and 19 deletions

View File

@@ -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(() => {