Browse Source

设备接口调用

zhaojijng 3 years ago
parent
commit
e3987310d5

+ 9 - 9
config/proxy.ts

@@ -33,16 +33,16 @@ export default {
       changeOrigin: true,
       pathRewrite: { '^/api2': '' },
     },
-    '/api3/': {
-      // 要代理的地址
-      //target: 'http://api.sagacloud.cn/',
-      target: 'http://192.168.0.65:52015/',
+    // '/api3/': {
+    //   // 要代理的地址
+    //   //target: 'http://api.sagacloud.cn/',
+    //   target: 'http://192.168.0.65:52015/',
 
-      // 配置了这个可以从 http 代理到 https
-      // 依赖 origin 的功能可能需要这个,比如 cookie
-      changeOrigin: true,
-      pathRewrite: { '^/api3': '' },
-    },
+    //   // 配置了这个可以从 http 代理到 https
+    //   // 依赖 origin 的功能可能需要这个,比如 cookie
+    //   changeOrigin: true,
+    //   pathRewrite: { '^/api3': '' },
+    // },
     '/api4/': {
       // 要代理的地址
       //target: 'http://api.sagacloud.cn/',

+ 2 - 0
src/components/SearchInput/index.tsx

@@ -8,6 +8,8 @@ type mapResType = {
   text: string;
   value: string;
 };
+import { querySpace } from '@/services/ant-design-pro/environment';
+
 const { Option } = Select;
 
 type SearchInputProps = {

+ 2 - 2
src/components/map/index.tsx

@@ -19,7 +19,7 @@ const Map: React.FC<MapProps> = ({ type, searchText, selFloorId, render, mapList
   //   useEffect(() => {
   //     getMapListData(selFloorId);
   //   }, [selFloorId]);
-  console.log('map-shuxin');
+
   const [startPageX, setStartPageX] = useState<number>(0);
   const [startPageY, setStartPageY] = useState<number>(0);
 
@@ -89,7 +89,7 @@ const Map: React.FC<MapProps> = ({ type, searchText, selFloorId, render, mapList
     }
   }, [searchText]);
   useEffect(() => {
-    debugger;
+    //debugger;
   }, [mapList]);
 
   //   useEffect(() => {// todo 要不要用呢

+ 11 - 7
src/pages/Environment/index.tsx

@@ -141,18 +141,22 @@ const Environment: React.FC = () => {
   //获取地图 mapList
   useEffect(() => {
     if (selFloorId) {
-      getMapList({ floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454', projectId: '' }).then(
-        (res) => {
+      setLoading(true);
+      getMapList({ floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454', projectId: '' })
+        .then((res) => {
+          setLoading(false);
           var data: API.MapInfo[] = (res.data || {}).spaceList || [];
           setMapList(data);
-        },
-      );
+        })
+        .catch(() => {
+          setLoading(false);
+        });
     }
   }, [selFloorId]);
   //请求环境数据
   useEffect(() => {
     if (selNavId && selFloorId) {
-      setLoading(true);
+      //setLoading(true);
       var floorParams = [
         { id: 'Fl11010802593241ec348ecb4148806b9034c8957454', projectId: 'Pj1101080259' },
       ];
@@ -168,7 +172,7 @@ const Environment: React.FC = () => {
       })
         .then((res) => {
           //debugger;
-          setLoading(false);
+          //setLoading(false);
           var avgValues = (res.data || {}).avgValues;
           avgValues = avgValues ? avgValues.toFixed(selNav.fixed) : avgValues;
           var navTemp = { ...selNav, avgValues: avgValues };
@@ -178,7 +182,7 @@ const Environment: React.FC = () => {
           setEnvirMapList(dataSpaces);
         })
         .catch(() => {
-          setLoading(false);
+          // setLoading(false);
         });
     }
   }, [selNavId, selFloorId]);

+ 72 - 12
src/pages/Equipment/components/topNavRight/index.tsx

@@ -1,44 +1,104 @@
 // 设备管理 导航条的右侧
 import React, { useState, useEffect } from 'react';
-import { Dropdown, Menu, Modal } from 'antd';
+import { Dropdown, Menu, Modal, message } from 'antd';
 import Icon from '@/tenants-ui/Icon';
 import { EllipsisOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
 import styles from './index.less';
 //import { equipImageMap } from '@/config/image.js';
 import type { navigatorItem } from '@/pages/Environment/index';
+import { changeAllAirHttp } from '@/services/ant-design-pro/equipment';
 
 export type topNavRightProps = {
   selNavObj: navigatorItem;
   navigatorList: navigatorItem[];
+  mapList: API.MapInfo[];
 };
 
-const TopNavRight: React.FC<topNavRightProps> = ({ selNavObj, navigatorList }) => {
-  const [modalvisible, setModalvisible] = useState<boolean>(false);
+const TopNavRight: React.FC<topNavRightProps> = ({ selNavObj, navigatorList, mapList }) => {
+  //const [modalvisible, setModalvisible] = useState<boolean>(false);
   //去掉全部设备的 设备列表
   const [deviceList, setDeviceList] = useState<navigatorItem[]>([]);
   useEffect(() => {
     setDeviceList(navigatorList.slice(1));
   }, []);
-  const menuClick = (key) => {
+  const allOpenClick = (key) => {
+    //debugger;
     console.log('key', key);
+    confirm({
+      title: '请确认',
+      icon: <ExclamationCircleOutlined />,
+      content: `确认要全部开启${selNavObj.name}吗?`,
+      okText: '确认',
+      cancelText: '取消',
+      onOk() {
+        //如果是空调
+        if (selNavObj.id == 'airConditioner') {
+          changeAllAir('open');
+        }
+        if (selNavObj.id == 'light') {
+        }
+        if (selNavObj.id == 'curtain') {
+        }
+      },
+      onCancel() {
+        //console.log('Cancel');
+      },
+    });
   };
   const { confirm } = Modal;
-  const showModal = () => {
+  const allCloseClick = () => {
     console.log('showModal');
     // setModalvisible(true);
     confirm({
-      title: '',
+      title: '请确认',
       icon: <ExclamationCircleOutlined />,
-      content: '确认全部关闭吗?',
+      content: `确认要全部关闭${selNavObj.name}吗?`,
       okText: '确认',
       cancelText: '取消',
+      onOk() {
+        //如果是空调
+        if (selNavObj.id == 'airConditioner') {
+          changeAllAir('close');
+        }
+        if (selNavObj.id == 'light') {
+        }
+        if (selNavObj.id == 'curtain') {
+        }
+      },
+      onCancel() {
+        //console.log('Cancel');
+      },
     });
   };
 
-  const hideModal = () => {
-    console.log('hideModal');
-    //setModalvisible(false);
+  const changeAllAir = (type: string) => {
+    let paramsArr: any[] = [];
+    debugger;
+    mapList.forEach((sitem) => {
+      const itemId = type === 'close' ? 10 : 12; // 10关闭 12开启
+      paramsArr.push({
+        projectId: 'Pj1101080259',
+        objectId: sitem.id, // 空间id
+        valueType: 1, // 固定为1 1
+        itemId: itemId,
+      });
+    });
+
+    changeAllAirHttp(paramsArr).then((res) => {
+      debugger;
+      if (res.result == 'success') {
+        message.success('指令下发成功');
+        // sitem.airConditioner = res.isClose ? 0 : 1; //改变某空间空调的状态
+        //mapCombineList[index]['airConditioner'] = res.isClose ? 0 : 1;
+        // var mapCopy = JSON.parse(JSON.stringify(mapCombineList));
+        // mapCopy[index]['airConditioner'] = res.isClose ? 0 : 1;
+        // setMapCombineList(mapCopy);
+      } else {
+        message.error('操作失败,请重试');
+      }
+    });
   };
+
   return (
     <>
       {/* 全部设备 */}
@@ -62,7 +122,7 @@ const TopNavRight: React.FC<topNavRightProps> = ({ selNavObj, navigatorList }) =
         <div className={styles.right}>
           <div className={styles.title}>运行中的设备</div>
           <div className={styles.onlyNum}>{selNavObj.num}</div>
-          <div className={styles.closeButton} onClick={showModal}>
+          <div className={styles.closeButton} onClick={allCloseClick}>
             {/* <Button type="primary"  size={'large'}  icon={<Icon type="closeall"  style={{color:'red',fontSize:20}} />} style={{'background':'rgba(196, 196, 196, 0.2)',border:'none'}} >
               全部关闭
             </Button> */}
@@ -75,7 +135,7 @@ const TopNavRight: React.FC<topNavRightProps> = ({ selNavObj, navigatorList }) =
               trigger="click"
               placement="bottomLeft"
               overlay={
-                <Menu style={{ width: 160 }} onClick={({ key }) => menuClick(key)}>
+                <Menu style={{ width: 160 }} onClick={({ key }) => allOpenClick(key)}>
                   <Menu.Item key="open">全部开启</Menu.Item>
                 </Menu>
               }

+ 42 - 21
src/pages/Equipment/index.tsx

@@ -126,18 +126,16 @@ const Environment: React.FC = () => {
   const { confirm } = Modal;
   //空调的调节      0是关闭 1 是开启  2 是部分开启
   //这是存在疑惑 部分开启怎么办
-  const changeAir = (sitem, index) => {
+  const changeAir = (sitem, index: number) => {
     const itemId = sitem.airConditioner === 0 ? 12 : 10; // 10关闭 12开启
     const paramsObj = {
       objectId: sitem.id, // 空间id
-      valueType: 1, // 固定为1
+      valueType: 1, // 固定为1 1
       itemId: itemId,
     };
     changeAirHttp(paramsObj).then((res) => {
       if (res.result == 'success') {
         message.success('指令下发成功');
-        //这是没有部分开启一说吧
-        debugger;
         // sitem.airConditioner = res.isClose ? 0 : 1; //改变某空间空调的状态
         //mapCombineList[index]['airConditioner'] = res.isClose ? 0 : 1;
         var mapCopy = JSON.parse(JSON.stringify(mapCombineList));
@@ -148,12 +146,13 @@ const Environment: React.FC = () => {
       }
     });
   };
+
   //单个空间的点击事情
   const spaceControl = (item, index: number) => {
     if (selNav.id == 'all' || !item.roomFuncType) return;
     var status = item[selNav.id] === 0 ? '打开' : '关闭';
     confirm({
-      title: '确认',
+      title: '确认',
       icon: <ExclamationCircleOutlined />,
       content: `确认${status}该${selNav.name}吗?`,
       okText: '确认',
@@ -167,6 +166,7 @@ const Environment: React.FC = () => {
         }
         if (selNav.id == 'curtain') {
         }
+        debugger;
       },
       onCancel() {
         //console.log('Cancel');
@@ -176,20 +176,26 @@ const Environment: React.FC = () => {
   //获取地图 mapList
   useEffect(() => {
     if (selFloorId) {
+      setLoading(true);
       getMapList({
         //floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454',
         floorId: selFloorId,
-      }).then((res) => {
-        //debugger;
-        var data: API.MapInfo[] = (res.data || {}).spaceList || [];
-        setMapList(data);
-      });
+      })
+        .then((res) => {
+          //debugger;
+          setLoading(false);
+          var data: API.MapInfo[] = (res.data || {}).spaceList || [];
+          setMapList(data);
+        })
+        .catch(() => {
+          setLoading(false);
+        });
     }
   }, [selFloorId]);
   //获取设备状态 设备种类
   useEffect(() => {
     if (selFloorId) {
-      setLoading(true);
+      //setLoading(true);
       queryEquipStatistics({
         //floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454',
         floorId: selFloorId,
@@ -197,7 +203,7 @@ const Environment: React.FC = () => {
       })
         .then((res) => {
           //debugger;
-          setLoading(false);
+          // setLoading(false);
           var statistics = res.data.statistics || [];
           //赋值 运行中的设备数量
           navigatorList.forEach(function (nItem) {
@@ -219,7 +225,7 @@ const Environment: React.FC = () => {
           setEquipMapList(spaceList);
         })
         .catch(() => {
-          setLoading(false);
+          // setLoading(false);
         });
     }
   }, [selFloorId]);
@@ -227,19 +233,19 @@ const Environment: React.FC = () => {
   //获取时间列表 spaceTimeList
   useEffect(() => {
     if (selFloorId) {
-      setLoading(true);
+      //setLoading(true);
       queryDeviceTimeManage({
         floorId: selFloorId,
         //floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454',
         date: moment().format('YYYYMMDD'),
       })
         .then(function (res) {
-          setLoading(false);
+          //  setLoading(false);
           var resList = res.content || [];
           setTimeMapList(resList);
         })
         .catch(() => {
-          setLoading(false);
+          // setLoading(false);
         });
     }
   }, [selFloorId]);
@@ -261,7 +267,7 @@ const Environment: React.FC = () => {
     });
     //debugger;
     setMapCombineList(combineList);
-    debugger;
+    console.log('combine');
   }, [equipMapList, mapList, timeMapList]);
   let firtTime: number = 0;
   let lastTime: number = 0;
@@ -273,6 +279,7 @@ const Environment: React.FC = () => {
           <SearchInput
             mapList={mapList}
             onSearch={(s) => {
+              //触发了搜索
               setSearchText({ text: s });
             }}
           />
@@ -282,7 +289,13 @@ const Environment: React.FC = () => {
         navigatorList={navigatorList}
         type={'equipment'}
         navigatorChange={navigatorChange}
-        action={<TopNavRight selNavObj={selNav} navigatorList={navigatorList}></TopNavRight>}
+        action={
+          <TopNavRight
+            selNavObj={selNav}
+            navigatorList={navigatorList}
+            mapList={mapCombineList}
+          ></TopNavRight>
+        }
         changeFloorId={changeFloorId}
         selParamObj={selNav}
       ></TopNavigator>
@@ -342,12 +355,10 @@ const Environment: React.FC = () => {
                     }
                   }}
                   onMouseDown={(event) => {
-                    console.log(1);
                     //event.stopPropagation();
                     firtTime = new Date().getTime();
                   }}
                   onMouseUp={(event) => {
-                    console.log(2);
                     //event.stopPropagation();
                     lastTime = new Date().getTime();
                   }}
@@ -379,7 +390,17 @@ const Environment: React.FC = () => {
                       className={mapstyles.showModal}
                       onClick={(event) => {
                         event.stopPropagation();
-                        showModalClick(item);
+                        if (lastTime - firtTime < 300) {
+                          showModalClick(item);
+                        }
+                      }}
+                      onMouseDown={(event) => {
+                        //event.stopPropagation();
+                        firtTime = new Date().getTime();
+                      }}
+                      onMouseUp={(event) => {
+                        //event.stopPropagation();
+                        lastTime = new Date().getTime();
                       }}
                     >
                       <Icon className="" type="hover"></Icon>

+ 11 - 7
src/pages/Runtime/index.tsx

@@ -51,20 +51,24 @@ const Runtime: React.FC = () => {
   //获取地图 mapList
   useEffect(() => {
     if (selFloorId) {
-      getMapList({ floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454', projectId: '' }).then(
-        (res) => {
+      setLoading(true);
+      getMapList({ floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454', projectId: '' })
+        .then((res) => {
           //debugger;
+          setLoading(false);
           var data: API.MapInfo[] = (res.data || {}).spaceList || [];
           setMapList(data);
-        },
-      );
+        })
+        .catch(() => {
+          setLoading(false);
+        });
     }
   }, [selFloorId]);
 
   //获取时间列表 spaceTimeList
   useEffect(() => {
     if (selFloorId && selTime) {
-      setLoading(true);
+      //setLoading(true);
       queryDeviceTimeManage({
         //floorId: selFloorId,
         floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454',
@@ -72,7 +76,7 @@ const Runtime: React.FC = () => {
         date: 20220212,
       })
         .then(function (res) {
-          setLoading(false);
+          //setLoading(false);
           var resdata = res || {};
           setRuntimeNav({
             normalRun: resdata.workTimeNum,
@@ -106,7 +110,7 @@ const Runtime: React.FC = () => {
           setSpaceTimeList(resList);
         })
         .catch(() => {
-          setLoading(false);
+          //setLoading(false);
         });
     }
   }, [selFloorId, selTime]);

+ 12 - 0
src/services/ant-design-pro/environment.ts

@@ -85,3 +85,15 @@ export async function queryEquipStatistics(params: any, options?: { [key: string
     },
   });
 }
+
+export async function querySpace(body: any, options?: { [key: string]: any }) {
+  //
+  return request<API.EnvironmentParam>(`/api2/object/object/space/query`, {
+    method: 'POST',
+    headers: {
+      'Content-Type': 'application/json',
+    },
+    ...(options || {}),
+    data: body,
+  });
+}

+ 70 - 58
src/services/ant-design-pro/equipment.js

@@ -3,11 +3,11 @@ import { request } from 'umi';
 const API = 'https://duoduoenv.sagacloud.cn';
 
 function commonParams() {
-  return `openid=9a1ecfbacb6b4f249bf2dd3ec7793ead&pubname=sagacareAndtenantslink&projectId=Pj1101080259&userName=%E5%AE%89%E5%B0%8F%E9%9C%9E&userPhone=17611228068&userId=9a1ecfbacb6b4f249bf2dd3ec7793ead`;
-  //   return `openid=9a1ecfbacb6b4f249bf2dd3ec7793ead&pubname=sagacareAndtenantslink&projectId=Pj1101080259&userName=anxiaoxia&userPhone=17611228068
-  //   &userId=9a1ecfbacb6b4f249bf2dd3ec7793ead`;
+    return `openid=9a1ecfbacb6b4f249bf2dd3ec7793ead&pubname=sagacareAndtenantslink&projectId=Pj1101080259&userName=%E5%AE%89%E5%B0%8F%E9%9C%9E&userPhone=17611228068&userId=9a1ecfbacb6b4f249bf2dd3ec7793ead`;
+    //   return `openid=9a1ecfbacb6b4f249bf2dd3ec7793ead&pubname=sagacareAndtenantslink&projectId=Pj1101080259&userName=anxiaoxia&userPhone=17611228068
+    //   &userId=9a1ecfbacb6b4f249bf2dd3ec7793ead`;
 }
-function getProjectId(){
+function getProjectId() {
     return 'Pj1101080259'
 }
 
@@ -25,77 +25,89 @@ function getProjectId(){
 
 //窗帘 获取设备
 export const getObjectDataEqpGroupHttp = (params) => {
-  return request(`/server/object/objectDataEqpGroup/query?${commonParams()}`, {
-    method: 'POST',
-    isNotShowErrorToast: true,
-    errorSave: true,
-    data: JSON.stringify({ ...params }),
-    headers: {
-      'Content-Type': 'application/json',
-    },
-  });
+    return request(`/server/object/objectDataEqpGroup/query?${commonParams()}`, {
+        method: 'POST',
+        isNotShowErrorToast: true,
+        errorSave: true,
+        data: JSON.stringify({ ...params }),
+        headers: {
+            'Content-Type': 'application/json',
+        },
+    });
 };
 
 // 灯的状态
 export const getLampHttp = (params) => {
-  return request(`/server/light/status/query?${commonParams()}&spaceId=${params}`, {
-    isNotShowErrorToast: true,
-    errorSave: true,
-    method: 'GET',
-    headers: {
-      'Content-Type': 'application/json',
-    },
-  });
+    return request(`/server/light/status/query?${commonParams()}&spaceId=${params}`, {
+        isNotShowErrorToast: true,
+        errorSave: true,
+        method: 'GET',
+        headers: {
+            'Content-Type': 'application/json',
+        },
+    });
 };
 
 // 开关失败时 定时查询灯状态
 export const getStatusHttp = (params) => {
-  return request(`/server/light/onoff/setSatus?${commonParams()}`, {
-    method: 'POST',
-    isNotShowErrorToast: true,
-    errorSave: true,
-    data: JSON.stringify(params),
-    headers: {
-      'Content-Type': 'application/json',
-    },
-  });
+    return request(`/server/light/onoff/setSatus?${commonParams()}`, {
+        method: 'POST',
+        isNotShowErrorToast: true,
+        errorSave: true,
+        data: JSON.stringify(params),
+        headers: {
+            'Content-Type': 'application/json',
+        },
+    });
 };
 
 //  空调 - 调节文案/空调信息
 export const getFeedbackDocumentsHttp = (params) => {
-  return request(`/server/custom/feedback/documents?${commonParams()}`, {
-    isNotShowErrorToast: true,
-    errorSave: true,
-    method: 'POST',
-    data: JSON.stringify(params),
-    headers: {
-      'Content-Type': 'application/json',
-    },
-  });
+    return request(`/server/custom/feedback/documents?${commonParams()}`, {
+        isNotShowErrorToast: true,
+        errorSave: true,
+        method: 'POST',
+        data: JSON.stringify(params),
+        headers: {
+            'Content-Type': 'application/json',
+        },
+    });
 };
 
 //  空调 调节
 export const changeAirHttp = (params) => {
-  return request(`/server/custom/feedbackCreate/v2?${commonParams()}`, {
-    method: 'POST',
-    isNotShowErrorToast: true,
-    errorSave: true,
-    data: JSON.stringify({ ...params, projectId: getProjectId() }),
-    headers: {
-      'Content-Type': 'application/json',
-    },
-  });
+    return request(`/server/custom/feedbackCreate/v2?${commonParams()}`, {
+        method: 'POST',
+        isNotShowErrorToast: true,
+        errorSave: true,
+        data: JSON.stringify({ ...params, projectId: getProjectId() }),
+        headers: {
+            'Content-Type': 'application/json',
+        },
+    });
 };
 
 // 空间环境质量
-export const  getSpaceAdjustList =(params) =>{
-    return request(`/server/space/property?${commonParams()}`,{
-      method: 'POST',
-      isNotShowErrorToast: true,
-      errorSave: true,
-      data: JSON.stringify({...params, criteria: {...params.criteria, projectId: getProjectId()}}),
-      headers: {
-        'Content-Type': 'application/json',
-      },
+export const getSpaceAdjustList = (params) => {
+    return request(`/server/space/property?${commonParams()}`, {
+        method: 'POST',
+        isNotShowErrorToast: true,
+        errorSave: true,
+        data: JSON.stringify({ ...params, criteria: { ...params.criteria, projectId: getProjectId() } }),
+        headers: {
+            'Content-Type': 'application/json',
+        },
+    });
+}
+//  空调 调节
+export const changeAllAirHttp = (body) => {
+    return request(`/server/custom/feedbackCreate/v2Batch?${commonParams()}`, {
+        method: 'POST',
+        isNotShowErrorToast: true,
+        errorSave: true,
+        data: body,
+        headers: {
+            'Content-Type': 'application/json',
+        },
     });
-  }
+};