From 141f98477273d4e79a2eb5d28c7683991c91f27d Mon Sep 17 00:00:00 2001 From: wsb1224 Date: Sun, 7 Jun 2026 11:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E9=80=9A=E8=AF=9D=E5=A4=B1=E8=B4=A5=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20pendingCallMode=20=E9=98=B2=E9=87=8D=E5=85=A5?= =?UTF-8?q?=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一个 commit 将 chatMode 赋值延迟到连接之后,导致连接期间 chatMode 仍为 'none',guard 检查 isInCall || chatMode === 'call' 两个都为 false,用户重复点击会再次进入新建通话分支造成竞态。 增加 pendingCallMode 标记:进入连接前设为 true,连接完成(成功或失败) 后在 finally 中清 false。guard 检查中加入 pendingCallMode,连接期间 重复点击直接 return;同时简化错误处理,始终在 finally/catch 中调用 resetToDefaultMode 确保状态可靠清理。 Co-Authored-By: Claude Opus 4.7 (1M context) --- frontend/src/views/ChatView.vue | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/frontend/src/views/ChatView.vue b/frontend/src/views/ChatView.vue index bf29e9b..cb2b05f 100644 --- a/frontend/src/views/ChatView.vue +++ b/frontend/src/views/ChatView.vue @@ -1811,14 +1811,20 @@ export default { isRecording.value = false } + let pendingCallMode = false + const toggleCallMode = async () => { - if (isInCall.value || chatMode.value === 'call') { - await stopCallRecording() - await forceStopVoiceAndCall() - await resetToDefaultMode() + if (pendingCallMode || isInCall.value || chatMode.value === 'call') { + // 正在连接中 或 已在通话中 → 点击即退出 + if (!pendingCallMode) { + await stopCallRecording() + await forceStopVoiceAndCall() + await resetToDefaultMode() + } return } + pendingCallMode = true try { const hasPermission = await chatStore.requestMicrophonePermission() if (!hasPermission) { @@ -1845,9 +1851,7 @@ export default { if (success) { await chatStore.exitRealtimeCallMode() } - if (chatMode.value === 'none') { - await resetToDefaultMode() - } + await resetToDefaultMode() return } @@ -1859,9 +1863,9 @@ export default { } catch (error) { console.error('Enter call mode error:', error) ElMessage.error('连接实时语音服务失败') - if (chatMode.value === 'none') { - await resetToDefaultMode() - } + await resetToDefaultMode() + } finally { + pendingCallMode = false } }