Skip to content

Commit

Permalink
fix(status bar): polling status after restartnew to solve statue data…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
Kinplemelon authored and ysfscream committed Nov 2, 2021
1 parent 4dff1b4 commit 5c945c8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default {
duration: 8000,
})
setTimeout(() => {
window.localStorage.setItem('restartnewTimestamp', Date.now())
window.location.reload()
}, 8000)
})
Expand Down
40 changes: 40 additions & 0 deletions src/components/core/MainLayout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default {
theme: 'default',
collapse: false,
loadData: false,
pollingStatusTimer: undefined,
}
},
computed: {
Expand All @@ -55,6 +56,7 @@ export default {
},
mounted() {
this.initData()
this.checkRestartnewTimestampNHandle()
},
methods: {
...mapMutations(['setAllData', 'setAlarmStatus', 'setNorthDriverList', 'setSouthDriverList']),
Expand Down Expand Up @@ -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()
}
},
},
}
</script>
Expand Down

0 comments on commit 5c945c8

Please sign in to comment.