Commit c4af6d3c by 前端

文件

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