mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 11:13:26 +00:00
perf: 优化客户端生命周期重连ws机制
This commit is contained in:
parent
6a2f1f80f5
commit
2ab12f74ee
@ -33,6 +33,7 @@ export default {
|
|||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.electronEvents();
|
this.electronEvents();
|
||||||
|
this.eeuiEvents();
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -82,7 +83,7 @@ export default {
|
|||||||
handler() {
|
handler() {
|
||||||
this.$store.dispatch("websocketConnection");
|
this.$store.dispatch("websocketConnection");
|
||||||
//
|
//
|
||||||
if (this.$isEEUiApp) {
|
if (this.$isEEUiApp && this.userId > 0) {
|
||||||
setTimeout(_ => {
|
setTimeout(_ => {
|
||||||
const webview = requireModuleJs("webview");
|
const webview = requireModuleJs("webview");
|
||||||
webview && webview.sendMessage({
|
webview && webview.sendMessage({
|
||||||
@ -220,6 +221,22 @@ export default {
|
|||||||
this.$store.dispatch(action, data);
|
this.$store.dispatch(action, data);
|
||||||
})
|
})
|
||||||
this.manifestUrl = $A.apiUrl("../manifest")
|
this.manifestUrl = $A.apiUrl("../manifest")
|
||||||
|
},
|
||||||
|
|
||||||
|
eeuiEvents() {
|
||||||
|
if (!this.$isEEUiApp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 页面失活
|
||||||
|
window.__onPagePause = () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
// 页面激活
|
||||||
|
window.__onPageResume = (num) => {
|
||||||
|
if (num > 0) {
|
||||||
|
this.$store.state.ws === null && this.$store.dispatch("websocketConnection");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
resources/assets/js/store/actions.js
vendored
8
resources/assets/js/store/actions.js
vendored
@ -2201,11 +2201,11 @@ export default {
|
|||||||
*/
|
*/
|
||||||
websocketConnection({state, dispatch, commit}) {
|
websocketConnection({state, dispatch, commit}) {
|
||||||
clearTimeout(state.wsTimeout);
|
clearTimeout(state.wsTimeout);
|
||||||
|
if (state.ws) {
|
||||||
|
state.ws.close();
|
||||||
|
state.ws = null;
|
||||||
|
}
|
||||||
if (state.userId === 0) {
|
if (state.userId === 0) {
|
||||||
if (state.ws) {
|
|
||||||
state.ws.close();
|
|
||||||
state.ws = null;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user