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,7 +222,16 @@ export default { ...@@ -222,7 +222,16 @@ 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
.$isNetWork()
.then(() => {
this.upload();
})
.catch(() => {
this.pollingLater(interval);
});
},
upload() {
if (this.snapshot.size == 0) { if (this.snapshot.size == 0) {
this.enQueue(); this.enQueue();
this.pollingLater(interval); this.pollingLater(interval);
...@@ -230,9 +239,6 @@ export default { ...@@ -230,9 +239,6 @@ export default {
const record = this.snapshot.dequeue(); const record = this.snapshot.dequeue();
this.uploadRecord(record); this.uploadRecord(record);
} }
}).catch(() => {
this.pollingLater(interval);
});
}, },
stopPolling() { stopPolling() {
this.snapshot.clear(); this.snapshot.clear();
...@@ -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!