From 8d907a76bf28e23f0ba5f62efdae240a293cf442 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Tue, 14 May 2024 17:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=BE=93=E5=85=A5=E6=B3=95=E8=BE=93=E5=85=A5=E3=80=81?= =?UTF-8?q?=E6=99=AE=E9=80=9A=E8=BE=93=E5=85=A5=E7=9B=91=E5=90=AC=20?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=9B=9E=E8=BD=A6=E8=AF=AF=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/ai/chat/index.vue | 68 ++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/views/ai/chat/index.vue b/src/views/ai/chat/index.vue index 5bbd5e91..7726db19 100644 --- a/src/views/ai/chat/index.vue +++ b/src/views/ai/chat/index.vue @@ -156,6 +156,9 @@
@@ -217,6 +220,7 @@ const conversationList = [ const {copy} = useClipboard(); const searchName = ref('') // 查询的内容 +const inputTimeout = ref() // 处理输入中回车的定时器 const conversationId = ref('1781604279872581648') // 对话id const conversationInProgress = ref() // 对话进行中 conversationInProgress.value = false @@ -227,6 +231,7 @@ const prompt = ref() // prompt // 判断 消息列表 滚动的位置(用于判断是否需要滚动到消息最下方) const messageContainer: any = ref(null); const isScrolling = ref(false)//用于判断用户是否在滚动 +const isComposing = ref(false) // 判断用户是否在输入 /** chat message 列表 */ // defineOptions({ name: 'chatMessageList' }) @@ -257,11 +262,22 @@ const searchConversation = () => { /** send */ const onSend = async () => { + // 判断用户是否在输入 + if (isComposing.value) { + return + } // 进行中不允许发送 if (conversationInProgress.value) { return } - const content = prompt.value; + const content = prompt.value?.trim(); + if (content?.length < 2) { + ElMessage({ + message: '请输入内容!', + type: 'error', + }) + return + } // 清空输入框 prompt.value = '' 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 () => { // 获取模型 @@ -448,6 +513,7 @@ onMounted(async () => { }) } }) + })