mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-05 00:47:05 +00:00
perf: 优化客户端生命周期重连ws机制
This commit is contained in:
parent
6a2f1f80f5
commit
2ab12f74ee
@ -33,6 +33,7 @@ export default {
|
||||
|
||||
created() {
|
||||
this.electronEvents();
|
||||
this.eeuiEvents();
|
||||
},
|
||||
|
||||
mounted() {
|
||||
@ -82,7 +83,7 @@ export default {
|
||||
handler() {
|
||||
this.$store.dispatch("websocketConnection");
|
||||
//
|
||||
if (this.$isEEUiApp) {
|
||||
if (this.$isEEUiApp && this.userId > 0) {
|
||||
setTimeout(_ => {
|
||||
const webview = requireModuleJs("webview");
|
||||
webview && webview.sendMessage({
|
||||
@ -220,6 +221,22 @@ export default {
|
||||
this.$store.dispatch(action, data);
|
||||
})
|
||||
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}) {
|
||||
clearTimeout(state.wsTimeout);
|
||||
if (state.ws) {
|
||||
state.ws.close();
|
||||
state.ws = null;
|
||||
}
|
||||
if (state.userId === 0) {
|
||||
if (state.ws) {
|
||||
state.ws.close();
|
||||
state.ws = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
//
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user