perf: 优化网络检查

This commit is contained in:
Pang 2024-04-08 08:13:30 +08:00
parent c61815db3a
commit cda2d0da27
2 changed files with 29 additions and 11 deletions

View File

@ -48,17 +48,43 @@ export default {
},
computed: {
...mapState([ 'ajaxNetworkException' ]),
...mapState(['ajaxNetworkException']),
},
watch: {
ajaxNetworkException: {
handler(v) {
this.show = v;
if (v) {
this.checkNetwork();
}
},
immediate: true
}
}
},
};
methods: {
isNotServer() {
let apiHome = $A.getDomain(window.systemInfo.apiUrl)
return this.$isSoftware && (apiHome == "" || apiHome == "public")
},
checkNetwork() {
this.__timer && clearTimeout(this.__timer);
this.__timer = setTimeout(() => {
if (!this.ajaxNetworkException) {
return; //
}
if (this.isNotServer()) {
return; //
}
this.$store.dispatch("call", {
url: "system/setting",
}).finally(() => {
this.checkNetwork();
});
}, 3000);
}
}
}
</script>

View File

@ -216,14 +216,6 @@ export default {
}
params.error = (xhr, status) => {
const networkException = window.navigator.onLine === false || (status === 0 && xhr.readyState === 4)
if (networkException && cloneParams.__networkFailureRetry !== true) {
// 网络异常,重试一次
setTimeout(_ => {
cloneParams.__networkFailureRetry = true
dispatch("call", cloneParams).then(resolve).catch(reject)
}, 1000)
return
}
if (params.checkNetwork !== false) {
state.ajaxNetworkException = networkException
}