feat: 修复发送消息后的键盘处理
This commit is contained in:
@@ -284,23 +284,31 @@ onUnmounted(() => {
|
|||||||
resetUI();
|
resetUI();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const hideKeyboardAfterSend = () => {
|
||||||
|
isFocused.value = false;
|
||||||
|
|
||||||
|
const textarea = textareaRef.value;
|
||||||
|
if (textarea && typeof textarea.blur === "function") {
|
||||||
|
textarea.blur();
|
||||||
|
}
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
uni.hideKeyboard();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const sendMessage = () => {
|
const sendMessage = () => {
|
||||||
if (props.isSessionActive) {
|
if (props.isSessionActive) {
|
||||||
// 如果会话进行中,调用停止请求函数
|
// 如果会话进行中,调用停止请求函数
|
||||||
if (props.stopRequest) {
|
if (props.stopRequest) {
|
||||||
props.stopRequest();
|
props.stopRequest();
|
||||||
}
|
}
|
||||||
|
hideKeyboardAfterSend();
|
||||||
} else {
|
} else {
|
||||||
// 否则发送新消息
|
// 否则发送新消息
|
||||||
if (!inputMessage.value.trim()) return;
|
if (!inputMessage.value.trim()) return;
|
||||||
emit("send", inputMessage.value);
|
emit("send", inputMessage.value);
|
||||||
|
hideKeyboardAfterSend();
|
||||||
// 发送后保持焦点(可选)
|
|
||||||
if (props.holdKeyboard && textareaRef.value) {
|
|
||||||
nextTick(() => {
|
|
||||||
textareaRef.value.focus();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -325,8 +333,9 @@ const handleTouchEnd = () => {
|
|||||||
const focusInput = () => {
|
const focusInput = () => {
|
||||||
isFocused.value = true;
|
isFocused.value = true;
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (textareaRef.value) {
|
const textarea = textareaRef.value;
|
||||||
textareaRef.value.focus();
|
if (textarea && typeof textarea.focus === "function") {
|
||||||
|
textarea.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -334,8 +343,10 @@ const focusInput = () => {
|
|||||||
// 手动失焦输入框
|
// 手动失焦输入框
|
||||||
const blurInput = () => {
|
const blurInput = () => {
|
||||||
isFocused.value = false;
|
isFocused.value = false;
|
||||||
if (textareaRef.value) {
|
|
||||||
textareaRef.value.blur();
|
const textarea = textareaRef.value;
|
||||||
|
if (textarea && typeof textarea.blur === "function") {
|
||||||
|
textarea.blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
|
|||||||
@@ -381,7 +381,10 @@ const hideKeyboardByScroll = () => {
|
|||||||
holdKeyboardFlag.value = true;
|
holdKeyboardFlag.value = true;
|
||||||
isKeyboardShow.value = false;
|
isKeyboardShow.value = false;
|
||||||
|
|
||||||
if (inputAreaRef.value && inputAreaRef.value.blurInput) {
|
if (
|
||||||
|
inputAreaRef.value &&
|
||||||
|
typeof inputAreaRef.value.blurInput === "function"
|
||||||
|
) {
|
||||||
inputAreaRef.value.blurInput();
|
inputAreaRef.value.blurInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,6 +397,21 @@ const hideKeyboardByScroll = () => {
|
|||||||
// #endif
|
// #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 = () => {
|
const handleScrollAreaTouchStart = () => {
|
||||||
lastScrollTouchAt = Date.now();
|
lastScrollTouchAt = Date.now();
|
||||||
hideKeyboardByScroll();
|
hideKeyboardByScroll();
|
||||||
@@ -476,7 +494,6 @@ const handleReplyInstruct = async (item) => {
|
|||||||
const sendMessageAction = (inputText) => {
|
const sendMessageAction = (inputText) => {
|
||||||
console.log("输入消息:", inputText);
|
console.log("输入消息:", inputText);
|
||||||
if (!inputText.trim()) return;
|
if (!inputText.trim()) return;
|
||||||
handleNoHideKeyboard();
|
|
||||||
|
|
||||||
// 发送消息时,强制开启自动滚动
|
// 发送消息时,强制开启自动滚动
|
||||||
isAutoScroll.value = true;
|
isAutoScroll.value = true;
|
||||||
@@ -484,12 +501,7 @@ const sendMessageAction = (inputText) => {
|
|||||||
resetMessageState();
|
resetMessageState();
|
||||||
|
|
||||||
sendMessage(inputText);
|
sendMessage(inputText);
|
||||||
// 发送消息后保持键盘状态
|
hideKeyboardAfterSend();
|
||||||
if (holdKeyboard.value && inputAreaRef.value) {
|
|
||||||
setTimeout(() => {
|
|
||||||
inputAreaRef.value.focusInput();
|
|
||||||
}, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeoutScrollToBottom(true);
|
setTimeoutScrollToBottom(true);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user