Skip to content

Commit

Permalink
fix(status bar): polling status after restartnew to solve status data…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
Kinplemelon authored and ysfscream committed Nov 1, 2021
1 parent 816bda2 commit fe27b66
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default {
...mapGetters(['res', 'deviceObj']),
...mapState({
// FIXME: add to state
status: state => state?.Status?.status,
status: (state) => state?.Status?.status,
}),
active() {
const srt = this.status?.mode || ''
Expand All @@ -52,7 +52,7 @@ export default {
stat: 'active',
wtrm: 'neruon',
})
.then(res => {
.then((res) => {
this.starting = false
if (res.data.errc !== 0) {
EmqxMessage.error(res.data.emsg)
Expand All @@ -74,7 +74,7 @@ export default {
stat: 'standby',
wtrm: 'neruon',
})
.then(res => {
.then((res) => {
this.stoping = false
if (res.data.errc !== 0) {
EmqxMessage.error(res.data.emsg)
Expand Down Expand Up @@ -120,13 +120,13 @@ export default {
if (data.chdv) {
delete data.chdv
}
data.objd.forEach(i => {
data.objd.forEach((i) => {
if (i.preAndSuff) delete i.preAndSuff
})
data.wtrm = 'neuron'
data.func = 21
postData(this.nodeId, data)
.then(res => {
.then((res) => {
this.handleSuccess(res.data)
})
.catch(() => {
Expand All @@ -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 fe27b66

Please sign in to comment.