From 5c945c891e3242ef70e3940254465d3aac0b96f3 Mon Sep 17 00:00:00 2001 From: Kinplemelon Date: Mon, 1 Nov 2021 18:16:36 +0800 Subject: [PATCH] fix(status bar): polling status after restartnew to solve statue data error --- .../HeaderRight/components/ControlGroup.vue | 1 + src/components/core/MainLayout/index.vue | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/components/core/MainLayout/components/HeaderRight/components/ControlGroup.vue b/src/components/core/MainLayout/components/HeaderRight/components/ControlGroup.vue index bc68f3ed..f5ab8b14 100644 --- a/src/components/core/MainLayout/components/HeaderRight/components/ControlGroup.vue +++ b/src/components/core/MainLayout/components/HeaderRight/components/ControlGroup.vue @@ -152,6 +152,7 @@ export default { duration: 8000, }) setTimeout(() => { + window.localStorage.setItem('restartnewTimestamp', Date.now()) window.location.reload() }, 8000) }) diff --git a/src/components/core/MainLayout/index.vue b/src/components/core/MainLayout/index.vue index 02d47ce4..2ddfa443 100644 --- a/src/components/core/MainLayout/index.vue +++ b/src/components/core/MainLayout/index.vue @@ -43,6 +43,7 @@ export default { theme: 'default', collapse: false, loadData: false, + pollingStatusTimer: undefined, } }, computed: { @@ -55,6 +56,7 @@ export default { }, mounted() { this.initData() + this.checkRestartnewTimestampNHandle() }, methods: { ...mapMutations(['setAllData', 'setAlarmStatus', 'setNorthDriverList', 'setSouthDriverList']), @@ -106,6 +108,44 @@ export default { EmqxMessage.error(data.emsg) } }, + refreshStatus() { + getData(this.nodeId, { + func: 61, + actn: 'act_en', + wtrm: 'neuron', + }).then((res) => { + const { data } = res + if (!data.func && data.tstp) { + this.setAlarmStatus(data) + } + }) + }, + pollingStatus() { + if (this.pollingStatusTimer) { + window.clearInterval(this.pollingStatusTimer) + } + this.pollingStatusTimer = window.setInterval(() => { + this.refreshStatus() + }, 2000) + window.setTimeout(() => { + window.clearInterval(this.pollingStatusTimer) + }, 2000 * 30 * 2) + }, + /** + * After the restart, poll the status data for two minutes to solve + * the status data display error caused by the restart still in progress + * when the status data is obtained after the restart. + */ + checkRestartnewTimestampNHandle() { + const restartnewTimestamp = window.localStorage.getItem('restartnewTimestamp') + if ( + restartnewTimestamp && + !Number.isNaN(Number(restartnewTimestamp)) && + Date.now() - Number(restartnewTimestamp) < 10 * 1000 + ) { + this.pollingStatus() + } + }, }, }