浏览代码

设备管理导航条显示

zhaojijng 2 年之前
父节点
当前提交
4154d615b6
共有 3 个文件被更改,包括 28 次插入39 次删除
  1. 1 1
      src/models/sagacare_spaceFunc.ts
  2. 2 7
      src/pages/Equipment/components/topNavRight/index.tsx
  3. 25 31
      src/pages/Equipment/index.tsx

+ 1 - 1
src/models/sagacare_spaceFunc.ts

@@ -63,7 +63,7 @@ export default function () {
   const [hasPersonList, setHasPersonList] = useState<any[]>([]);
 
   const querySpaceAdjustList = useCallback((selFloorId) => {
-    return getSpaceAdjustArray({ floorId: selFloorId }, {}).then(function (res) {
+    return getSpaceAdjustArray({ floorId: selFloorId }).then(function (res) {
       var resList = res.data || [];
       setHasPersonList(resList);
       return 'next';

+ 2 - 7
src/pages/Equipment/components/topNavRight/index.tsx

@@ -14,15 +14,10 @@ export type topNavRightProps = {
   selNavObj: navigatorItem;
   navigatorList: navigatorItem[];
   mapList: API.MapInfo[];
-  queryDeviceManage: () => Promise<any>;
+  //queryDeviceManage: () => Promise<any>;
 };
 
-const TopNavRight: React.FC<topNavRightProps> = ({
-  selNavObj,
-  navigatorList,
-  mapList,
-  queryDeviceManage,
-}) => {
+const TopNavRight: React.FC<topNavRightProps> = ({ selNavObj, navigatorList, mapList }) => {
   //const [modalvisible, setModalvisible] = useState<boolean>(false);
   //去掉全部设备的 设备列表
   const [deviceList, setDeviceList] = useState<navigatorItem[]>([]);

+ 25 - 31
src/pages/Equipment/index.tsx

@@ -123,6 +123,7 @@ const Environment: React.FC = () => {
   //根据设备状态返回不同的 颜色
   const getColorOpacity = (value: any, type?: string): string => {
     let colorStr = '';
+    // console.log('getColorOpacity-selNav', selNav, navigatorList);
     if (selNav.id == 'all') {
       //全部设备时 colorStr赋值
       var filterRes = navigatorList.filter(function (item) {
@@ -216,7 +217,6 @@ const Environment: React.FC = () => {
   };
   //获取地图 mapList
   useEffect(() => {
-    getProjectEquipType();
     if (selFloorId) {
       changeLastFloorId(selFloorId);
       setLoading(true);
@@ -288,7 +288,7 @@ const Environment: React.FC = () => {
     [mapListCopy],
   );
 
-  const queryDeviceManage = () => {
+  const queryDeviceManage = (equiptTypeArr: any) => {
     //setLoading(true);
     return queryEquipStatistics({
       floorId: selFloorId,
@@ -300,13 +300,14 @@ const Environment: React.FC = () => {
         var statistics = res.data.statistics || [];
         //赋值 运行中的设备数量
 
-        navigatorList.forEach(function (nItem) {
+        equiptTypeArr.forEach(function (nItem) {
           var fres = statistics.filter((sItem: statistics) => {
             return sItem.equipType == nItem.id;
           });
           nItem.num = (fres[0] || {}).runCount;
         });
-        setNavigatorList(navigatorList);
+        //console.log('queryDeviceManage333-arr', equiptTypeArr);
+        setNavigatorList(equiptTypeArr);
         //设备空间信息
         var spaceList = res.data.spaceList || [];
         spaceList.forEach((item: any) => {
@@ -343,17 +344,19 @@ const Environment: React.FC = () => {
         return 'next';
       })
       .catch(() => {
+        setNavigatorList(equiptTypeArr);
         // setLoading(false);
       });
   };
+
   let setTimer1 = useRef();
   let setTimer2 = useRef();
 
-  async function getDeviceStatus() {
-    await queryDeviceManage().then((res) => {
+  function getDeviceStatus(equiptTypeArr: any) {
+    queryDeviceManage(equiptTypeArr).then((res) => {
       clearTimeout(setTimer1.current);
       setTimer1.current = setTimeout(() => {
-        getDeviceStatus();
+        getDeviceStatus(equiptTypeArr);
       }, 8000);
     });
   }
@@ -378,7 +381,9 @@ const Environment: React.FC = () => {
           arr.push(item);
         }
       });
-      setNavigatorList(arr);
+      //console.log('setNavigatorList-arr1111', arr);
+      //setNavigatorList(arr);
+      return arr;
     });
   }
 
@@ -386,6 +391,7 @@ const Environment: React.FC = () => {
     //获取有人无人
     querySpaceAdjustList(sfId).then((res) => {
       //debugger;
+      clearTimeout(setTimer2.current);
       setTimer2.current = setTimeout(() => {
         getSpaceHasPerson(sfId);
       }, 8000);
@@ -393,34 +399,23 @@ const Environment: React.FC = () => {
   }
   //获取设备状态 设备种类
   useEffect(() => {
-    if (selFloorId) {
-      getDeviceStatus();
-      getSpaceHasPerson(selFloorId);
-
-      //   queryDeviceManage(); //第一次执行
-      //   if (setTimer.current) {
-      //     clearInterval(setTimer.current);
-      //     setTimer.current = null;
-      //   }
-      //   //循环调接口
-      //   setTimer.current = setInterval(() => {
-      //     queryDeviceManage();
-      //   }, 3000);
-    }
+    (async function () {
+      var equiptTypeArr = await getProjectEquipType();
+      //console.log('getProjectEquipType222-equiptTypeArr', equiptTypeArr);
+      if (selFloorId) {
+        getDeviceStatus(equiptTypeArr);
+        getSpaceHasPerson(selFloorId);
+      }
+    })();
 
     return () => {
       //clearInterval(setTimer.current);
+      console.log('clearTimeout-clear');
       clearTimeout(setTimer1.current);
       clearTimeout(setTimer2.current);
     };
   }, [selFloorId]);
 
-  //   useEffect(() => {
-  //     if (selFloorId) {
-  //       querySpaceAdjustList(selFloorId);
-  //     }
-  //   }, [selFloorId]);
-
   //获取时间列表 spaceTimeList
   useEffect(() => {
     if (selFloorId) {
@@ -465,7 +460,7 @@ const Environment: React.FC = () => {
   let firtTime: number = 0;
   let lastTime: number = 0;
   return (
-    <>
+    <div className={styles.sagawrap}>
       <PageHeader title={<FormattedMessage id="menu.equipment" />} action={<SearchInput />} />
       <TopNavigator
         navigatorList={navigatorList}
@@ -477,7 +472,6 @@ const Environment: React.FC = () => {
               selNavObj={selNav}
               navigatorList={navigatorList}
               mapList={mapCombineList}
-              queryDeviceManage={queryDeviceManage}
             ></TopNavRight>
           )
         }
@@ -753,7 +747,7 @@ const Environment: React.FC = () => {
           }}
         ></DeviceModal>
       )}
-    </>
+    </div>
   );
 };