Commit 02ffe1c7 by 前端

无录音文件提交

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