Browse Source

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

zhaojijng 2 years ago
parent
commit
51dec64974
1 changed files with 15 additions and 10 deletions
  1. 15 10
      src/pages/Equipment/components/deviceModal/airEq/index.jsx

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

@@ -21,7 +21,7 @@ export default ({ spaceId, projectId }) => {
   const hasAir = true;
   const [isOpen, setIsOpen] = useState(true);
   const [imgSrc, setImgSrc] = useState(null);
-  const timer = useRef(null);
+  let timer = useRef(null);
   const [spaceStatus, setStatusText] = useState('null');
   const airExpend = [
     {
@@ -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('操作失败,请重试');
       }
@@ -96,12 +102,11 @@ export default ({ spaceId, projectId }) => {
   };
 
   useEffect(() => {
-    // timer = setInterval(() => {
     getAirInfo(); // 获取空调状态
-    // }, 1000);
-    // return () => {
-    //   clearInterval(timer);
-    // };
+    timerGetAirInfo(3000);
+    return () => {
+      clearInterval(timer.current);
+    };
   }, []);
 
   const AirExpend = () => {