mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 04:32:49 +00:00
perf: 优化网络检查
This commit is contained in:
parent
c61815db3a
commit
cda2d0da27
@ -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>
|
||||
|
||||
8
resources/assets/js/store/actions.js
vendored
8
resources/assets/js/store/actions.js
vendored
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user