优化websocket重连后的逻辑
This commit is contained in:
parent
ac26713f86
commit
59b98209ac
@ -16,6 +16,7 @@ import axios from "axios";
|
||||
Vue.component('MarkdownPreview', MarkdownPreview)
|
||||
|
||||
import {Store} from "le5le-store";
|
||||
import {mapState} from "vuex";
|
||||
|
||||
export default {
|
||||
name: 'AppDown',
|
||||
@ -27,14 +28,13 @@ export default {
|
||||
repoData: {},
|
||||
|
||||
status: 0, // 0 没有,1有客户端,2客户端有新版本
|
||||
downInfo: {},
|
||||
releases: {},
|
||||
releaseTimeout: null,
|
||||
|
||||
websocketOpenSubscribe: null
|
||||
downInfo: {},
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getReleases();
|
||||
//
|
||||
if (this.$Electron) {
|
||||
this.$Electron.ipcRenderer.on('downloadDone', (event, args) => {
|
||||
if (args.name == this.repoData.name) {
|
||||
@ -43,17 +43,11 @@ export default {
|
||||
}
|
||||
})
|
||||
}
|
||||
//
|
||||
this.getReleases();
|
||||
this.websocketOpenSubscribe = Store.subscribe('websocketOpen', this.getReleaseBefore);
|
||||
},
|
||||
destroyed() {
|
||||
if (this.websocketOpenSubscribe) {
|
||||
this.websocketOpenSubscribe.unsubscribe();
|
||||
this.websocketOpenSubscribe = null;
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState([
|
||||
'wsOpenNum',
|
||||
]),
|
||||
repoTitle() {
|
||||
return this.status == 2 ? '更新客户端' : '客户端下载';
|
||||
},
|
||||
@ -61,6 +55,13 @@ export default {
|
||||
return this.status && !this.$store.state.windowMax768 && ['login', 'manage-dashboard'].includes(this.$route.name)
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
wsOpenNum(num) {
|
||||
if (num <= 1) return
|
||||
this.wsOpenTimeout && clearTimeout(this.wsOpenTimeout)
|
||||
this.wsOpenTimeout = setTimeout(this.getReleases, 5000)
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
compareVersion(version1, version2) {
|
||||
let pA = 0, pB = 0;
|
||||
@ -106,11 +107,6 @@ export default {
|
||||
return 0;
|
||||
},
|
||||
|
||||
getReleaseBefore() {
|
||||
clearTimeout(this.releaseTimeout)
|
||||
this.releaseTimeout = setTimeout(this.getReleases, 5000)
|
||||
},
|
||||
|
||||
getReleases() {
|
||||
if (this.status > 0) {
|
||||
return;
|
||||
|
@ -231,10 +231,6 @@ export default {
|
||||
|
||||
dialogMsgSubscribe: null,
|
||||
|
||||
refreshTimeout: null,
|
||||
|
||||
websocketOpenSubscribe: null,
|
||||
|
||||
columns: [],
|
||||
|
||||
projectKeyValue: '',
|
||||
@ -270,7 +266,6 @@ export default {
|
||||
//
|
||||
this.addTaskSubscribe = Store.subscribe('addTask', this.onAddTask);
|
||||
this.dialogMsgSubscribe = Store.subscribe('dialogMsgPush', this.addDialogMsg);
|
||||
this.websocketOpenSubscribe = Store.subscribe('websocketOpen', this.refreshBasic);
|
||||
//
|
||||
document.addEventListener('keydown', this.shortcutEvent);
|
||||
window.addEventListener('resize', this.innerHeightListener);
|
||||
@ -289,10 +284,6 @@ export default {
|
||||
this.dialogMsgSubscribe.unsubscribe();
|
||||
this.dialogMsgSubscribe = null;
|
||||
}
|
||||
if (this.websocketOpenSubscribe) {
|
||||
this.websocketOpenSubscribe.unsubscribe();
|
||||
this.websocketOpenSubscribe = null;
|
||||
}
|
||||
//
|
||||
document.removeEventListener('keydown', this.shortcutEvent);
|
||||
window.removeEventListener('resize', this.innerHeightListener);
|
||||
@ -311,6 +302,7 @@ export default {
|
||||
'cacheProjects',
|
||||
'projectTotal',
|
||||
'taskId',
|
||||
'wsOpenNum'
|
||||
]),
|
||||
|
||||
...mapGetters(['taskData', 'dashboardTask']),
|
||||
@ -421,6 +413,14 @@ export default {
|
||||
this.notificationClass.close();
|
||||
}, 6000);
|
||||
}
|
||||
},
|
||||
|
||||
wsOpenNum(num) {
|
||||
if (num <= 1) return
|
||||
this.wsOpenTimeout && clearTimeout(this.wsOpenTimeout)
|
||||
this.wsOpenTimeout = setTimeout(() => {
|
||||
this.$store.dispatch("getBasicData")
|
||||
}, 5000)
|
||||
}
|
||||
},
|
||||
|
||||
@ -624,15 +624,6 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
refreshBasic(num) {
|
||||
if (num > 1) {
|
||||
clearTimeout(this.refreshTimeout)
|
||||
this.refreshTimeout = setTimeout(() => {
|
||||
this.$store.dispatch("refreshBasicData")
|
||||
}, 5000)
|
||||
}
|
||||
},
|
||||
|
||||
notificationInit() {
|
||||
this.notificationClass = new notificationKoro(this.$L("打开通知成功"));
|
||||
if (this.notificationClass.support) {
|
||||
|
@ -88,7 +88,7 @@ export default {
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState(['userId', 'cacheTasks', 'taskCompleteTemps']),
|
||||
...mapState(['userId', 'cacheTasks', 'taskCompleteTemps', 'wsOpenNum']),
|
||||
|
||||
...mapGetters(['transforTasks']),
|
||||
|
||||
@ -167,6 +167,16 @@ export default {
|
||||
rangeTime(time) {
|
||||
this.getTask(time);
|
||||
},
|
||||
|
||||
wsOpenNum(num) {
|
||||
if (num <= 1) return
|
||||
this.wsOpenTimeout && clearTimeout(this.wsOpenTimeout)
|
||||
this.wsOpenTimeout = setTimeout(() => {
|
||||
if (this.$route.name == 'manage-calendar') {
|
||||
this.setRenderRange();
|
||||
}
|
||||
}, 5000)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
@ -430,7 +430,7 @@ export default {
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState(['userId', 'userToken', 'userIsAdmin', 'userInfo', 'files']),
|
||||
...mapState(['userId', 'userToken', 'userIsAdmin', 'userInfo', 'files', 'wsOpenNum']),
|
||||
|
||||
actionUrl() {
|
||||
return $A.apiUrl('file/content/upload?pid=' + this.pid)
|
||||
@ -507,6 +507,16 @@ export default {
|
||||
this.getFileList();
|
||||
}
|
||||
},
|
||||
|
||||
wsOpenNum(num) {
|
||||
if (num <= 1) return
|
||||
this.wsOpenTimeout && clearTimeout(this.wsOpenTimeout)
|
||||
this.wsOpenTimeout = setTimeout(() => {
|
||||
if (this.$route.name == 'manage-file') {
|
||||
this.getFileList();
|
||||
}
|
||||
}, 5000)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
@ -18,7 +18,7 @@ export default {
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.project_id = this.$route.params.id;
|
||||
this.project_id = $A.runNum(this.$route.params.id);
|
||||
},
|
||||
|
||||
deactivated() {
|
||||
@ -26,38 +26,55 @@ export default {
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState(['cacheProjects']),
|
||||
...mapState(['cacheProjects', 'wsOpenNum']),
|
||||
...mapGetters(['projectParameter']),
|
||||
},
|
||||
|
||||
watch: {
|
||||
'$route' (route) {
|
||||
this.project_id = route.params.id;
|
||||
'$route' ({params}) {
|
||||
this.project_id = $A.runNum(params.id);
|
||||
},
|
||||
project_id(id) {
|
||||
if (id > 0) {
|
||||
setTimeout(() => {
|
||||
this.$store.state.projectId = $A.runNum(id);
|
||||
this.$store.dispatch("getProjectOne", id).then(() => {
|
||||
this.$store.dispatch("getColumns", id);
|
||||
this.$store.dispatch("getTaskForProject", id);
|
||||
}).catch(({msg}) => {
|
||||
$A.modalWarning({
|
||||
content: msg,
|
||||
onOk: () => {
|
||||
const project = this.cacheProjects.find(({id}) => id);
|
||||
if (project) {
|
||||
$A.goForward({path: '/manage/project/' + project.id});
|
||||
} else {
|
||||
$A.goForward({path: '/manage/dashboard'});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
this.$store.dispatch("forgetTaskCompleteTemp", true);
|
||||
});
|
||||
}
|
||||
|
||||
project_id() {
|
||||
this.getProjectData();
|
||||
},
|
||||
|
||||
wsOpenNum(num) {
|
||||
if (num <= 1) return
|
||||
this.wsOpenTimeout && clearTimeout(this.wsOpenTimeout)
|
||||
this.wsOpenTimeout = setTimeout(() => {
|
||||
if (this.$route.name == 'manage-project') {
|
||||
this.getProjectData();
|
||||
}
|
||||
}, 5000)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
getProjectData() {
|
||||
let id = this.project_id;
|
||||
if (id <= 0) return;
|
||||
setTimeout(() => {
|
||||
this.$store.state.projectId = $A.runNum(id);
|
||||
this.$store.dispatch("getProjectOne", id).then(() => {
|
||||
this.$store.dispatch("getColumns", id);
|
||||
this.$store.dispatch("getTaskForProject", id);
|
||||
}).catch(({msg}) => {
|
||||
$A.modalWarning({
|
||||
content: msg,
|
||||
onOk: () => {
|
||||
const project = this.cacheProjects.find(({id}) => id);
|
||||
if (project) {
|
||||
$A.goForward({path: '/manage/project/' + project.id});
|
||||
} else {
|
||||
$A.goForward({path: '/manage/dashboard'});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
this.$store.dispatch("forgetTaskCompleteTemp", true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
8
resources/assets/js/store/actions.js
vendored
8
resources/assets/js/store/actions.js
vendored
@ -167,10 +167,10 @@ export default {
|
||||
},
|
||||
|
||||
/**
|
||||
* 刷新基本数据(项目、对话、仪表盘任务)
|
||||
* 获取基本数据(项目、对话、仪表盘任务)
|
||||
* @param dispatch
|
||||
*/
|
||||
refreshBasicData({dispatch}) {
|
||||
getBasicData({dispatch}) {
|
||||
dispatch("getProjects");
|
||||
dispatch("getDialogs");
|
||||
dispatch("getTaskForDashboard");
|
||||
@ -212,7 +212,7 @@ export default {
|
||||
state.userToken = userInfo.token;
|
||||
state.userIsAdmin = $A.inArray('admin', userInfo.identity);
|
||||
$A.setStorage("userInfo", state.userInfo);
|
||||
dispatch("refreshBasicData");
|
||||
dispatch("getBasicData");
|
||||
dispatch("websocketConnection");
|
||||
resolve()
|
||||
});
|
||||
@ -1967,7 +1967,7 @@ export default {
|
||||
state.ws = new WebSocket(url);
|
||||
state.ws.onopen = (e) => {
|
||||
console.log("[WS] Open", $A.formatDate())
|
||||
Store.set('websocketOpen', ++state.wsOpenNum);
|
||||
state.wsOpenNum++;
|
||||
};
|
||||
state.ws.onclose = (e) => {
|
||||
console.log("[WS] Close", $A.formatDate())
|
||||
|
Loading…
x
Reference in New Issue
Block a user