Commit 16ab2579 by yixinjj

轮询逻辑拆分

1 parent 8bb2c25e
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 = 6 const interval = 6;
export default { export default {
onLoad() {}, onLoad() {},
data() { data() {
...@@ -222,18 +222,24 @@ export default { ...@@ -222,18 +222,24 @@ export default {
polling() { polling() {
console.log(this.snapshot.size, "this.snapshot.size"); console.log(this.snapshot.size, "this.snapshot.size");
if (this.snapshot === null) return; if (this.snapshot === null) return;
uni.$isNetWork().then(() => { uni
if (this.snapshot.size == 0) { .$isNetWork()
this.enQueue(); .then(() => {
this.pollingLater(interval); this.upload();
} else { })
const record = this.snapshot.dequeue(); .catch(() => {
this.uploadRecord(record);
}
}).catch(() => {
this.pollingLater(interval); this.pollingLater(interval);
}); });
}, },
upload() {
if (this.snapshot.size == 0) {
this.enQueue();
this.pollingLater(interval);
} else {
const record = this.snapshot.dequeue();
this.uploadRecord(record);
}
},
stopPolling() { stopPolling() {
this.snapshot.clear(); this.snapshot.clear();
this.snapshot = null; this.snapshot = null;
...@@ -247,5 +253,5 @@ export default { ...@@ -247,5 +253,5 @@ export default {
beforeDestroy() { beforeDestroy() {
console.log("stopPolling"); console.log("stopPolling");
this.stopPolling(); this.stopPolling();
} },
}; };
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!