Browse Source

Merge branch 'master' of http://39.106.8.246:3003/sagacloud/sagacloud-manager-control

zhaojijng 2 years ago
parent
commit
c046456a47

+ 26 - 25
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) => {
@@ -90,18 +76,33 @@ export default ({ spaceId, projectId }) => {
           getAirInfo();
         }, 500);
       } else {
-        message.error('操作失败,请重试');
+        getAirInfo();
+        // message.error('操作失败,请重试');
       }
     });
   };
 
+  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 = () => {
@@ -151,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>

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

@@ -42,15 +42,17 @@ export default ({ spaceId }) => {
   };
 
   useEffect(() => {
-    // startLightsStatusTimer.current = setInterval(() => {
-    getLamp(); // 灯设备状态
-    // }, 1000);
-    // return clearInterval(startLightsStatusTimer.current);
+    getLamp();
+    startLightsStatusTimer.current = setInterval(() => {
+      getLamp(); // 灯设备状态
+    }, 1000);
+    return () => {
+      clearInterval(startLightsStatusTimer.current);
+    };
   }, []);
 
   const [flagSvg, setFlagSvg] = useState(false);
   function handleExpend() {
-    clearInterval(startLightsStatusTimer.current);
     setFlagSvg(!flagSvg);
   }
   const changeSwitch = (val, type, id) => {