recorder.js
3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 11:28:48
* @LastEditors: limin
* @LastEditTime: 2024-12-06 14:44:19
* @FilePath: \gl_tape\utils\recordManager\recorder.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import AudioManager from './AudioManager'
import Record from './Record'
const UPLOAD_STATUS = {
// 上传状态
success: 1,
fail: 2
}
const AUDIO_STATUS = {
START: 'start', //录音中
END: 'end', //录音结束
ABNORMAL: 'abnormal' //40分钟未触碰平板,断开录音,不提交记录
}
import { mapMutations, mapState } from 'vuex'
import utils from '@/utils/utils.js'
export default {
data() {
return {
voicePath: '',
times: 0,
timeout: 240,
reaction: 1,
audioManager: null,
record: null
}
},
async mounted() {
this.audioManager = AudioManager.getInstance()
this.record = this.audioManager.record
this.recovery()
},
watch: {
/**
* 监听客户信息是否发生变化
* @param {object} val 监听客户信息
*/
changeData: {
handler(val) {
console.log(val, 'val', this.audioInfo.audioStatus)
if (!this.audioManager.isRecording) return
const { customerInfo, booksList, receptionStatus } = val
this.record.updatePreRecords(customerInfo, booksList, receptionStatus)
},
deep: true
}
},
computed: {
...mapState('audio', ['receptionStatus', 'booksList', 'audioInfo']),
...mapState(['user.customerInfo']),
changeData() {
const customerInfo = this.$store?.state?.user?.customerInfo || {}
const booksList = this.booksList || []
const receptionStatus = this.receptionStatus
return { customerInfo, booksList, receptionStatus }
}
},
methods: {
...mapMutations('audio', ['setReceptionStatus', 'setBooks', 'setAudioInfo']),
//开始录音
startAudio: utils.throttle(async function () {
if (this.audioManager.isRecording) return
uni.$logger.local.info('开始接待')
this.setBooks([])
this.$store.dispatch('clearCustomerInfo')
this.setReceptionStatus('')
this.initTime()
// this.setAudioInfo({ audioList: [], audioStatus: AUDIO_STATUS.START })
this.audioManager.start()
}, 300),
onAudioStart() {
if (this.audioManager.counter === 0) {
this.record.add(this.customerInfo, this.booksList, this.receptionStatus)
} else {
this.record.addAudio()
}
},
onAudioStop() {
if (this.audioManager.isRecording) {
uni.$logger.local.info('接待中,再次开启录音!')
this.audioManager.start()
} else {
uni.$logger.local.info('断开录音!')
}
},
onAudioError(error) {
const message = error.message
this.reportError(`录音异常: error: ${message}`, message)
},
async recovery() {
const records = this.record.getRecords()
if (!records.length) return
while (records.length) {
const record = records.shift()
await this.record.save(record)
}
},
/**
* 结束接待
* @params {boolean} status true 不保存记录/AUDIO_STATUS.ABNORMAL 只要断开录音
* @returns {void}
*/
stopAudio(status) {
this.endWatchClick()
this.audioManager.stop()
const preRecord = this.record.preRecord
//直接退出
if (status) {
uni.$logger.local.info('退出接待,不保存记录!')
this.record.removeRecord(preRecord.id)
return
}
this.record.save(preRecord)
}
}
}