Commit 8cbf4ab9 by yixinjj

添加无网络逻辑

1 parent 243df4d9
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
export default { export default {
onLoad() {}, onLoad() {},
data() { data() {
...@@ -216,24 +217,29 @@ export default { ...@@ -216,24 +217,29 @@ export default {
*/ */
polling() { polling() {
if (this.snapshot === null) return; if (this.snapshot === null) return;
if (this.snapshot.size == 0) { uni.$isNetWork().then(() => {
this.enQueue(); if (this.snapshot.size == 0) {
setTimeout(() => { this.enQueue();
this.polling(); this.pollingLater(interval);
}, 1000 * 60); } else {
} else { const record = this.snapshot.dequeue();
console.log(this.snapshot, "this.snapshot"); this.uploadRecord(record);
const record = this.snapshot.dequeue(); }
console.log(record); }).catch(() => {
this.uploadRecord(record); this.pollingLater(interval);
} });
}, },
stopPolling() { stopPolling() {
this.snapshot.clear(); this.snapshot.clear();
this.snapshot = null this.snapshot = null;
},
pollingLater(interval = 60 * 10) {
setTimeout(() => {
this.polling();
}, interval * 1000);
}, },
onUnload() { onUnload() {
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!