Commit df88315b by liimin

feat(recorder): 添加接待中断恢复功能

实现接待异常中断后的恢复逻辑,包括:
1. 新增恢复确认弹窗组件
2. 添加AudioManager计数器设置方法
3. 实现恢复现场的核心逻辑
4. 优化录音异常处理流程
5. 增加相关日志记录
1 parent 79b56b96
...@@ -20,6 +20,19 @@ ...@@ -20,6 +20,19 @@
<!-- 未点击开始接待,弹窗 --> <!-- 未点击开始接待,弹窗 -->
<MessageBox ref="previewRef" @confirm="previewHandler('preview', true)" :popupW="704" content="直接点击素材可进行预览,若面向车主展示,请点击「开始接待」" confirmBtnText="预览素材" @cancel="previewHandler('previewCancel')" @close="previewHandler('previewClose')"></MessageBox> <MessageBox ref="previewRef" @confirm="previewHandler('preview', true)" :popupW="704" content="直接点击素材可进行预览,若面向车主展示,请点击「开始接待」" confirmBtnText="预览素材" @cancel="previewHandler('previewCancel')" @close="previewHandler('previewClose')"></MessageBox>
<finish-reception-dialog ref="finish" @confirm="$emit('openStep')" @cancel="$emit('backHome')" /> <finish-reception-dialog ref="finish" @confirm="$emit('openStep')" @cancel="$emit('backHome')" />
<!-- 恢复接待弹窗 -->
<MessageBox
ref="resumePopup"
title="恢复接待"
content="检测到您有上次未完成的接待,是否继续接待?"
confirmBtnText="继续接待"
cancelBtnText="不再提示"
:showCancelBtn="true"
:popupW="704"
@confirm="resumeConfirm"
@cancel="resumeCancel"
@close="resumeCancel"
/>
<!-- 升级弹框 --> <!-- 升级弹框 -->
<update-box /> <update-box />
<slot name="content" /> <slot name="content" />
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn * @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-12-26 10:03:54 * @Date: 2024-12-26 10:03:54
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2025-12-30 18:31:01 * @LastEditTime: 2026-01-05 17:51:05
* @FilePath: \simgle_app\mixin\record\recorder.js * @FilePath: \simgle_app\mixin\record\recorder.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
...@@ -14,13 +14,14 @@ import permision from '@/js_sdk/wa-permission/permission.js' ...@@ -14,13 +14,14 @@ import permision from '@/js_sdk/wa-permission/permission.js'
export default { export default {
provide() { provide() {
return { return {
getRecorder: () => this.record getRecorder: () => this.recorder
} }
}, },
async mounted() { async mounted() {
this.audioManager = new AudioManager(this.onAudioStart, this.onAudioStop, this.onAudioError) this.audioManager = new AudioManager(this.onAudioStart, this.onAudioStop, this.onAudioError)
await this.initDto() await this.initDto()
this.record = new TempRecord(this.tempRecord, this.triggleTempNumber, this.attributesProvider) this.recorder = new TempRecord(this.tempRecord, this.triggleTempNumber, this.attributesProvider)
await this.recoverIfNeeded()
this.triggleTempNumber() this.triggleTempNumber()
}, },
watch: { watch: {
...@@ -47,6 +48,85 @@ export default { ...@@ -47,6 +48,85 @@ export default {
methods: { methods: {
...mapMutations('audio', ['setReceptionStatus', 'setPerRecordNumber']), ...mapMutations('audio', ['setReceptionStatus', 'setPerRecordNumber']),
...mapMutations(['clearCustomerInfo']), ...mapMutations(['clearCustomerInfo']),
/**
* 尝试恢复异常中断的录音现场
*/
async recoverIfNeeded() {
try {
const records = await this.recorder.getRecords()
// 查找最近一条未正常结束的记录(没有结束时间)
const interruptedRecord = records.find(r => !r.endTime && r.userId == this.tempRecord.userId)
if (interruptedRecord) {
uni.$logger.local.warn('〖接待管理Recorder〗 == 发现未完成的接待记录,尝试恢复现场:', interruptedRecord)
this.interruptedRecord = interruptedRecord
if (this.$refs.resumePopup) {
this.$refs.resumePopup.open()
}
return true
}
} catch (e) {
uni.$logger.local.error('〖接待管理Recorder〗 == 恢复现场失败:', e)
}
return false
},
async resumeConfirm() {
if (this.interruptedRecord) {
await this.resumeReception(this.interruptedRecord)
this.interruptedRecord = null
}
},
async resumeCancel() {
uni.$logger.local.info('〖接待管理Recorder〗 == 用户放弃恢复,不再提示')
if (this.interruptedRecord && this.interruptedRecord.id) {
try {
// 删除该条未完成的记录,避免下次再次提示
await this.record.deleteRecord(this.interruptedRecord)
uni.$logger.local.info('〖接待管理Recorder〗 == 已删除未完成记录:' + this.interruptedRecord.id)
} catch (e) {
uni.$logger.local.error('〖接待管理Recorder〗 == 删除未完成记录失败:' + e)
}
}
this.interruptedRecord = null
},
/**
* 恢复接待现场
* @param {Object} record - 异常中断的记录
*/
async resumeReception(record) {
uni.$logger.local.info('〖接待管理Recorder〗 == 用户确认恢复现场,开始恢复...')
// 1. 设置 counter 为 urlList 的数量(至少为1,确保不走新建逻辑),用于 onAudioStart 判断
const count = record.urlList?.length || 1
this.audioManager.setCounter(count)
// 2. 恢复内存对象
this.recorder.record = record
// 3. 尝试恢复 UI 状态 (Vuex)
if (record.customerName || record.customerPhone) {
try {
this.$store.commit('setCustomerInfo', {
customerName: record.customerName,
customerPhone: record.customerPhone,
customerType: record.customerType,
carType: record.carType
})
} catch (e) {
console.warn('Failed to restore vuex state', e)
}
}
// 4. 调用页面 开始接待 按钮 启动录音
await this.start()
// 5. 恢复轮询(如果需要继续上传临时文件)
this.recorder.clearLoopTimer()
this.recorder.startSaveAudioLoop()
},
//开始录音 //开始录音
async startAudio(isInitData = true) { async startAudio(isInitData = true) {
if (this._startAudioPromise) return this._startAudioPromise if (this._startAudioPromise) return this._startAudioPromise
...@@ -87,9 +167,9 @@ export default { ...@@ -87,9 +167,9 @@ export default {
}, },
async onAudioStart() { async onAudioStart() {
if (this.audioManager.counter === 0) { if (this.audioManager.counter === 0) {
await this.record.add() await this.recorder.add()
} else { } else {
this.record.addAudio() this.recorder.addAudio()
} }
}, },
async onAudioStop() { async onAudioStop() {
...@@ -126,18 +206,18 @@ export default { ...@@ -126,18 +206,18 @@ export default {
async saveAndClearRecord(isNotSave = false) { async saveAndClearRecord(isNotSave = false) {
if (isNotSave) { if (isNotSave) {
uni.$logger.local.warn('〖接待管理Recorder〗 == 不保存记录! ') uni.$logger.local.warn('〖接待管理Recorder〗 == 不保存记录! ')
this.record.clearSavedFiles() this.recorder.clearSavedFiles()
this.record.clearLocalRecord() this.recorder.clearLocalRecord()
return return
} }
this.record.setReceptionEndTime() //设置接待结束时间 this.recorder.setReceptionEndTime() //设置接待结束时间
//如果不需要保存记录 //如果不需要保存记录
await this.record.save() await this.recorder.save()
}, },
stop() { stop() {
this.endWatchClick?.() this.endWatchClick?.()
this.record?.clearLoopTimer() this.recorder?.clearLoopTimer()
this.audioManager?.stop() this.audioManager?.stop()
}, },
handler(params, fn) { handler(params, fn) {
...@@ -146,11 +226,11 @@ export default { ...@@ -146,11 +226,11 @@ export default {
} }
}, },
isReceptioning() { isReceptioning() {
return this.audioManager?.isRecording || this.record?.currentRecord?.endReasonType == 1 return this.audioManager?.isRecording || this.recorder?.currentRecord?.endReasonType == 1
}, },
reset() { reset() {
this.audioManager = null this.audioManager = null
this.record = null this.recorder = null
this.tempRecord = null this.tempRecord = null
}, },
async initDto() { async initDto() {
...@@ -176,17 +256,17 @@ export default { ...@@ -176,17 +256,17 @@ export default {
customerType, customerType,
carType carType
} }
this.record.updatePreRecords(params) this.recorder.updatePreRecords(params)
}, },
updateReceptionStatus(status) { updateReceptionStatus(status) {
this.record.updatePreRecords({ result: status }) this.recorder.updatePreRecords({ result: status })
}, },
getRecorder() { getRecorder() {
return this.record return this.recorder
}, },
async triggleTempNumber() { async triggleTempNumber() {
if (!this.record) return if (!this.recorder) return
const _records = await this.record.getRecords() const _records = await this.recorder.getRecords()
this.setPerRecordNumber(_records.length) this.setPerRecordNumber(_records.length)
}, },
async isPermission(hintText = '为了记录语音通话,请打开录音权限') { async isPermission(hintText = '为了记录语音通话,请打开录音权限') {
...@@ -207,7 +287,7 @@ export default { ...@@ -207,7 +287,7 @@ export default {
} }
}, },
beforeDestroy() { beforeDestroy() {
this.record?.destroy() this.recorder?.destroy()
this.stop() this.stop()
this.reset() this.reset()
} }
......
...@@ -289,10 +289,12 @@ export default { ...@@ -289,10 +289,12 @@ export default {
*/ */
async initWebview() { async initWebview() {
try { try {
uni.$logger.local.warn('【上传管理Uploader】 == 初始化 WebView 开始...')
const currentWebview = this.$parent?.$scope?.$getAppWebview() const currentWebview = this.$parent?.$scope?.$getAppWebview()
const wv = currentWebview?.children()?.[0] const wv = currentWebview?.children()?.[0]
if (wv) { if (wv) {
wv.setStyle({ top: '100%', height: 300 }) wv.setStyle({ top: '100%', height: 300 })
uni.$logger.local.warn('【上传管理Uploader】 == 初始化 WebView 成功!')
return wv return wv
} }
return null return null
...@@ -749,12 +751,8 @@ export default { ...@@ -749,12 +751,8 @@ export default {
if (this._pumpRunning) return if (this._pumpRunning) return
this._pumpRunning = true this._pumpRunning = true
try { try {
if (await this._shouldPausePump()) { const isPause = await this._shouldPausePump()
await this.waitting() if (isPause) {
return
}
if (!this.snapshot || this.snapshot.size === 0) {
await this.enQueue()
await this.waitting() await this.waitting()
return return
} }
...@@ -796,6 +794,11 @@ export default { ...@@ -796,6 +794,11 @@ export default {
if (this.updateResolve || this.operationQueue?.processing) { if (this.updateResolve || this.operationQueue?.processing) {
return true return true
} }
// 5. 检查队列是否为空
if (!this.snapshot || this.snapshot.size === 0) {
await this.enQueue()
return true
}
return false return false
}, },
_scheduleNext(ms = 0) { _scheduleNext(ms = 0) {
......
...@@ -122,6 +122,10 @@ class AudioManager { ...@@ -122,6 +122,10 @@ class AudioManager {
return this.__counter return this.__counter
} }
setCounter(val) {
this.__counter = val
}
/** /**
* 重置录音状态 * 重置录音状态
* *
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @Author: limin * @Author: limin
* @Date: 2025-01-02 18:49:17 * @Date: 2025-01-02 18:49:17
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2025-12-31 11:38:31 * @LastEditTime: 2026-01-05 17:25:50
* @FilePath: \simgle_app\utils\recordManager\TempRecord.js * @FilePath: \simgle_app\utils\recordManager\TempRecord.js
*/ */
import utils from '../utils' import utils from '../utils'
...@@ -273,8 +273,12 @@ class TempRecord { ...@@ -273,8 +273,12 @@ class TempRecord {
// Update the record with the new information // Update the record with the new information
async addAudio() { async addAudio() {
this.clearLoopTimer() this.clearLoopTimer()
try {
await this.processPreviousAudio() await this.processPreviousAudio()
await helpler.sleep(1500) } catch (e) {
uni.$logger.local.error('〖接待记录Record〗 == 处理上一个录音异常,尝试继续执行: ' + e.message)
}
// await helpler.sleep(1500)
await this.addNewAudioAndStartLoop() await this.addNewAudioAndStartLoop()
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!