Commit c4af6d3c by 前端

文件

1 parent 9a553a20
...@@ -16,7 +16,7 @@ module.exports = { ...@@ -16,7 +16,7 @@ module.exports = {
// SERVER: 'app-admin-server.test.glsx.com.cn', // SERVER: 'app-admin-server.test.glsx.com.cn',
// SOCKET_PORT: '9081', // SOCKET_PORT: '9081',
// HTTP_PORT: '3000', // HTTP_PORT: '3000',
HTTP_SERVER: 'http://app-admin-server.test.glsx.com.cn', HTTP_SERVER: 'http://app-admin-server.glsx.com.cn',
SOCKET_SERVER: 'http://app-admin-server.test.glsx.com.cn', SOCKET_SERVER: 'http://app-admin-server.glsx.com.cn',
FILE_UPLOAD_URL: 'file/upload' FILE_UPLOAD_URL: 'file/upload'
} }
const target = ['ip', 'dev', 'uat', 'prod', 'beta'] const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 2 const index = 3
/** /**
* *
0本地 0本地
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name" : "展业助手", "name" : "展业助手",
"appid" : "__UNI__D3BD3DF", "appid" : "__UNI__D3BD3DF",
"description" : "", "description" : "",
"versionName" : "2.0.0", "versionName" : "2.0.1",
"versionCode" : "100", "versionCode" : "100",
"transformPx" : false, "transformPx" : false,
/* 5+App特有相关 */ /* 5+App特有相关 */
......
...@@ -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-11-19 11:18:42 * @LastEditTime: 2024-11-20 16:59:06
* @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
*/ */
...@@ -147,7 +147,7 @@ export default { ...@@ -147,7 +147,7 @@ export default {
* @param {string} oldFilePath 旧的文件路径 * @param {string} oldFilePath 旧的文件路径
* @param {string} newFileName 新的文件名 * @param {string} newFileName 新的文件名
*/ */
RenameFile(oldFilePath, newFileName) { renameFile(oldFilePath, newFileName) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
plus.io.resolveLocalFileSystemURL( plus.io.resolveLocalFileSystemURL(
oldFilePath, oldFilePath,
...@@ -254,7 +254,7 @@ export default { ...@@ -254,7 +254,7 @@ export default {
} }
let newFileName = String(phone).slice(-4) + '_' + oldFilePath.replace(/.+\/(\d+\.mp3)/, '$1') let newFileName = String(phone).slice(-4) + '_' + oldFilePath.replace(/.+\/(\d+\.mp3)/, '$1')
try { try {
await this.RenameFile(oldFilePath, newFileName) await this.renameFile(oldFilePath, newFileName)
} catch { } catch {
uni.$logger.local.error(`${newFileName}文件重命名失败`) uni.$logger.local.error(`${newFileName}文件重命名失败`)
newFileName = oldFilePath.replace(/.+\/(\d+\.mp3)/, '$1') newFileName = oldFilePath.replace(/.+\/(\d+\.mp3)/, '$1')
......
...@@ -9,14 +9,14 @@ export default { ...@@ -9,14 +9,14 @@ export default {
wv: null, wv: null,
snapshot: null, snapshot: null,
interval: 60 * 5, interval: 60 * 5,
timer: null timer: null,
_isUploading: false
} }
}, },
mounted() { mounted() {
this.init() this.init()
this.subscribe() this.subscribe()
}, },
methods: { methods: {
/** /**
* 初始化函数 * 初始化函数
...@@ -66,11 +66,10 @@ export default { ...@@ -66,11 +66,10 @@ export default {
/** /**
* 上报文件上传失败日志 * 上报文件上传失败日志
*/ */
reportError(recordId, filePath, res) { reportError(recordId, filePath, res, message = '上传文件失败!!') {
const { customerName, phoneNumber, carModel, salesName } = uni.$recordManager.getRecordById(recordId) || {} const { customerName, phoneNumber, carModel, salesName } = uni.$recordManager.getRecordById(recordId) || {}
// const { name } = uni.$storage.get('userInfo') || {} // const { name } = uni.$storage.get('userInfo') || {}
uni.$logger.error({ msg: '上传文件失败!!', extra: { '手机号: ': phoneNumber, '姓名: ': customerName, '销售: ': salesName, '车型: ': carModel, '原因: ': JSON.stringify(res), '文件路径: ': filePath } }) uni.$logger.error({ msg: message, extra: { '手机号: ': phoneNumber, '姓名: ': customerName, '销售: ': salesName, '车型: ': carModel, '原因: ': JSON.stringify(res), '文件路径: ': filePath } })
// this.$sendSentry(`上传失败:文件-${filePath} 手机号-${phoneNumber} 姓名-${customerName} 销售-${salesName} 车型-${carModel} 员工-${name}失败原因-${JSON.stringify(res)}`)
}, },
/** /**
* 初始化 WebView 的异步函数 * 初始化 WebView 的异步函数
...@@ -171,7 +170,7 @@ export default { ...@@ -171,7 +170,7 @@ export default {
const record = uni.$recordManager.getRecordById(recordId) const record = uni.$recordManager.getRecordById(recordId)
if (!record) return uni.$logger.local.info(`未找到接待记录!!`) if (!record) return uni.$logger.local.info(`未找到接待记录!!`)
this._changeFilePathToServer(record, filePathOnClient, filePathOnServer, fileName) this._changeFilePathToServer(record, filePathOnClient, filePathOnServer, fileName)
await this._saveOrUpdate(record, filePathOnClient) await this._saveOrUpdate(record)
} catch (err) { } catch (err) {
throw new Error(err) throw new Error(err)
} finally { } finally {
...@@ -195,6 +194,7 @@ export default { ...@@ -195,6 +194,7 @@ export default {
record.recordUrlList?.forEach(fileInfo => { record.recordUrlList?.forEach(fileInfo => {
if (fileInfo.file === filePathOnClient || fileInfo.file.endsWith(fileName)) { if (fileInfo.file === filePathOnClient || fileInfo.file.endsWith(fileName)) {
fileInfo.file = filePathOnServer fileInfo.file = filePathOnServer
fileInfo.filePathOnClient = filePathOnClient
delete fileInfo.status delete fileInfo.status
uni.$logger.local.info(`修改文件路径完成并删除文件status属性!! fileInfo.file-> ${fileInfo.file} fileInfo.status-> ${fileInfo.status}`) uni.$logger.local.info(`修改文件路径完成并删除文件status属性!! fileInfo.file-> ${fileInfo.file} fileInfo.status-> ${fileInfo.status}`)
} }
...@@ -211,14 +211,15 @@ export default { ...@@ -211,14 +211,15 @@ export default {
*/ */
_removeFileOnClient(filePathOnClient) { _removeFileOnClient(filePathOnClient) {
uni.$logger.local.info(`开始删除客户端的文件!! 路径-> ${filePathOnClient}`) uni.$logger.local.info(`开始删除客户端的文件!! 路径-> ${filePathOnClient}`)
//删除客户端的文件 return new Promise((resolve, reject) => {
uni.removeSavedFile({ uni.removeSavedFile({
filePath: filePathOnClient, filePath: filePathOnClient,
complete: function (res) { complete: function (res) {
// console.log(res)
uni.$logger.local.info(`${filePathOnClient}->删除成功!!`) uni.$logger.local.info(`${filePathOnClient}->删除成功!!`)
resolve(res)
} }
}) })
})
}, },
/** /**
* 保存或更新记录 * 保存或更新记录
...@@ -230,10 +231,11 @@ export default { ...@@ -230,10 +231,11 @@ export default {
* @param {Object} record - 要保存或更新的记录对象 * @param {Object} record - 要保存或更新的记录对象
* @throws {Error} 如果在保存或更新记录时发生错误,将抛出错误 * @throws {Error} 如果在保存或更新记录时发生错误,将抛出错误
*/ */
async _saveOrUpdate(record, filePathOnClient) { async _saveOrUpdate(record) {
uni.$logger.local.info(`开始保存或更新接待记录!! record-> ${JSON.stringify(record)}`) uni.$logger.local.info(`开始保存或更新接待记录!! record-> ${JSON.stringify(record)}`)
if (record.recordUrlList?.every(i => i.status == undefined)) { if (record.recordUrlList?.every(i => i.status == undefined)) {
const pathArr = record.recordUrlList.map(i => i.file) const pathArr = record.recordUrlList.map(i => i.file)
const originalFileArr = record.recordUrlList.map(i => i.filePathOnClient)
const params = { ...record, recordUrlList: pathArr } const params = { ...record, recordUrlList: pathArr }
uni.$logger.local.info(`记录中的文件已全部上传,开始向服务器保存接待记录!!`) uni.$logger.local.info(`记录中的文件已全部上传,开始向服务器保存接待记录!!`)
if (!params.receptionEndTime) { if (!params.receptionEndTime) {
...@@ -246,12 +248,16 @@ export default { ...@@ -246,12 +248,16 @@ export default {
if (res) { if (res) {
uni.$logger.local.info(`保存接待记录成功,开始删除本地接待记录!!`) uni.$logger.local.info(`保存接待记录成功,开始删除本地接待记录!!`)
uni.$recordManager.removeRecord(record.id) uni.$recordManager.removeRecord(record.id)
this._removeFileOnClient(filePathOnClient) while (originalFileArr.length > 0) {
const file = originalFileArr.shift()
await this._removeFileOnClient(file)
}
// await this._removeFileOnClient(filePathOnClient)
} }
} else { } else {
uni.$logger.local.info(`记录中有未上传文件,开始更新记录!!`) uni.$logger.local.info(`记录中有未上传文件,开始更新记录!!`)
uni.$recordManager.updateRecord(record) uni.$recordManager.updateRecord(record)
this._removeFileOnClient(filePathOnClient) // await this._removeFileOnClient(filePathOnClient)
} }
}, },
async _saveOrUpdateFail(recordId) { async _saveOrUpdateFail(recordId) {
...@@ -293,27 +299,58 @@ export default { ...@@ -293,27 +299,58 @@ export default {
* @param {Array} records - 要展开的记录列表 * @param {Array} records - 要展开的记录列表
* @returns {Array} - 展开后包含文件对象的列表,每个文件对象都包含一个 recordId 属性 * @returns {Array} - 展开后包含文件对象的列表,每个文件对象都包含一个 recordId 属性
*/ */
flattenData(records) { async flattenData(records) {
const result = records.reduce((acc, cur) => { const result = []
for (const cur of records) {
cur.recordUrlList = cur.recordUrlList || [] cur.recordUrlList = cur.recordUrlList || []
let recordUrlList = cur.recordUrlList.map(file => { // 如果记录没有文件,添加一个空记录
if (!file.status) { if (cur.recordUrlList.length == 0) {
return [] result.push({ recordId: cur.id })
this.reportError(cur.id, '', cur, '记录中不存在接待语音文件') //记录中不存在接待语音文件
continue
} }
// 处理每个记录的文件列表
for (const file of cur.recordUrlList) {
if (!file.status) continue
const aFullPath = file.file.split('/') const aFullPath = file.file.split('/')
const fileName = aFullPath.pop() const fileName = aFullPath.pop()
const filePath = aFullPath.join('/') + '/' const filePath = aFullPath.join('/') + '/'
return { ...file, recordId: cur.id, fileName, filePath } // 检查文件是否存在
}) const fileExists = await this.checkFileExists(file.file)
if (cur.recordUrlList.length == 0) { if (!fileExists) {
recordUrlList = [{ recordId: cur.id }] this.reportError(cur.id, fileName, cur, '记录中有语音文件地址,但是文件不存在') //记录中语音文件不存在
continue
}
result.push({ ...file, recordId: cur.id, fileName, filePath })
}
} }
acc = acc.concat(...recordUrlList)
return acc
}, [])
return result return result
}, },
/** /**
* 检查文件是否存在
* 此函数检查指定路径的文件是否存在
*
* @param {string} filePath - 要检查的文件路径
* @returns {Promise<boolean>} - 返回一个 Promise,当文件存在时解析为 true,否则解析为 false
*/
async checkFileExists(filePath) {
return new Promise(resolve => {
if (!filePath) {
resolve(false)
return
}
uni.getFileInfo({
filePath: filePath,
success: function (info) {
resolve(true)
},
fail: function (error) {
resolve(false)
}
})
})
},
/**
* 轮询函数 * 轮询函数
* 这个函数用于检查一个队列的大小,并在需要时执行文件上传操作 * 这个函数用于检查一个队列的大小,并在需要时执行文件上传操作
* 如果队列大小为 0,则调用 enQueue() 函数来获取新的文件进行上传,并延迟一段时间后再次轮询 * 如果队列大小为 0,则调用 enQueue() 函数来获取新的文件进行上传,并延迟一段时间后再次轮询
...@@ -327,7 +364,7 @@ export default { ...@@ -327,7 +364,7 @@ export default {
// console.log(this.snapshot.size, '当前待上传文件快照数量') // console.log(this.snapshot.size, '当前待上传文件快照数量')
if (this.snapshot === null) return if (this.snapshot === null) return
// prettier-ignore // prettier-ignore
uni.$isNetWork().then(this.upload).catch(e =>{ uni.$isNetWork().then(this.upload).catch(e => {
this.reportError('', '异常', e) this.reportError('', '异常', e)
this.pollingLater(this.interval) this.pollingLater(this.interval)
}) })
...@@ -339,13 +376,19 @@ export default { ...@@ -339,13 +376,19 @@ export default {
* @throws {Error} 如果在上传过程中发生错误,将抛出错误,延迟 interval 后继续 polling * @throws {Error} 如果在上传过程中发生错误,将抛出错误,延迟 interval 后继续 polling
*/ */
async upload() { async upload() {
if (this._isUploading) return
try {
this._isUploading = true
if (this.snapshot.size == 0) { if (this.snapshot.size == 0) {
await this.enQueue()
this.pollingLater(this.interval) this.pollingLater(this.interval)
this.enQueue()
} else { } else {
let record = this.snapshot.dequeue() let record = this.snapshot.dequeue()
await this.uploadRecord(record) await this.uploadRecord(record)
} }
} finally {
this._isUploading = false
}
}, },
/** /**
* 停止轮询并清除队列 * 停止轮询并清除队列
...@@ -393,7 +436,6 @@ export default { ...@@ -393,7 +436,6 @@ export default {
this.timer = null this.timer = null
} }
}, },
/** /**
* 在指定的时间间隔后启动轮询 * 在指定的时间间隔后启动轮询
* 这个函数用于在指定的时间间隔后执行轮询操作 * 这个函数用于在指定的时间间隔后执行轮询操作
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn * @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-10-14 17:38:35 * @Date: 2024-10-14 17:38:35
* @LastEditors: 前端 qianduan01@didihu.com.cn * @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-11-19 09:35:24 * @LastEditTime: 2024-11-20 17:27:29
* @FilePath: \gl-tape\utils\recordManager\interruptRecord.js * @FilePath: \gl-tape\utils\recordManager\interruptRecord.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
*/ */
...@@ -129,9 +129,10 @@ class InterruptRecord extends RecordManager { ...@@ -129,9 +129,10 @@ class InterruptRecord extends RecordManager {
const pathName = await this.getAudioPathName() const pathName = await this.getAudioPathName()
const audioPath = await this.getAudioPath(pathName) const audioPath = await this.getAudioPath(pathName)
this.audioPath = audioPath this.audioPath = audioPath
const addAudioPath = [...this.records.audioPath, audioPath]
this.records.audioPath.push(audioPath) this.records.audioPath.push(audioPath)
const records = this.getPreRecord() const records = this.getPreRecord()
const params = { ...records, ...this.records } const params = { ...records, audioPath: addAudioPath }
this.updateRecord(params) this.updateRecord(params)
this.setLoopAudio() this.setLoopAudio()
} }
...@@ -219,17 +220,39 @@ class InterruptRecord extends RecordManager { ...@@ -219,17 +220,39 @@ class InterruptRecord extends RecordManager {
var dirR = e.createReader() var dirR = e.createReader()
dirR.readEntries( dirR.readEntries(
function (er) { function (er) {
for (var i = 0; i < er.length; i++) { Promise.all(
if (er[i].name.startsWith('uniapp_temp')) { er.map((item, index) => {
resolve(er[i].name) console.log(item, 'item')
} return new Promise(resolve => {
// er[i].getMetadata(function (metadata) { item.getMetadata(metadata => {
// console.log(metadata.modificationTime, '修改时间') resolve({
// }) index: index,
name: item.name,
modificationTime: new Date(metadata.modificationTime).getTime()
})
})
})
})
).then(results => {
console.log(results, 'results')
results = results.filter(i => i.name.startsWith('uniapp_temp'))
// 找到修改时间最晚的文件
const latest = results.reduce(
(acc, current) => {
if (current.modificationTime > acc.modificationTime) {
return current
} }
return acc
},
{ modificationTime: 0 }
)
// 修改时间最晚的文件名
resolve(latest.name)
})
}, },
err => { err => {
console.log(err) reject(err)
} }
) )
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!