index.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import React, { useState, useEffect, useCallback } from 'react';
  2. import PageHeader from '@/components/PageHeader';
  3. import Map from '@/components/map';
  4. import TopNavigator from '@/components/topNavigator';
  5. import RunNavRight from './components/topNavRight';
  6. import { FormattedMessage, history, useModel } from 'umi';
  7. import { Spin } from 'antd';
  8. import { Popover } from 'antd';
  9. import styles from './index.less';
  10. import mapstyles from '@/assets/css/map.less';
  11. import Icon from '@/tenants-ui/Icon';
  12. import SearchInput from '@/components/SearchInput';
  13. import moment from 'moment';
  14. import cx from 'classnames';
  15. import { getMapList, queryDeviceTimeManage } from '@/services/ant-design-pro/environment';
  16. type runtimeNavType = {
  17. normalRun: any;
  18. overtimeWork: number;
  19. meetingBook: number;
  20. };
  21. const Runtime: React.FC = () => {
  22. // const { maptemp6 } = equipImageMap;
  23. const { getSpaceFunc } = useModel('spaceFunc');
  24. const [loading, setLoading] = useState<boolean>(true);
  25. const [searchText, setSearchText] = useState<{ text: any }>();
  26. const [runtimeNav, setRuntimeNav] = useState<runtimeNavType>({});
  27. const [mapList, setMapList] = useState<API.MapInfo[]>([]);
  28. const [mapCombineList, setMapCombineList] = useState<any[]>([]);
  29. const [selFloorId, setSelFloorId] = useState<string>();
  30. const [selTime, setSelTime] = useState<string>(moment().format('YYYYMMDD'));
  31. const [spaceTimeList, setSpaceTimeList] = useState<any[]>([]);
  32. //楼层切换的回调
  33. const changeFloorId = (data: string) => {
  34. //debugger;
  35. setSelFloorId(data);
  36. };
  37. const checkRecord = () => {
  38. history.push('/runtime/recordList');
  39. console.log('showR');
  40. };
  41. //时间切换的回调
  42. const changeTime = (time) => {
  43. //debugger;
  44. var timeStr = time.format('YYYYMMDD');
  45. setSelTime(timeStr);
  46. };
  47. //获取地图 mapList
  48. useEffect(() => {
  49. if (selFloorId) {
  50. getMapList({ floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454', projectId: '' }).then(
  51. (res) => {
  52. //debugger;
  53. var data: API.MapInfo[] = (res.data || {}).spaceList || [];
  54. setMapList(data);
  55. },
  56. );
  57. }
  58. }, [selFloorId]);
  59. //获取时间列表 spaceTimeList
  60. useEffect(() => {
  61. if (selFloorId && selTime) {
  62. setLoading(true);
  63. queryDeviceTimeManage({
  64. //floorId: selFloorId,
  65. floorId: 'Fl11010802593241ec348ecb4148806b9034c8957454',
  66. //date: selTime,
  67. date: 20220212,
  68. })
  69. .then(function (res) {
  70. setLoading(false);
  71. var resdata = res || {};
  72. setRuntimeNav({
  73. normalRun: resdata.workTimeNum,
  74. overtimeWork: resdata.overTimeNum,
  75. meetingBook: resdata.meetTimeNum,
  76. });
  77. var resList = res.content || [];
  78. resList.forEach((ritem) => {
  79. ritem.runTimeStatus = 'normalRun'; //正常工作
  80. var timeList = [];
  81. if (ritem.hasOwnProperty('workTimeStartTime')) {
  82. var timeStrArr = [ritem.workTimeStartTime, ritem.workTimeEndTime];
  83. timeList.push(timeStrArr);
  84. }
  85. if (ritem.hasOwnProperty('meetTime')) {
  86. ritem.runTimeStatus = 'meetingBook'; //会议预约
  87. ritem.meetTime.forEach((meetitem) => {
  88. var timeStrArr = [meetitem.meetTimeStartTime, meetitem.meetTimeEndTime];
  89. timeList.push(timeStrArr);
  90. });
  91. }
  92. if (ritem.hasOwnProperty('overTimeStartTime')) {
  93. var timeStrArr = [ritem.overTimeStartTime, ritem.overTimeEndTime];
  94. timeList.push(timeStrArr);
  95. ritem.runTimeStatus = 'overtimeWork'; //加班
  96. }
  97. ritem.showTimeList = timeList;
  98. ritem.showTimeStr =
  99. timeList.length > 0 ? timeList[0][0] + '-' + timeList[timeList.length - 1][1] : '';
  100. });
  101. setSpaceTimeList(resList);
  102. })
  103. .catch(() => {
  104. setLoading(false);
  105. });
  106. }
  107. }, [selFloorId, selTime]);
  108. useEffect(() => {
  109. //mapList,spaceTimeList 这两个数据的结合
  110. console.log('dfsd-------', mapList, spaceTimeList);
  111. // if (mapList && mapList.length > 0 && spaceTimeList && spaceTimeList.length > 0) {
  112. var combineList: any = [];
  113. mapList.map(function (mitem) {
  114. var spaceId = mitem.spaceId;
  115. var filterSpace = spaceTimeList.filter((ele) => {
  116. return ele.id == spaceId;
  117. });
  118. var combine = Object.assign({}, mitem, filterSpace[0]);
  119. combineList.push(combine);
  120. });
  121. setMapCombineList(combineList);
  122. // }
  123. }, [mapList, spaceTimeList]);
  124. return (
  125. <>
  126. <PageHeader
  127. title={<FormattedMessage id="menu.runtime" />}
  128. action={
  129. // <div className={styles.headerRight}>
  130. // <div className={styles.check} onClick={checkRecord} style={{ display: 'none' }}>
  131. // <Icon className="" style={{ marginRight: 6 }} type="document" />
  132. // <span>查看加班记录</span>
  133. // </div>
  134. // </div>
  135. <SearchInput
  136. mapList={mapList}
  137. onSearch={(s) => {
  138. setSearchText({ text: s });
  139. }}
  140. />
  141. }
  142. />
  143. <TopNavigator
  144. type={'runtime'}
  145. action={<RunNavRight runtimeNav={runtimeNav} changeTime={changeTime}></RunNavRight>}
  146. changeFloorId={changeFloorId}
  147. ></TopNavigator>
  148. <div className={styles.maptop}>
  149. <div className={styles.right}></div>
  150. </div>
  151. {/* <div className={styles.map}>
  152. <div className={styles.specialRoom}></div>
  153. <img src={mapImg}></img>
  154. </div> */}
  155. {/* <div
  156. className={mapstyles.house}
  157. style={{
  158. width: 180,
  159. height: 100,
  160. }}
  161. >
  162. <div className={mapstyles.allTime}>08:00-23:00</div>
  163. <div className={mapstyles.content}>
  164. <Icon className="" type="office" style={{ fontSize: 20 }}></Icon>
  165. <div className={mapstyles.name}>Jozy Zone</div>
  166. </div>
  167. </div> */}
  168. <Spin spinning={loading}>
  169. <Map
  170. searchText={searchText}
  171. mapList={mapCombineList}
  172. type={'runtime'}
  173. render={(item, index) => {
  174. return (
  175. <div
  176. key={index + 'house'}
  177. className={mapstyles.house}
  178. style={{
  179. left: item.left,
  180. top: item.top,
  181. width: item.width,
  182. height: item.height,
  183. background: item.roomFuncType
  184. ? item.runTimeStatus == 'meetingBook'
  185. ? 'rgba(0, 220, 35, 0.2)'
  186. : item.runTimeStatus == 'overtimeWork'
  187. ? 'rgba(94, 139, 207, 0.2)'
  188. : 'rgba(196, 196, 196, 0.2)'
  189. : 'repeating-linear-gradient(45deg, rgb(226 226 226), #ffffff 8px)',
  190. }}
  191. >
  192. <div className={mapstyles.allTime}>
  193. {/* {(item.timeList || []).map(function (titem: string, tindex: number) {
  194. return <span key={tindex + 'time'}>{titem},</span>;
  195. })} */}
  196. {item.showTimeList && item.showTimeList.length > 1 && (
  197. <Popover
  198. content={(item.showTimeList || []).map((timeItem, index) => {
  199. return (
  200. <div key={'time' + index}>
  201. {timeItem[0]}-{timeItem[1]}
  202. </div>
  203. );
  204. })}
  205. trigger="hover"
  206. style={{ color: 'none' }}
  207. >
  208. <span
  209. className={cx({
  210. [mapstyles.overworkTime]: item.runTimeStatus == 'overtimeWork',
  211. [mapstyles.meetTime]: item.runTimeStatus == 'meetingBook',
  212. })}
  213. >
  214. {item.showTimeStr}
  215. </span>
  216. </Popover>
  217. )}
  218. {item.showTimeList && item.showTimeList.length == 1 && (
  219. <span>{item.showTimeStr}</span>
  220. )}
  221. </div>
  222. <div className={mapstyles.content}>
  223. <Icon
  224. className=""
  225. type={getSpaceFunc(item.roomFuncType)}
  226. style={{ fontSize: 20 }}
  227. ></Icon>
  228. <div className={mapstyles.name}>{item.localName}</div>
  229. </div>
  230. </div>
  231. );
  232. }}
  233. ></Map>
  234. </Spin>
  235. </>
  236. );
  237. };
  238. export default Runtime;