anxiaoxia преди 2 години
родител
ревизия
b331342a8e

+ 1 - 1
config/proxy.ts

@@ -11,7 +11,7 @@ export default {
     // localhost:8000/api/** -> https://preview.pro.ant.design/api/**
     '/sgadmin/duoduo-service': {
       target: 'https://duoduoenv.sagacloud.cn/',
-      //target: 'http://10.100.28.79',
+      //   target: 'http://10.100.28.79',
       changeOrigin: true,
       pathRewrite: {
         '^/sgadmin/duoduo-service': '/duoduo-service',

+ 2 - 2
src/config/api.js

@@ -1,3 +1,3 @@
 export const BASE_PATH = '/api';
-export const projectId = 'Pj3301100002';
-  //const projectId = 'Pj1101080259';
+// export const projectId = 'Pj3301100002';
+export  const projectId = 'Pj1101080259';

+ 2 - 1
src/pages/Equipment/checLampStatus.js

@@ -62,8 +62,9 @@ export const judgeChangeResponeseSuccess = (response, paramsArr, fn) => {
 };
 
 //  开关
-export const setallLamps = (paramsArr, fn) => {
+export const setallLamps = (paramsArr, fn,waitSetResultFlag) => {
     setallLampHttp(paramsArr).then((res) => {
+        waitSetResultFlag.current = false
         judgeChangeResponeseSuccess(res, paramsArr, fn);
     });
 };

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

@@ -11,43 +11,46 @@ export default ({ spaceId }) => {
   const [isMore, setIsMore] = useState(false);
   const [isOpen, setIsOpen] = useState(false); // 12 开, 10关
   const [lampArr, setLampArr] = useState([]);
-  let startTime = null;
-  let endTime = null;
-  const startLightsStatusTimer = useRef(null);
-  const getLamp = () => {
-    getLampHttp(spaceId).then((res) => {
-      if (res.result != 'success') return;
-      const arr = res.content;
-      if (arr.length > 1) {
-        setIsMore(true);
-        let totalIsOpen = false;
-        arr.forEach((item) => {
-          if (item.runStatus) {
-            totalIsOpen = true;
-          }
-        });
-        setIsOpen(totalIsOpen);
-      } else {
-        arr.forEach((item) => {
-          if (item.runStatus) {
-            setIsOpen(true);
-          } else {
-            setIsOpen(false);
-          }
-        });
-      }
+  let startLightsStatusTimer = useRef(null);
+  let waitSetResultFlag = useRef(false); // 等待开关接口
+  const getLamp = useCallback(() => {
+    getLampHttp(spaceId).then(
+      (res) => {
+        clearTimeout(startLightsStatusTimer);
+        startLightsStatusTimer = setTimeout(() => {
+          getLamp(); // 灯设备状态
+        }, 3000);
+        if (res.result != 'success' && waitSetResultFlag.current) return;
+        const arr = res.content;
+        if (arr.length > 1) {
+          setIsMore(true);
+          let totalIsOpen = false;
+          arr.forEach((item) => {
+            if (item.runStatus) {
+              totalIsOpen = true;
+            }
+          });
+          setIsOpen(totalIsOpen);
+        } else {
+          arr.forEach((item) => {
+            if (item.runStatus) {
+              setIsOpen(true);
+            } else {
+              setIsOpen(false);
+            }
+          });
+        }
 
-      setLampArr(arr);
-    });
-  };
+        setLampArr(arr);
+      },
+      (e) => {},
+    );
+  }, [waitSetResultFlag]);
 
   useEffect(() => {
     getLamp();
-    startLightsStatusTimer.current = setInterval(() => {
-      getLamp(); // 灯设备状态
-    }, 1000);
     return () => {
-      clearInterval(startLightsStatusTimer.current);
+      clearTimeout(startLightsStatusTimer);
     };
   }, []);
 
@@ -59,15 +62,28 @@ export default ({ spaceId }) => {
     let paramsArr = [];
     if (type == 'total') {
       lampArr.forEach((item) => {
+        item.runStatus = val;
         paramsArr.push({
           id: item.id,
           switch: val,
         });
       });
     } else {
+      lampArr.forEach((item) => {
+        if (item.id == id) {
+          item.runStatus = val;
+        }
+      });
       paramsArr.push({ id: id, switch: val });
     }
-    setallLamps(paramsArr, getLamp);
+    lampArr.forEach((item) => {
+      if (item.runStatus) {
+        setIsOpen(item.runStatus); // 总开关
+      }
+    });
+    waitSetResultFlag.current = true;
+    setLampArr([...lampArr]);
+    setallLamps(paramsArr, getLamp, waitSetResultFlag);
   };
   return (
     <div className={commonStyles.box}>

+ 2 - 2
src/services/ant-design-pro/equipment.js

@@ -44,8 +44,8 @@ export const getObjectDataEqpGroupHttp = (params) => {
 // 灯的状态
 export const getLampHttp = (params) => {
     return request(`/sgadmin/duoduo-service/duoduoenv-service/light/status/query?${commonParams()}&spaceId=${params}`, {
-        isNotShowErrorToast: true,
-        errorSave: true,
+        timeout:1000, 
+        skipErrorHandler:true,
         method: 'GET',
         headers: {
             'Content-Type': 'application/json',