fix: interview 录音改为长按按住录音松开提交

startRecord 先同步设 isRecording=true 再异步 uni.authorize,避免
touchend 在 authorize success 回调前就触发 stopRecord 导致录音没
来得及开始就被停止。
移除冗余 doStartRecorder 函数,inline 到 authorize success 回调中。
stopRecord 不再检查 isRecording 守卫(可能已被 startRecord 设为 true),
直接 recorder.stop()。
This commit is contained in:
yuzhiran
2026-07-05 09:32:36 +08:00
parent fe688096a4
commit 656dfabb29
+20 -22
View File
@@ -401,28 +401,11 @@ function startRecord() {
if (aiLoading.value || isComplete.value) return if (aiLoading.value || isComplete.value) return
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
if (isRecording.value) return if (isRecording.value) return
// 先确保已获得 scope.record 授权,避免没权限时产生全 0 的 corrupted 音频 // 先标记正在录音,避免 touchend 在 authorize 回调前就触发 stopRecord
isRecording.value = true
uni.authorize({ uni.authorize({
scope: 'scope.record', scope: 'scope.record',
success: () => doStartRecorder(), success: () => {
fail: () => {
uni.showModal({
title: '需要录音权限',
content: '请在「设置」中开启「麦克风」权限后再使用语音输入',
confirmText: '去设置',
success: (r) => { if (r.confirm) uni.openSetting({}) },
})
},
})
// #endif
// #ifndef MP-WEIXIN
uni.showToast({ title: '语音输入仅支持小程序', icon: 'none' })
// #endif
}
// #ifdef MP-WEIXIN
function doStartRecorder() {
isRecording.value = true
if (!recorder) initRecorder() if (!recorder) initRecorder()
if (!recorder) { if (!recorder) {
isRecording.value = false isRecording.value = false
@@ -436,12 +419,27 @@ function doStartRecorder() {
encodeBitRate: 128000, encodeBitRate: 128000,
}) })
uni.vibrateShort({ type: 'medium' }) uni.vibrateShort({ type: 'medium' })
},
fail: () => {
isRecording.value = false
uni.showModal({
title: '需要录音权限',
content: '请在「设置」中开启「麦克风」权限后再使用语音输入',
confirmText: '去设置',
success: (r) => { if (r.confirm) uni.openSetting({}) },
})
},
})
// #endif
// #ifndef MP-WEIXIN
isRecording.value = false
uni.showToast({ title: '语音输入仅支持小程序', icon: 'none' })
// #endif
} }
// #endif
function stopRecord() { function stopRecord() {
if (!recorder || !isRecording.value) return
isRecording.value = false isRecording.value = false
if (!recorder) return
recorder.stop() recorder.stop()
} }
</script> </script>