Commit 5eebff32 by yixinjj

调整删除文件逻辑

1 parent 2cb1e5eb
import { getOssToken } from '@/utils/ossUploadFile/uploadFile.js' import { getOssToken } from '@/utils/ossUploadFile/uploadFile.js'
import Queue from '@/utils/Queue.js' import Queue from '@/utils/Queue.js'
const interval = 60 * 10 const interval = 60 * 1
const timer = null let timer = null
export default { export default {
onLoad() {}, onLoad() {},
data() { data() {
...@@ -49,6 +49,7 @@ export default { ...@@ -49,6 +49,7 @@ export default {
} catch (e) { } catch (e) {
this.reportError(recordId, fileName, e) this.reportError(recordId, fileName, e)
} finally { } finally {
console.log('本次任务完成,开启下一次上传任务!');
this.polling() this.polling()
} }
}, },
...@@ -141,11 +142,9 @@ export default { ...@@ -141,11 +142,9 @@ export default {
const record = uni.$recordManager.getRecordById(recordId) const record = uni.$recordManager.getRecordById(recordId)
if (!record) return if (!record) return
this._changeFilePathToServer(record, filePathOnClient, filePathOnServer, fileName) this._changeFilePathToServer(record, filePathOnClient, filePathOnServer, fileName)
this._removeFileOnClient(filePathOnClient) await this._saveOrUpdate(record,filePathOnClient)
await this._saveOrUpdate(record)
} catch (err) { } catch (err) {
this.reportError(recordId, filePathOnClient, err) throw new Error(err)
Promise.reject(error)
} finally { } finally {
unlock() unlock()
} }
...@@ -197,13 +196,14 @@ export default { ...@@ -197,13 +196,14 @@ export default {
* @param {Object} record - 要保存或更新的记录对象 * @param {Object} record - 要保存或更新的记录对象
* @throws {Error} 如果在保存或更新记录时发生错误,将抛出错误 * @throws {Error} 如果在保存或更新记录时发生错误,将抛出错误
*/ */
async _saveOrUpdate(record) { async _saveOrUpdate(record,filePathOnClient) {
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 params = { ...record, recordUrlList: pathArr } const params = { ...record, recordUrlList: pathArr }
const res = await uni.$api.commonApi.saveRecCustomer(params) const res = await uni.$api.commonApi.saveRecCustomer(params)
if (res) { if (res) {
uni.$recordManager.removeRecord(record.id) uni.$recordManager.removeRecord(record.id)
this._removeFileOnClient(filePathOnClient)
} }
} else { } else {
uni.$recordManager.updateRecord(record) uni.$recordManager.updateRecord(record)
...@@ -256,10 +256,10 @@ export default { ...@@ -256,10 +256,10 @@ export default {
* @throws {Error} 如果在上传过程中发生错误,将抛出错误,延迟 interval 后继续 polling * @throws {Error} 如果在上传过程中发生错误,将抛出错误,延迟 interval 后继续 polling
*/ */
polling() { polling() {
console.log(this.snapshot.size, '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(() =>this.pollingLater(interval)) uni.$isNetWork().then(this.upload).catch(() =>{this.pollingLater(interval)})
}, },
/** /**
* 上传文件或执行队列操作 * 上传文件或执行队列操作
...@@ -269,8 +269,8 @@ export default { ...@@ -269,8 +269,8 @@ export default {
*/ */
upload() { upload() {
if (this.snapshot.size == 0) { if (this.snapshot.size == 0) {
this.enQueue()
this.pollingLater(interval) this.pollingLater(interval)
this.enQueue()
} else { } else {
let record = this.snapshot.dequeue() let record = this.snapshot.dequeue()
// while(record.file.startsWith('http')) { // while(record.file.startsWith('http')) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!