anxiaoxia 2 years ago
parent
commit
f1d1c11f5d

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

@@ -58,23 +58,9 @@ export default ({ spaceId, projectId }) => {
     }
   };
 
-  function changeSwitch(val) {
-    const itemIdSum = val ? 12 : 10; // 10关闭 12开启
+  const changeSwitch = () => {
+    const itemIdSum = !isOpen ? 12 : 10; // 10关闭 12开启
     changeAir(itemIdSum);
-    setIsOpen(val);
-  }
-
-  const getAirInfo = () => {
-    const paramsObj = {
-      objectId: spaceId,
-      projectId: projectId,
-    };
-    getFeedbackDocumentsHttp(paramsObj).then((res) => {
-      const val = res.icon == 7 ? false : true;
-      setIsOpen(val); // 开关
-      setStatusText(res.spaceStatus); // 状态文案
-      statusImg(res.icon); // icon
-    });
   };
 
   const changeAir = (itemId) => {
@@ -96,13 +82,27 @@ export default ({ spaceId, projectId }) => {
     });
   };
 
+  const getAirInfo = () => {
+    const paramsObj = {
+      objectId: spaceId,
+      projectId: projectId,
+    };
+    getFeedbackDocumentsHttp(paramsObj).then((res) => {
+      const val = res.icon == 7 ? false : true;
+      setIsOpen(val); // 开关
+      setStatusText(res.spaceStatus); // 状态文案
+      statusImg(res.icon); // icon
+    });
+  };
+
   useEffect(() => {
-    // timer = setInterval(() => {
-    getAirInfo(); // 获取空调状态
-    // }, 1000);
-    // return () => {
-    //   clearInterval(timer);
-    // };
+    getAirInfo();
+    timer.current = setInterval(() => {
+      getAirInfo(); // 获取空调状态
+    }, 1000);
+    return () => {
+      clearInterval(timer.current);
+    };
   }, []);
 
   const AirExpend = () => {
@@ -152,8 +152,8 @@ export default ({ spaceId, projectId }) => {
           <div className={styles.envRight}>
             <img className={styles.roomAirImg} src={isOpen ? airOpen : airClose} />
           </div>
-          <div className={commonStyles.eqBtn}>
-            <AnSwitch isOpen={isOpen} changeSwitch={changeSwitch} />
+          <div className={commonStyles.eqBtn} onClick={changeSwitch}>
+            <AnSwitch isOpen={isOpen} />
           </div>
         </div>
       </div>

+ 6 - 6
src/pages/Equipment/components/deviceModal/lampEq/index.jsx

@@ -43,12 +43,12 @@ export default ({ spaceId }) => {
 
   useEffect(() => {
     getLamp();
-    // startLightsStatusTimer.current = setInterval(() => {
-    //   getLamp(); // 灯设备状态
-    // }, 1000);
-    // return () => {
-    //   clearInterval(startLightsStatusTimer.current);
-    // };
+    startLightsStatusTimer.current = setInterval(() => {
+      getLamp(); // 灯设备状态
+    }, 1000);
+    return () => {
+      clearInterval(startLightsStatusTimer.current);
+    };
   }, []);
 
   const [flagSvg, setFlagSvg] = useState(false);