Commit 2cb1e5eb by yixinjj

调整定时器启动逻辑

1 parent 1c4757c6
import { getOssToken } from '@/utils/ossUploadFile/uploadFile.js'
import Queue from '@/utils/Queue.js'
const interval = 60*10
const interval = 60 * 10
const timer = null
export default {
onLoad() {},
data() {
......@@ -24,7 +25,7 @@ export default {
async init() {
this.wv = await this.initWebview()
await this.enQueue()
this.pollingLater(interval)
this.polling()
},
/**
* 处理消息函数
......@@ -35,32 +36,29 @@ export default {
* @param {Object} result - 包含消息详情的对象
* @throws {Error} 如果解构对象时缺少关键属性,将抛出错误
*/
handlerMessage(result) {
async handlerMessage(result) {
const { code, fileName, data, recordId, filePath, filePathOnClient = filePath + fileName } = result.detail.data[0]
try{
try {
if (code == 0) {
const filePathOnServer = data.oss.res.requestUrls[0].split('?')[0]
this.uploadSuccess(recordId, filePathOnServer, filePathOnClient, fileName)
await this.uploadSuccess(recordId, filePathOnServer, filePathOnClient, fileName)
} else {
this.reportError(recordId,fileName,data)
this.polling()
this.reportError(recordId, fileName, data)
// this.$sendSentry(`上传失败:文件名-${fileName} 错误码-${data.oss.res.status},失败原因-${JSON.stringify(data.oss.res)}`);
}
} catch(e) {
this.reportError(recordId,fileName,e)
} catch (e) {
this.reportError(recordId, fileName, e)
} finally {
this.polling()
}
},
/**
* 上报文件上传失败日志
*/
reportError(recordId, filePath,res) {
const { customerName, phoneNumber, carModel, salesName } =
uni.$recordManager.getRecordById(recordId) || {};
const { name } = uni.$storage.get("userInfo");
this.$sendSentry(
`上传失败:文件-${filePath} 手机号-${phoneNumber} 姓名-${customerName} 销售-${salesName} 车型-${carModel} 员工-${name}失败原因-${JSON.stringify(res)}`
);
reportError(recordId, filePath, res) {
const { customerName, phoneNumber, carModel, salesName } = uni.$recordManager.getRecordById(recordId) || {}
const { name } = uni.$storage.get('userInfo')
this.$sendSentry(`上传失败:文件-${filePath} 手机号-${phoneNumber} 姓名-${customerName} 销售-${salesName} 车型-${carModel} 员工-${name}失败原因-${JSON.stringify(res)}`)
},
/**
* 初始化 WebView 的异步函数
......@@ -146,11 +144,10 @@ export default {
this._removeFileOnClient(filePathOnClient)
await this._saveOrUpdate(record)
} catch (err) {
this.reportError(recordId,filePathOnClient,err)
this.reportError(recordId, filePathOnClient, err)
Promise.reject(error)
} finally {
unlock()
this.polling()
}
},
/**
......@@ -235,8 +232,8 @@ export default {
*/
flattenData(records) {
const result = records.reduce((acc, cur) => {
const recordUrlList = cur.recordUrlList.map(file => {
if(!file.status) {
const recordUrlList = cur.recordUrlList.map(file => {
if (!file.status) {
return []
}
const aFullPath = file.file.split('/')
......@@ -291,6 +288,7 @@ export default {
stopPolling() {
this.snapshot.clear()
this.snapshot = null
if (timer) clearTimeout(timer)
},
/**
* 在指定的时间间隔后启动轮询
......@@ -299,7 +297,8 @@ export default {
* @returns {void} - 此函数不返回任何值
*/
pollingLater(interval = 60 * 10) {
setTimeout(() => {
if (timer) clearTimeout(timer)
timer = setTimeout(() => {
this.polling()
}, interval * 1000)
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!