From 01b9e7244825cac11146e3961cafa6525dad56f1 Mon Sep 17 00:00:00 2001
From: web <candymxq888@outlook.com>
Date: 星期五, 25 四月 2025 17:24:33 +0800
Subject: [PATCH] fix:水温监控添加定时器

---
 src/views/screen/temperature/monitor/index.vue |   50 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/src/views/screen/temperature/monitor/index.vue b/src/views/screen/temperature/monitor/index.vue
index bdd961c..89bec41 100644
--- a/src/views/screen/temperature/monitor/index.vue
+++ b/src/views/screen/temperature/monitor/index.vue
@@ -1,5 +1,5 @@
 <script setup>
-import {ref, onMounted} from "vue";
+import {ref, onMounted, onUnmounted} from "vue";
 import {getUserType} from '@/utils/auth.js'
 import {setTempMonitor, getTempMonitorConfig, editTempMonitorConfig} from '@/api/screen/monitor/index.js'
 import {getTemperaturePointList} from '@/api/screen/index.js'
@@ -15,12 +15,17 @@
 const userType = ref(getUserType())
 const monitorRef = ref()
 const searchVal = ref('')
+let timer = null;
 
 // 选择菜单
 const handleSelectMenu = (id) => {
-    pointApi().get(id).then(res => {
-        monitorList.value = [res.data]
-    })
+    clearInterval(timer)
+    getMonitorList(id)
+}
+
+// 搜索
+const handleSearch = () => {
+    getMonitorList()
 }
 
 // 获取水温监控点菜单
@@ -31,8 +36,16 @@
 }
 
 // 获取监控点列表
-const getMonitorList = () => {
-    pointApi().search({type: 1, page: 1, limit: 100, keywords: searchVal.value}).then(res => {
+const getMonitorList = (id) => {
+    clearInterval(timer)
+    const data = {
+        type: 1,
+        page: 1,
+        limit: 100,
+        keywords: searchVal.value,
+        pointId: id || ''
+    }
+    pointApi().search(data).then(res => {
         //0-未报警, 1-下限报警, 2-上限报警
         monitorList.value = res.data.list.filter(el => el.parentId !== 0).map(item => {
             return {
@@ -41,22 +54,35 @@
             }
         })
     })
+
+    // 挂载定时器获取数据
+    timer = setInterval(() => {
+        pointApi().search(data).then(res => {
+            monitorList.value = res.data.list.filter(el => el.parentId !== 0).map(item => {
+                return {
+                    ...item,
+                    errorType: Number(item.waterTemperature) < Number(item.lowWaterLevel) ? 1 : Number(item.waterTemperature) > Number(item.tallWaterLevel) ? 2 : 0
+                }
+            })
+        })
+    }, 5000)
 }
 
-// 获取监控点参数
+// 获取监控点配置
 const getMonitorConfig = () => {
     getTempMonitorConfig().then(res => {
         monitorConfig.value = res.data
     })
 }
 
-// 设置监控点参数
+// 设置监控点配置
 const setMonitorConfig = () => {
     editTempMonitorConfig(monitorConfig.value).then(res => {
         ElMessage.success('设置成功')
     })
 }
 
+// 监控点参数设置
 const setMonitorData = (data) => {
     setTempMonitor(data).then(res => {
         if (res.code === 200) {
@@ -75,6 +101,12 @@
     getTempMonitor()
     getMonitorList()
     getMonitorConfig()
+})
+
+onUnmounted(() => {
+    if(timer) {
+        clearInterval(timer)
+    }
 })
 
 </script>
@@ -105,7 +137,7 @@
             <div class="monitor-tool">
                 <div class="tool-l">
                     <el-input v-model="searchVal" style="width: 20rem" placeholder="请输入监测点名称" clearable/>
-                    <el-button @click="getMonitorList">
+                    <el-button @click="handleSearch">
                         <el-icon>
                             <Search/>
                         </el-icon>

--
Gitblit v1.9.3