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;
uni.$isNetWork().then(() => {
if (this.snapshot.size == 0) { if (this.snapshot.size == 0) {
this.enQueue(); this.enQueue();
setTimeout(() => { this.pollingLater(interval);
this.polling();
}, 1000 * 60);
} else { } else {
console.log(this.snapshot, "this.snapshot");
const record = this.snapshot.dequeue(); const record = this.snapshot.dequeue();
console.log(record);
this.uploadRecord(record); this.uploadRecord(record);
} }
}).catch(() => {
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!