Browse Source

fix 空调开关

anxiaoxia 2 years ago
parent
commit
efe201b6c4
1 changed files with 12 additions and 8 deletions
  1. 12 8
      src/pages/Equipment/components/deviceModal/airEq/index.jsx

+ 12 - 8
src/pages/Equipment/components/deviceModal/airEq/index.jsx

@@ -58,10 +58,17 @@ export default ({ spaceId, projectId }) => {
     }
   };
 
+  function timerGetAirInfo(timeLong) {
+    clearInterval(timer.current);
+    timer.current = setInterval(() => {
+      getAirInfo(); // 获取空调状态
+    }, timeLong);
+  }
+
   function changeSwitch(val) {
     const itemIdSum = val ? 12 : 10; // 10关闭 12开启
+    clearInterval(timer.current);
     changeAir(itemIdSum);
-    setIsOpen(val);
   }
 
   const getAirInfo = () => {
@@ -86,9 +93,8 @@ export default ({ spaceId, projectId }) => {
     changeAirHttp(paramsObj).then((res) => {
       if (res.result == 'success') {
         message.success('指令下发成功');
-        setTimeout(() => {
-          getAirInfo();
-        }, 500);
+        getAirInfo();
+        timerGetAirInfo(3000);
       } else {
         message.error('操作失败,请重试');
       }
@@ -97,11 +103,9 @@ export default ({ spaceId, projectId }) => {
 
   useEffect(() => {
     getAirInfo(); // 获取空调状态
-    timer = setInterval(() => {
-      getAirInfo(); // 获取空调状态
-    }, 1000);
+    timerGetAirInfo(3000);
     return () => {
-      clearInterval(timer);
+      clearInterval(timer.current);
     };
   }, []);