123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- import React, { useState, useEffect, useCallback } from 'react';
- import { FormattedMessage, useModel } from 'umi';
- import SearchInput from '@/components/SearchInput';
- import PageHeader from '@/components/PageHeader';
- import Map from '@/components/map';
- import TopNavigator from '@/components/topNavigator';
- import TopNavRight from './components/topNavRight';
- import DeviceModal from './components/deviceModal';
- import styles from './index.less';
- import mapstyles from '@/assets/css/map.less';
- import { Spin, Modal, message } from 'antd';
- import moment from 'moment';
- import { ExclamationCircleOutlined } from '@ant-design/icons';
- import { equipImageMap } from '@/config/image.js';
- import Icon from '@/tenants-ui/Icon';
- import type { navigatorItem } from '@/pages/Environment/index';
- import {
- getMapList,
- queryEquipStatistics,
- queryDeviceTimeManage,
- } from '@/services/ant-design-pro/environment';
- import {
- changeCurtain,
- changeAir,
- changeLight,
- getLamp,
- getAirInfo,
- } from '@/pages/Equipment/equipmentControl';
- type equipStatus = {
- equipType: string;
- status: number;
- };
- type statistics = {
- equipType: string;
- runCount: number;
- };
- const Environment: React.FC = () => {
- const { getSpaceFunc, projectId } = useModel('spaceFunc');
- const { changeSearchFloorId } = useModel('buildFloor');
- const { envir_all, equip_air, equip_lamp, envir_curtain } = equipImageMap;
- const [searchText, setSearchText] = useState<{ text: any }>();
-
-
-
- const [showModal, setShowModal] = useState<boolean>(false);
- const [showSpace, setShowSpace] = useState<API.MapInfo>({});
- const [navigatorList, setNavigatorList] = useState<navigatorItem[]>([
- {
- name: '全部设备',
- id: 'all',
- src: envir_all,
-
- color: '#E89E32',
- colorStr: '',
- },
- {
- name: '空调',
- id: 'airConditioner',
- src: equip_air,
- num: 0,
- color: '#5E8BCF',
- colorStr: '94,139,207,',
- },
- {
- name: '照明',
- id: 'light',
- src: equip_lamp,
- num: 0,
- color: '#FFE823',
- colorStr: '255,232,35,',
- },
- {
- name: '窗帘',
- id: 'curtain',
- src: envir_curtain,
- num: 0,
- color: '#E89E32',
- colorStr: '232, 158, 50,',
- },
- ]);
- const [mapList, setMapList] = useState<API.MapInfo[]>([]);
- const [equipMapList, setEquipMapList] = useState<any[]>([]);
- const [timeMapList, setTimeMapList] = useState<any[]>([]);
- const [selNav, setSelNav] = useState<navigatorItem>(navigatorList[0]);
- const [selFloorId, setSelFloorId] = useState<string>();
- const [mapCombineList, setMapCombineList] = useState<any[]>([]);
- const [loading, setLoading] = useState<boolean>(false);
- const changeFloorId = (data: string) => {
-
- setSelFloorId(data);
- };
-
- const navigatorChange = (item: navigatorItem) => {
- setSelNav(item);
- };
- const showModalClick = (item) => {
- console.log('showChart');
- setShowModal(true);
- setShowSpace(item);
- };
-
-
- const getColorOpacity = (value: number, type?: string): string => {
- let colorStr = '';
- if (selNav.id == 'all') {
-
- var filterRes = navigatorList.filter(function (item) {
- return item.id == type;
- });
- colorStr = (filterRes[0] || {}).colorStr;
- } else {
- colorStr = selNav.colorStr;
- }
- if (value === 2) {
-
- return 'rgba(' + colorStr + '0.4)';
- } else if (value === 1) {
-
- return 'rgba(' + colorStr + '1)';
- } else if (value === 0) {
-
- return 'rgba(196, 196, 196, 0.6)';
- }
- };
- const { confirm } = Modal;
-
- const spaceControl = (item, index: number) => {
-
- if (selNav.id == 'all' || !item.roomFuncType) return;
-
-
- if (item[selNav.id] === 2) {
- confirm({
- title: '请确认',
- icon: <ExclamationCircleOutlined />,
- content: `是否进入单空间进行调节?`,
- okText: '确认',
- cancelText: '取消',
- onOk() {
- showModalClick(item);
- },
- onCancel() {
-
- },
- });
- return;
- }
- var status = item[selNav.id] === 1 ? '关闭' : '打开';
- confirm({
- title: '请确认',
- icon: <ExclamationCircleOutlined />,
- content: `确认${status}该${selNav.name}吗?`,
- okText: '确认',
- cancelText: '取消',
- onOk() {
-
-
-
-
-
-
-
-
-
- function callback() {
-
- var mapCopy = JSON.parse(JSON.stringify(mapCombineList));
- mapCopy[index][selNav.id] = item[selNav.id] === 1 ? 0 : 1;
- setMapCombineList(mapCopy);
- }
-
- if (selNav.id == 'airConditioner') {
- function getDeviceStatus() {
-
- getAirInfo(item, callback, 10, projectId);
- }
- changeAir(item, index, getDeviceStatus);
- }
- if (selNav.id == 'light') {
- function getDeviceStatus() {
-
- getLamp(item, callback, 10);
- }
- changeLight('one', [item], getDeviceStatus, status);
- }
- if (selNav.id == 'curtain') {
- changeCurtain('one', [item], callback, status);
- }
- },
- onCancel() {
-
- },
- });
- };
-
- useEffect(() => {
-
- if (selFloorId) {
- setLoading(true);
- getMapList({
-
- floorId: selFloorId,
- })
- .then((res) => {
- setLoading(false);
- var data: API.MapInfo[] = (res.data || {}).spaceList || [];
- setMapList(data);
-
- })
- .catch(() => {
- setLoading(false);
- });
- } else {
- setMapList([]);
- }
- }, [selFloorId]);
- const queryDeviceManage = () => {
-
- queryEquipStatistics({
- floorId: selFloorId,
- projectId: projectId,
- })
- .then((res) => {
-
- var statistics = res.data.statistics || [];
-
- navigatorList.forEach(function (nItem) {
- var fres = statistics.filter((sItem: statistics) => {
- return sItem.equipType == nItem.id;
- });
- nItem.num = (fres[0] || {}).runCount;
- });
- setNavigatorList(navigatorList);
-
- var spaceList = res.data.spaceList || [];
- spaceList.forEach((item: any) => {
- var allType = ['airConditioner', 'light', 'curtain'];
- allType.forEach((etype) => {
- var filterRes = (item.equipStatusList || []).filter((eItem: equipStatus) => {
- return eItem.equipType == etype;
- });
-
- filterRes.length > 0 ? (item[etype] = filterRes[0].status) : (item[etype] = 'not');
- });
- });
-
- setEquipMapList(spaceList);
- })
- .catch(() => {
-
- });
- };
-
- useEffect(() => {
- if (selFloorId) {
- queryDeviceManage();
- }
- }, [selFloorId]);
-
- useEffect(() => {
- if (selFloorId) {
-
- queryDeviceTimeManage({
- floorId: selFloorId,
-
- date: moment().format('YYYYMMDD'),
- })
- .then(function (res) {
-
- var resList = res.content || [];
- setTimeMapList(resList);
- })
- .catch(() => {
-
- });
- }
- }, [selFloorId]);
-
- useEffect(() => {
- var combineList: any = [];
- mapList.map(function (mitem) {
- var spaceId = mitem.spaceId;
- var filterSpace1 = equipMapList.filter((ele) => {
- return ele.id == spaceId;
- });
- var filterSpace2 = timeMapList.filter((ele) => {
- return ele.id == spaceId;
- });
- var combine = Object.assign({}, mitem, filterSpace1[0], filterSpace2[0]);
- combineList.push(combine);
- });
- setMapCombineList(combineList);
- console.log('combine');
- }, [equipMapList, mapList, timeMapList]);
- let firtTime: number = 0;
- let lastTime: number = 0;
- return (
- <>
- <PageHeader
- title={<FormattedMessage id="menu.equipment" />}
- action={
- <SearchInput
- mapList={mapList}
- callbackSearch={(s) => {
-
-
- setSearchText({ text: s.localName });
- }}
- />
- }
- />
- <TopNavigator
- navigatorList={navigatorList}
- type={'equipment'}
- navigatorChange={navigatorChange}
- action={
- <TopNavRight
- selNavObj={selNav}
- navigatorList={navigatorList}
- mapList={mapCombineList}
- queryDeviceManage={queryDeviceManage}
- ></TopNavRight>
- }
- changeFloorId={changeFloorId}
- selParamObj={selNav}
- ></TopNavigator>
- <div className={styles.maptop}>
- {selNav.id !== 'all' && (
- <div className={styles.right}>
- <div>
- <span
- className={styles.circle}
- style={{ backgroundColor: 'rgba(' + selNav.colorStr + '1)' }}
- ></span>
- <span>开启</span>
- </div>
- <div>
- <span
- className={styles.circle}
- style={{ backgroundColor: 'rgba(' + selNav.colorStr + '0.4)' }}
- ></span>
- <span>部分开启</span>
- </div>
- <div>
- <span
- className={styles.circle}
- style={{ backgroundColor: 'rgba(196, 196, 196, 0.6)' }}
- ></span>
- <span>关闭</span>
- </div>
- </div>
- )}
- </div>
- <Spin spinning={loading}>
- {mapCombineList.length > 0 && (
- <Map
- searchText={searchText}
- mapList={mapCombineList}
- type={'equipment'}
- render={(item, index) => {
- return (
- <div
- key={index + item.id}
- className={mapstyles.house}
- style={{
- left: item.left,
- top: item.top,
- width: item.width,
- height: item.height,
- background: item.roomFuncType
- ? selNav.id == 'all'
- ? 'rgba(196, 196, 196, 0.2)'
- : getColorOpacity(item[selNav.id])
- : 'repeating-linear-gradient(45deg, rgb(226 226 226), #ffffff 8px)',
- }}
- onClick={(event) => {
- event.stopPropagation();
- if (lastTime - firtTime < 200) {
- spaceControl(item, index);
- }
- }}
- onMouseDown={(event) => {
-
- firtTime = new Date().getTime();
- }}
- onMouseUp={(event) => {
-
- lastTime = new Date().getTime();
- }}
- >
- {selNav.id !== 'all' && item[selNav.id] == 'not' && (
- <div className={mapstyles.allDevice}>无设备</div>
- )}
- {selNav.id == 'all' && (
- <div className={mapstyles.allDevice}>
- {}
- {(item.equipStatusList || []).map((ditem: equipStatus, dindex: number) => {
- return (
- <div
- key={dindex + 'device'}
- className={mapstyles.icon}
- style={{
- backgroundColor: getColorOpacity(ditem.status, ditem.equipType),
- }}
- >
- <Icon
- className=""
- type={ditem.equipType}
- style={{ color: '#ffffff', fontWeight: 'bold' }}
- ></Icon>
- </div>
- );
- })}
- </div>
- )}
- {item.roomFuncType && (
- <div
- className={mapstyles.showModal}
- onClick={(event) => {
- event.stopPropagation();
- if (lastTime - firtTime < 200) {
- showModalClick(item);
- }
- }}
- onMouseDown={(event) => {
-
- firtTime = new Date().getTime();
- }}
- onMouseUp={(event) => {
-
- lastTime = new Date().getTime();
- }}
- >
- <Icon className="" type="hover"></Icon>
- </div>
- )}
- <div className={mapstyles.content}>
- <Icon
- className=""
- type={getSpaceFunc(item.roomFuncType)}
- style={{ fontSize: 20 }}
- ></Icon>
- <div className={mapstyles.name}>{item.localName}</div>
- </div>
- </div>
- );
- }}
- ></Map>
- )}
- </Spin>
- {showModal && (
- <DeviceModal
- showSpace={showSpace}
- onClose={() => {
- setShowModal(false);
- }}
- ></DeviceModal>
- )}
- </>
- );
- };
- export default Environment;
|