Browse Source

设备修改

zhaojijng 2 years ago
parent
commit
80a63fdbb4

+ 69 - 35
src/components/topNavigator/index.tsx

@@ -42,26 +42,40 @@ const TopNavigator: React.FC<topNavigatorProps> = ({
 
   const [floorList, setFloorList] = useState<floorItem[]>([]);
   const [currentFloor, setCurrentFloor] = useState<string>();
+
+  //const [shishi, setShishi] = useState<string>('22');
   //则监听searchBuildId的改变    如果buildingId改变 请求楼层列表
   useEffect(() => {
-    debugger;
-    if (searchBuildId) {
-      setCurrentBuild(searchBuildId);
-      // changeSearchBuildId('');
+    if (searchBuildId && searchFloorId) {
+      if (searchBuildId !== currentBuild) {
+        //如果buildId 改变
+        setCurrentBuild(searchBuildId);
+        debugger;
+      } else {
+        //显示
+        setCurrentFloor(searchFloorId);
+        //父亲的floorId
+        debugger;
+        //这块 其实只想楼层id改变时调用 建筑id 改变时不调用
+        changeFloorId && changeFloorId(searchFloorId);
+      }
+      changeSearchBuildId(''); //清空搜索记录  以防两次搜索一样的建筑的 没反应
+      changeSearchFloorId(''); //清空搜索记录 以防两次搜索一样的楼层时 没反应 要不要换位置
     }
-  }, [searchBuildId]);
+  }, [searchBuildId, searchFloorId]);
 
-  useEffect(() => {
-    debugger;
-    //如果 建筑id改变 不应该走着 todo
-    if (searchFloorId) {
-      //显示
-      setCurrentFloor(searchFloorId);
-      //父亲的floorId
-      changeFloorId && changeFloorId(searchFloorId);
-      // changeSearchFloorId('');
-    }
-  }, [searchFloorId]);
+  //   useEffect(() => {
+  //     //如果 建筑id改变 不应该走着 todo
+  //     if (searchFloorId) {
+  //       //显示
+  //       setCurrentFloor(searchFloorId);
+  //       //父亲的floorId
+  //       debugger;
+  //       //todo 这块 其实只想楼层id改变时调用 建筑id 改变时不调用
+  //       changeFloorId && changeFloorId(searchFloorId);
+  //       changeSearchFloorId(''); //清空搜索记录 以防两次搜索一样的楼层时 没反应 要不要换位置
+  //     }
+  //   }, [searchFloorId]);
 
   //请求建筑的接口
   useEffect(() => {
@@ -92,47 +106,67 @@ const TopNavigator: React.FC<topNavigatorProps> = ({
       changeBuildId && changeBuildId((resData[0] || {}).id);
     });
   }, []);
+
   //请求楼层列表的接口
   useEffect(() => {
     debugger;
-    if (currentBuild) {
-      getFloorList({
+    async function asyncFunction() {
+      var res = await getFloorList({
         criteria: {
           buildingId: currentBuild,
           //buildingId: 'Bd1101080259317347f00d0811ebb06b1d2749356f83',
         },
-      }).then((res) => {
-        var resData = res.content || [];
-        setFloorList(
-          (resData || []).map((item) => {
-            return { label: item.localName, value: item.id };
-          }),
-        );
-
-        //默认选中的楼层id
-        setTimeout(() => {
-          debugger;
-          setCurrentFloor(searchFloorId || (resData[0] || {}).id); //如果有搜索的楼层id 则用搜索的结果
-          changeFloorId && changeFloorId(searchFloorId || (resData[0] || {}).id); //改变父组件的floorId的值
-        }, 0);
       });
+      var resData = res.content || [];
+      setFloorList(
+        (resData || []).map((item) => {
+          return { label: item.localName, value: item.id };
+        }),
+      );
+
+      debugger;
+      setCurrentFloor(searchFloorId || (resData[0] || {}).id); //如果有搜索的楼层id 则用搜索的结果
+      changeFloorId && changeFloorId(searchFloorId || (resData[0] || {}).id); //改变父组件的floorId的值
+    }
+    if (currentBuild) {
+      asyncFunction();
     }
+
+    // if (currentBuild) {
+    //   getFloorList({
+    //     criteria: {
+    //       buildingId: currentBuild,
+    //       //buildingId: 'Bd1101080259317347f00d0811ebb06b1d2749356f83',
+    //     },
+    //   }).then((res) => {
+    //     var resData = res.content || [];
+    //     setFloorList(
+    //       (resData || []).map((item) => {
+    //         return { label: item.localName, value: item.id };
+    //       }),
+    //     );
+
+    //     debugger;
+    //     setCurrentFloor(searchFloorId || (resData[0] || {}).id); //如果有搜索的楼层id 则用搜索的结果
+    //     changeFloorId && changeFloorId(searchFloorId || (resData[0] || {}).id); //改变父组件的floorId的值
+    //   });
+    // }
   }, [currentBuild]);
 
   const changBuildHandle = useCallback((val) => {
     //console.log('select-onChange', val);
     debugger;
-    // changeSearchFloorId('');
+    //changeSearchFloorId('');
+    //setShishi('fsdf');
     //显示的建筑改变
     setCurrentBuild(val);
     //父亲的buildId改变
     changeBuildId && changeBuildId(val);
   }, []);
   const changFloorHandle = useCallback((val) => {
-    //console.log('select-onChange', val);
     //debugger;
     setCurrentFloor(val);
-    //console.log('changeFloorId', changeFloorId);
+
     changeFloorId && changeFloorId(val);
   }, []);
 

+ 5 - 4
src/models/buildFloor.ts

@@ -3,12 +3,13 @@ import React, { useState, useCallback } from 'react';
 export default function () {
   const [searchBuildId, setSearchBuildId] = useState<string>();
   const [searchFloorId, setSearchFloorId] = useState<string>();
-  const changeSearchBuildId = (value: string) => {
+  const changeSearchBuildId = useCallback((value: string) => {
     setSearchBuildId(value);
-  };
-  const changeSearchFloorId = (value: string) => {
+  }, []);
+  const changeSearchFloorId = useCallback((value: string) => {
     setSearchFloorId(value);
-  };
+  }, []);
+
   return {
     searchBuildId,
     searchFloorId,

+ 4 - 1
src/pages/Environment/index.tsx

@@ -155,6 +155,9 @@ const Environment: React.FC = () => {
         .catch(() => {
           setLoading(false);
         });
+    } else {
+      debugger;
+      setMapList([]);
     }
   }, [selFloorId]);
   //请求环境数据
@@ -216,7 +219,7 @@ const Environment: React.FC = () => {
           <SearchInput
             mapList={mapList}
             callbackSearch={(s) => {
-              setSelFloorId(s.floorId);
+              //setSelFloorId(s.floorId);
               setSearchText({ text: s.localName });
             }}
           />

+ 89 - 15
src/pages/Equipment/index.tsx

@@ -22,7 +22,8 @@ import {
   queryEquipStatistics,
   queryDeviceTimeManage,
 } from '@/services/ant-design-pro/environment';
-import { getFeedbackDocumentsHttp, changeAirHttp } from '@/services/ant-design-pro/equipment';
+import { changeAirHttp, setEquipeHttp } from '@/services/ant-design-pro/equipment';
+import { setallLamps } from '@/pages/Equipment/checLampStatus.js';
 
 //设备状态
 type equipStatus = {
@@ -116,20 +117,19 @@ const Environment: React.FC = () => {
     } else {
       colorStr = selNav.colorStr;
     }
-    if (value == 2) {
+    if (value === 2) {
       //2 是部分开启
       return 'rgba(' + colorStr + '0.4)';
-    } else if (value == 1) {
+    } else if (value === 1) {
       //1 是开启
       return 'rgba(' + colorStr + '1)';
-    } else {
+    } else if (value === 0) {
       //0是关闭
       return 'rgba(196, 196, 196, 0.6)';
     }
   };
   const { confirm } = Modal;
   //空调的调节      0是关闭 1 是开启  2 是部分开启
-  //这是存在疑惑 部分开启怎么办
   const changeAir = (sitem, index: number) => {
     const itemId = sitem.airConditioner === 0 ? 12 : 10; // 10关闭 12开启
     const paramsObj = {
@@ -150,11 +150,70 @@ const Environment: React.FC = () => {
       }
     });
   };
+  //窗帘的调节      0是关闭 1 是开启  2 是部分开启
+  const changeCurtain = (citem: any, index: number) => {
+    debugger;
+    const setType = citem.curtain === 1 ? 'EquipOffSet' : 'EquipOnSet'; // 10关闭 12开启
+    var paramsArr: any = [];
+    citem.equipList.forEach((item: any) => {
+      if (item.equipType == 'curtain') {
+        paramsArr.push({
+          equipmentCategory: 'CFSSES',
+          infoCode: setType,
+          value: 1,
+          objectId: item.id,
+        });
+      }
+    });
+    console.log(citem);
+    console.log(paramsArr);
 
+    //发送指令
+    setEquipeHttp(paramsArr);
+    //这是在手动改变状态
+    var mapCopy = JSON.parse(JSON.stringify(mapCombineList));
+    mapCopy[index]['curtain'] = citem.curtain === 1 ? 0 : 1;
+    setMapCombineList(mapCopy);
+  };
+  const changeSwitch = (citem: any, index: number) => {
+    const setType = citem.light === 1 ? false : true; // 10关闭 12开启
+    var paramsArr: any = [];
+    citem.equipList.forEach((item: any) => {
+      if (item.equipType == 'curtain') {
+        paramsArr.push({
+          id: item.id,
+          switch: setType,
+        });
+      }
+    });
+    function getLamp() {}
+    setallLamps(paramsArr, getLamp);
+  };
   //单个空间的点击事情
   const spaceControl = (item, index: number) => {
+    //全部设备 或者没有房间类型 则不可以点击
     if (selNav.id == 'all' || !item.roomFuncType) return;
-    var status = item[selNav.id] === 0 ? '打开' : '关闭';
+    //没有设备时
+    if (item[selNav.id] == 'not') return;
+    debugger;
+    if (item[selNav.id] === 2) {
+      confirm({
+        title: '请确认',
+        icon: <ExclamationCircleOutlined />,
+        content: `是否进入单空间进行调节?`,
+        okText: '确认',
+        cancelText: '取消',
+        onOk() {
+          debugger;
+          showModalClick(item);
+        },
+        onCancel() {
+          //console.log('Cancel');
+        },
+      });
+      return;
+    }
+    var status = item[selNav.id] === 1 ? '关闭' : '打开';
     confirm({
       title: '请确认',
       icon: <ExclamationCircleOutlined />,
@@ -169,6 +228,7 @@ const Environment: React.FC = () => {
         if (selNav.id == 'light') {
         }
         if (selNav.id == 'curtain') {
+          changeCurtain(item, index);
         }
         debugger;
       },
@@ -183,15 +243,18 @@ const Environment: React.FC = () => {
     if (selFloorId) {
       debugger;
       setLoading(true);
+
       getMapList({
         //floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454',
         floorId: selFloorId,
       })
         .then((res) => {
-          //debugger;
+          debugger;
           setLoading(false);
           var data: API.MapInfo[] = (res.data || {}).spaceList || [];
+
           setMapList(data);
+          //setSelNav(navigatorList[0]); //每当重新请求地图时 让选中导航的默认是第一个
         })
         .catch(() => {
           setLoading(false);
@@ -226,13 +289,21 @@ const Environment: React.FC = () => {
           //设备空间信息
           var spaceList = res.data.spaceList || [];
           spaceList.forEach((item: any) => {
+            // (item.equipStatusList || []).forEach((eItem: equipStatus) => {
+            //   //debugger;
+            //   item[eItem.equipType] = eItem.status;
+            // });
             //debugger;
-            (item.equipStatusList || []).forEach((eItem: equipStatus) => {
-              //debugger;
-              item[eItem.equipType] = eItem.status;
+            var allType = ['airConditioner', 'light', 'curtain'];
+            allType.forEach((etype) => {
+              var filterRes = (item.equipStatusList || []).filter((eItem: equipStatus) => {
+                return eItem.equipType == etype;
+              });
+              //不存时 赋值not
+              filterRes.length > 0 ? (item[etype] = filterRes[0].status) : (item[etype] = 'not');
             });
           });
-
+          //console.log('spaceList', spaceList);
           setEquipMapList(spaceList);
         })
         .catch(() => {
@@ -261,7 +332,7 @@ const Environment: React.FC = () => {
     }
   }, [selFloorId]);
 
-  //合并空间环境数据 和 空间数据
+  //合并空间设备数据 和 空间数据
   useEffect(() => {
     var combineList: any = [];
     mapList.map(function (mitem) {
@@ -364,7 +435,7 @@ const Environment: React.FC = () => {
                   }}
                   onClick={(event) => {
                     event.stopPropagation();
-                    if (lastTime - firtTime < 300) {
+                    if (lastTime - firtTime < 200) {
                       spaceControl(item, index);
                     }
                   }}
@@ -377,6 +448,9 @@ const Environment: React.FC = () => {
                     lastTime = new Date().getTime();
                   }}
                 >
+                  {selNav.id !== 'all' && item[selNav.id] == 'not' && (
+                    <div className={mapstyles.allDevice}>无设备</div>
+                  )}
                   {selNav.id == 'all' && (
                     <div className={mapstyles.allDevice}>
                       {/* 所有设备的图标列表 */}
@@ -404,7 +478,7 @@ const Environment: React.FC = () => {
                       className={mapstyles.showModal}
                       onClick={(event) => {
                         event.stopPropagation();
-                        if (lastTime - firtTime < 300) {
+                        if (lastTime - firtTime < 200) {
                           showModalClick(item);
                         }
                       }}
@@ -439,7 +513,7 @@ const Environment: React.FC = () => {
         <DeviceModal
           showSpace={showSpace}
           onClose={() => {
-            setShowModal(true);
+            setShowModal(false);
           }}
         ></DeviceModal>
       )}

+ 5 - 2
src/pages/Runtime/index.tsx

@@ -53,7 +53,8 @@ const Runtime: React.FC = () => {
     if (selFloorId) {
       setLoading(true);
       getMapList({
-        floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454',
+        floorId: selFloorId,
+        //floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454',
         projectId: '',
       })
         .then((res) => {
@@ -65,6 +66,8 @@ const Runtime: React.FC = () => {
         .catch(() => {
           setLoading(false);
         });
+    } else {
+      setMapList([]);
     }
   }, [selFloorId]);
 
@@ -151,7 +154,7 @@ const Runtime: React.FC = () => {
           <SearchInput
             mapList={mapList}
             callbackSearch={(s) => {
-              setSelFloorId(s.floorId);
+              // setSelFloorId(s.floorId);
               setSearchText({ text: s.localName });
             }}
           />