量测:关闭页面时清除定时器

This commit is contained in:
高云鹏 2024-10-25 15:49:54 +08:00
parent e723ce4d93
commit 06bc07bfcd

View File

@ -155,10 +155,10 @@ const getCompleteData = () => {
return getRealValueList({ deviceId: props.deviceId, attributes: codeList }, data)
})
.then((realData: any) => {
console.log(realData);
console.log(realData)
const data = realData.list.map((item: any) => {
const realValItem = realData.realVal[props.deviceId]?.[item.attributeCode?.toLowerCase()]
const realValItem = realData.realVal[props.deviceId]?.[item.attributeCode?.toLowerCase()]
return {
...item,
realTimeValue: realValItem ? (realValItem % 1 === 0 ? realValItem : realValItem.toFixed(3)) : '-',
@ -207,25 +207,30 @@ const openChart = (data: any) => {}
watch(
() => props.show,
(newVal) => {
newVal && getCompleteData()
if (newVal) {
getCompleteData()
} else {
autoUpdateTimer.value && clearInterval(autoUpdateTimer.value)
autoUpdateTimer.value = null
}
},
{
immediate: true,
}
)
let autoUpdateTimer: any = null
const autoUpdateTimer: any = ref(null)
watch(
() => props.autoUpdate,
(newVal) => {
if (newVal) {
if (!autoUpdateTimer) {
autoUpdateTimer = setInterval(() => {
if (!autoUpdateTimer.value) {
autoUpdateTimer.value = setInterval(() => {
getCompleteData()
}, 2000)
}
} else {
clearInterval(autoUpdateTimer)
autoUpdateTimer = null
clearInterval(autoUpdateTimer.value)
autoUpdateTimer.value = null
}
}
)