Commit 02ffe1c7 by 前端

无录音文件提交

1 parent 2800a348
...@@ -49,7 +49,7 @@ import { index } from './env' ...@@ -49,7 +49,7 @@ import { index } from './env'
// } // }
Vue.prototype.$permision = permision Vue.prototype.$permision = permision
import sentryInit from '@/utils/sentryConfig/sentryInit' import sentryInit from '@/utils/sentryConfig/sentryInit'
if (index == 3) { if (index == 3 || index == 2) {
const sentry = sentryInit() const sentry = sentryInit()
Vue.prototype.$sendSentry = function (e) { Vue.prototype.$sendSentry = function (e) {
sentry.captureException(e) sentry.captureException(e)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn * @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 11:28:48 * @Date: 2024-04-08 11:28:48
* @LastEditors: 前端 qianduan01@didihu.com.cn * @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-10-23 17:23:29 * @LastEditTime: 2024-10-29 13:33:37
* @FilePath: \gl_tape\mixin\click.js * @FilePath: \gl_tape\mixin\click.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
*/ */
...@@ -15,9 +15,9 @@ const UPLOAD_STATUS = { ...@@ -15,9 +15,9 @@ const UPLOAD_STATUS = {
fail: 2 fail: 2
} }
const AUDIO_STATUS = { const AUDIO_STATUS = {
START: 'start', //开始 START: 'start', //录音中
END: 'end', //结束 END: 'end', //录音结束
ABNORMAL: 'abnormal' //异常 ABNORMAL: 'abnormal' //40分钟未触碰平板,断开录音,不提交记录
} }
const audioTime = 10 * 60 * 1000 const audioTime = 10 * 60 * 1000
import { mapMutations, mapState } from 'vuex' import { mapMutations, mapState } from 'vuex'
...@@ -43,6 +43,10 @@ export default { ...@@ -43,6 +43,10 @@ export default {
this.initTime() this.initTime()
}, },
watch: { watch: {
/**
* 监听客户信息是否发生变化
* @param {object} val 监听客户信息
*/
changeData: { changeData: {
handler(val) { handler(val) {
console.log(val, 'val', this.audioInfo.audioStatus) console.log(val, 'val', this.audioInfo.audioStatus)
...@@ -141,8 +145,8 @@ export default { ...@@ -141,8 +145,8 @@ export default {
}, },
/** /**
* 修改文件名。 * 修改文件名。
* @param {旧的文件路径} oldFilePath * @param {string} oldFilePath 旧的文件路径
* @param {新的文件名} newFileName * @param {string} newFileName 新的文件名
*/ */
RenameFile(oldFilePath, newFileName) { RenameFile(oldFilePath, newFileName) {
plus.io.resolveLocalFileSystemURL(oldFilePath, entry => { plus.io.resolveLocalFileSystemURL(oldFilePath, entry => {
...@@ -163,6 +167,7 @@ export default { ...@@ -163,6 +167,7 @@ export default {
this.initTime() this.initTime()
this.setAudioInfo({ audioList: [], audioStatus: AUDIO_STATUS.START }) this.setAudioInfo({ audioList: [], audioStatus: AUDIO_STATUS.START })
recorderManager.onStart(() => { recorderManager.onStart(() => {
//开始录音保持记录,1s延时是因为第一段录音结束时间的文件修改时间等于第二段开始的文件修改时间,加上1s延时,就不会这个问题
setTimeout(() => { setTimeout(() => {
const params = this.getParams(this.$store.state.user.customerInfo, this.booksList, this.receptionStatus) const params = this.getParams(this.$store.state.user.customerInfo, this.booksList, this.receptionStatus)
interruptRecord.addPreRecords(params) interruptRecord.addPreRecords(params)
...@@ -174,6 +179,7 @@ export default { ...@@ -174,6 +179,7 @@ export default {
numberOfChannels: 1 numberOfChannels: 1
}) })
recorderManager.onStop(async res => { recorderManager.onStop(async res => {
//第一段录音结束,还在接待中,则开启第二段录音
if (this.audioInfo.audioStatus == AUDIO_STATUS.START) { if (this.audioInfo.audioStatus == AUDIO_STATUS.START) {
uni.getRecorderManager().start({ uni.getRecorderManager().start({
duration: audioTime, duration: audioTime,
...@@ -185,6 +191,8 @@ export default { ...@@ -185,6 +191,8 @@ export default {
}, 300), }, 300),
/** /**
* 保存记录 * 保存记录
* 首先查看有没有没有保存的记录records,没有就直接返回
* 存在没有保存的记录,首先把临时的录音文件,保存永久的录音文件,并重新命名
* @params {boolean} isNormal 是否是正常保存 * @params {boolean} isNormal 是否是正常保存
* @returns {void} * @returns {void}
*/ */
...@@ -197,33 +205,47 @@ export default { ...@@ -197,33 +205,47 @@ export default {
} }
const audioPath = records.audioPath const audioPath = records.audioPath
const recordUrlList = [] const recordUrlList = []
for (let i = 0; i < audioPath.length; i++) { try {
console.log(audioPath[i], 'audioPath[i]') // 把临时文件保存为永久录音文件
const saveResult = await uni.saveFile({ for (let i = 0; i < audioPath.length; i++) {
tempFilePath: audioPath[i] console.log(audioPath[i], 'audioPath[i]')
}) const saveResult = await uni.saveFile({
const oldFilePath = saveResult[1].savedFilePath tempFilePath: audioPath[i]
console.log(oldFilePath, 'oldFilePath') })
const { phone } = uni.$storage.get('userInfo') const oldFilePath = saveResult[1].savedFilePath
const newFileName = String(phone).slice(-4) + '_' + oldFilePath.replace(/.+\/(\d+\.mp3)/, '$1') console.log(oldFilePath, 'oldFilePath')
const newFilePath = oldFilePath.replace(/(.+\/)(\d+\.mp3)/, '') + newFileName const { phone } = uni.$storage.get('userInfo')
const path = await utils.getFileSaveFolderOnClient() const newFileName = String(phone).slice(-4) + '_' + oldFilePath.replace(/.+\/(\d+\.mp3)/, '$1')
recordUrlList.push({ status: UPLOAD_STATUS.fail, file: path + newFilePath }) const newFilePath = oldFilePath.replace(/(.+\/)(\d+\.mp3)/, '') + newFileName
this.RenameFile(oldFilePath, newFileName) const path = await utils.getFileSaveFolderOnClient()
recordUrlList.push({ status: UPLOAD_STATUS.fail, file: path + newFilePath })
this.RenameFile(oldFilePath, newFileName)
}
} catch (error) {
this.$sendSentry(`上传保存失败:${JSON.stringify(error)}`)
} }
delete records.audioPath delete records.audioPath
let saveRecords = Object.assign(records, { recordUrlList }) let saveRecords = Object.assign(records, { recordUrlList })
// 如果是正常保存,保存为待上传,并删除待提交记录,如果是异常保存,则更新待提交记录
if (isNormal) { if (isNormal) {
this.saveRecord(saveRecords) this.saveRecord(saveRecords)
} else { } else {
interruptRecord.updatePreRecords(saveRecords, true) interruptRecord.updatePreRecords(saveRecords, true)
} }
}, },
/**
* 删除待提交记录
* @returns {void}
*/
removeRecords() { removeRecords() {
const records = interruptRecord.getPreRecord() const records = interruptRecord.getPreRecord()
interruptRecord.removePreRecord(records.id) interruptRecord.removePreRecord(records.id)
}, },
/**保存记录*/ /**
* 保存待上传的记录,并删除待提交的记录
* @param {object} record 记录信息
* @returns {void}
*/
async saveRecord(record) { async saveRecord(record) {
const unlock = await uni.$recordManager.lock() const unlock = await uni.$recordManager.lock()
console.log('record', record) console.log('record', record)
...@@ -248,11 +270,13 @@ export default { ...@@ -248,11 +270,13 @@ export default {
// }); // });
// return; // return;
// } // }
//如果是40分钟未触碰平板,只要断开录音即可
if (status == AUDIO_STATUS.ABNORMAL) { if (status == AUDIO_STATUS.ABNORMAL) {
this.setAudioInfo({ audioStatus: AUDIO_STATUS.ABNORMAL }) this.setAudioInfo({ audioStatus: AUDIO_STATUS.ABNORMAL })
recorderManager.stop() recorderManager.stop()
return return
} }
//如果是40分钟未触碰平板后完成接待,需要保存记录
if (this.audioInfo.audioStatus == AUDIO_STATUS.ABNORMAL && status != true) { if (this.audioInfo.audioStatus == AUDIO_STATUS.ABNORMAL && status != true) {
this.setAudioInfo({ audioStatus: AUDIO_STATUS.END }) this.setAudioInfo({ audioStatus: AUDIO_STATUS.END })
this.handleSave() this.handleSave()
......
...@@ -126,9 +126,13 @@ export default { ...@@ -126,9 +126,13 @@ export default {
* @throws {Error} - 如果获取 OSS 令牌的过程中出现错误,将抛出错误 * @throws {Error} - 如果获取 OSS 令牌的过程中出现错误,将抛出错误
*/ */
async uploadRecord(record) { async uploadRecord(record) {
const { lsaccessKeySecret, securityToken, lsaccessKeyId } = await getOssToken() if (record.filePath) {
console.log('获取Token成功!!', `lsaccessKeySecret: ${lsaccessKeySecret}, lsaccessKeyId: ${lsaccessKeyId}`) const { lsaccessKeySecret, securityToken, lsaccessKeyId } = await getOssToken()
this.wv.evalJS(`msgFromUniapp('${lsaccessKeyId}','${lsaccessKeySecret}','${securityToken}','${record.fileName}','${record.filePath}','${record.recordId}')`) console.log('获取Token成功!!', `lsaccessKeySecret: ${lsaccessKeySecret}, lsaccessKeyId: ${lsaccessKeyId}`)
this.wv.evalJS(`msgFromUniapp('${lsaccessKeyId}','${lsaccessKeySecret}','${securityToken}','${record.fileName}','${record.filePath}','${record.recordId}')`)
} else {
this._saveOrUpdateFail(record.recordId)
}
}, },
/** /**
* 文件上传成功后的处理逻辑 * 文件上传成功后的处理逻辑
...@@ -224,7 +228,25 @@ export default { ...@@ -224,7 +228,25 @@ export default {
this._removeFileOnClient(filePathOnClient) this._removeFileOnClient(filePathOnClient)
} }
}, },
async _saveOrUpdateFail(recordId) {
const unlock = await uni.$recordManager.lock()
try {
const record = uni.$recordManager.getRecordById(recordId)
const params = { ...record, recordUrlList: [] }
if (!params.receptionEndTime) {
params.receptionEndTime = params.receptionStartTime
}
const res = await uni.$api.commonApi.saveRecCustomer(params)
if (res) {
uni.$recordManager.removeRecord(record.id)
}
} catch (e) {
this.reportError(recordId, '无文件', e)
} finally {
unlock()
this.polling()
}
},
/** /**
* 获取记录快照的异步函数 * 获取记录快照的异步函数
* 此函数获取当前记录列表的快照,并返回这些记录 * 此函数获取当前记录列表的快照,并返回这些记录
...@@ -247,7 +269,8 @@ export default { ...@@ -247,7 +269,8 @@ export default {
*/ */
flattenData(records) { flattenData(records) {
const result = records.reduce((acc, cur) => { const result = records.reduce((acc, cur) => {
const recordUrlList = cur.recordUrlList.map(file => { cur.recordUrlList = cur.recordUrlList || []
let recordUrlList = cur.recordUrlList.map(file => {
if (!file.status) { if (!file.status) {
return [] return []
} }
...@@ -256,6 +279,9 @@ export default { ...@@ -256,6 +279,9 @@ export default {
const filePath = aFullPath.join('/') + '/' const filePath = aFullPath.join('/') + '/'
return { ...file, recordId: cur.id, fileName, filePath } return { ...file, recordId: cur.id, fileName, filePath }
}) })
if (cur.recordUrlList.length == 0) {
recordUrlList = [{ recordId: cur.id }]
}
acc = acc.concat(...recordUrlList) acc = acc.concat(...recordUrlList)
return acc return acc
}, []) }, [])
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!