【增加】增加输入法输入、普通输入监听 避免回车误触发送

This commit is contained in:
cherishsince 2024-05-14 17:17:26 +08:00
parent cea5b8b138
commit 8d907a76bf

View File

@ -156,6 +156,9 @@
<el-footer class="footer-container"> <el-footer class="footer-container">
<form @submit.prevent="onSend" class="prompt-from"> <form @submit.prevent="onSend" class="prompt-from">
<textarea class="prompt-input" v-model="prompt" @keyup.enter="onSend" <textarea class="prompt-input" v-model="prompt" @keyup.enter="onSend"
@input="onPromptInput"
@compositionstart="onCompositionstart"
@compositionend="onCompositionend"
placeholder="问我任何问题...Shift+Enter 换行,按下 Enter 发送)"></textarea> placeholder="问我任何问题...Shift+Enter 换行,按下 Enter 发送)"></textarea>
<div class="prompt-btns"> <div class="prompt-btns">
<el-switch/> <el-switch/>
@ -217,6 +220,7 @@ const conversationList = [
const {copy} = useClipboard(); const {copy} = useClipboard();
const searchName = ref('') // const searchName = ref('') //
const inputTimeout = ref<any>() //
const conversationId = ref('1781604279872581648') // id const conversationId = ref('1781604279872581648') // id
const conversationInProgress = ref<Boolean>() // const conversationInProgress = ref<Boolean>() //
conversationInProgress.value = false conversationInProgress.value = false
@ -227,6 +231,7 @@ const prompt = ref<string>() // prompt
// () // ()
const messageContainer: any = ref(null); const messageContainer: any = ref(null);
const isScrolling = ref(false)// const isScrolling = ref(false)//
const isComposing = ref(false) //
/** chat message 列表 */ /** chat message 列表 */
// defineOptions({ name: 'chatMessageList' }) // defineOptions({ name: 'chatMessageList' })
@ -257,11 +262,22 @@ const searchConversation = () => {
/** send */ /** send */
const onSend = async () => { const onSend = async () => {
//
if (isComposing.value) {
return
}
// //
if (conversationInProgress.value) { if (conversationInProgress.value) {
return return
} }
const content = prompt.value; const content = prompt.value?.trim();
if (content?.length < 2) {
ElMessage({
message: '请输入内容!',
type: 'error',
})
return
}
// //
prompt.value = '' prompt.value = ''
const requestParams = { const requestParams = {
@ -427,6 +443,55 @@ const getModalList = async () => {
} }
} }
//
const onCompositionstart = () => {
console.log('onCompositionstart。。。.')
isComposing.value= true
}
const onCompositionend = () => {
// console.log('...')
setTimeout(() => {
console.log('输入结束...')
isComposing.value = false
}, 200)
}
const onPromptInput = (event) => {
// true
if (!isComposing.value) {
// event data null
if (event.data == null) {
return
}
console.log('setTimeout 输入开始...')
isComposing.value = true
}
//
if (inputTimeout.value) {
clearTimeout(inputTimeout.value)
}
//
inputTimeout.value = setTimeout(() => {
console.log('setTimeout 输入结束...')
isComposing.value = false
}, 400)
// isComposing.value= false
// setTimeout(() => {
// console.log('...')
// isComposing.value = false
// }, 200)
// isComposing.value = event.data && event.data === event.target.value.slice(-1);
//
// if (isComposing.value) {
// console.log('使');
// } else {
// console.log('');
// }
}
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
// //
@ -448,6 +513,7 @@ onMounted(async () => {
}) })
} }
}) })
}) })