fix: sendAnswer await startInterview + stopRecord guard
- sendAnswer: await startInterview() 后再发答案,避免面试还没创建 就把用户输入 '你好' 当成答案提交给空 interviewId - stopRecord: 加 !isRecording.value 守卫,防止 user touchend 在 uni.authorize success 回调之前触发 recorder.stop() 导致报错
This commit is contained in:
@@ -301,9 +301,10 @@ const startInterview = async () => {
|
||||
const sendAnswer = async () => {
|
||||
if (!inputText.value.trim() || aiLoading.value || isComplete.value) return
|
||||
if (!token()) { checkLogin(); return }
|
||||
// 确保面试已创建(startInterview 是 async,必须 await)
|
||||
if (!interviewId.value) {
|
||||
await startInterview()
|
||||
if (!interviewId.value) return // creation failed, don't discard answer
|
||||
if (!interviewId.value) return // 创建失败,不丢弃用户输入
|
||||
}
|
||||
|
||||
const answer = inputText.value.trim()
|
||||
@@ -412,6 +413,7 @@ function startRecord() {
|
||||
uni.showToast({ title: '录音初始化失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
// 确保在授权通过后才开始录音,避免 stopRecord 先于 startRecord 被调用
|
||||
recorder.start({
|
||||
format: 'wav',
|
||||
sampleRate: 16000,
|
||||
@@ -438,6 +440,7 @@ function startRecord() {
|
||||
}
|
||||
|
||||
function stopRecord() {
|
||||
if (!isRecording.value) return
|
||||
isRecording.value = false
|
||||
if (!recorder) return
|
||||
recorder.stop()
|
||||
|
||||
Reference in New Issue
Block a user