index.jsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import React, { useState, useEffect, useRef } from 'react';
  2. import { Modal, Form } from 'antd';
  3. import Draggable from 'react-draggable';
  4. import Icon from '@/tenants-ui/SgIcon';
  5. import styles from './index.less';
  6. import cx from 'classnames';
  7. import { equipImageMap } from '@/config/sagacare/sagacare_image.js';
  8. import LineChart from './lineChart';
  9. export default ({ onClose, showSpace, selNav }) => {
  10. const { ruleCo2, ruleHcho, rulePm25 } = equipImageMap;
  11. const [paramList, setParamList] = useState([
  12. {
  13. name: 'CO₂',
  14. id: 'CO2',
  15. maxType: 'co2Max',
  16. pointNum: null,
  17. level: '不同浓度下的人体感觉',
  18. srcImg: ruleCo2,
  19. content:
  20. 'CO₂一种无色无味气体,CO₂的标准为1000ppm,CO₂过高,影响人体呼吸系统,大脑易疲劳,工作效率降低,室内人员增多,新风量不足时,室内CO₂的浓度就会上升,宜开窗通风或增加送风量,来降低CO₂浓度',
  21. },
  22. {
  23. name: 'PM2.5',
  24. id: 'PM2d5',
  25. maxType: 'pm25Max',
  26. pointNum: 1,
  27. level: '不同PM2.5浓度对应等级',
  28. srcImg: rulePm25,
  29. content:
  30. 'PM2.5,直径≤2.5微米的颗粒,PM2.5的平均值在0-35μg/m3,PM2.5浓度过高,影响人体,呼吸系统和心血管系统健康,应开启除尘净化设备',
  31. },
  32. {
  33. name: '甲醛',
  34. id: 'HCHO',
  35. maxType: 'hchoMax',
  36. pointNum: 2,
  37. level: '不同阈值浓度对应标准',
  38. srcImg: ruleHcho,
  39. content:
  40. '甲醛(HCHO)是无色有刺激性有机气体。甲醛的主要危害表现为对皮肤和黏膜的刺激作用,室内甲醛浓度长期偏高会引发呼吸系统,消化系统或免疫系统疾病。甲醛多来自于室内装饰材料,如家具,墙纸,油漆以及胶水、芳香剂等物质。由于家具,胶水中的甲醛挥发是一个长期缓慢的过程,因此甲醛超标常表现为室内甲醛浓度长期处于较高的数值。最为有效避免甲醛超标的方法是持续高效的通风,通过引入室外新鲜空气将室内甲醛浓度长期控制在低于有害标准的范围内。由于甲醛传感器为电化学传感器,存在交叉干扰的特性,当室内出现无害的挥发性气体时也会导致测得的甲醛浓度短暂升高,如吸烟,使用香水,空气清新剂,喷洒酒精,甚至剥橘子皮溅出的汁液均可能在短时间内影响甲醛传感器的读数,在去除干扰源后,此种影响会在短时间内消除,可不必因此产生担忧。',
  41. },
  42. {
  43. name: '温湿度',
  44. id: 'Tdb,RH',
  45. maxType: 'temperatureMax',
  46. pointNum: 1,
  47. level: '',
  48. srcImg: '',
  49. content:
  50. '温度表示空气的冷热程度,夏季高温高湿会使人烦躁、疲倦,冬季湿度过高时,人体感觉越冷,冬季湿度低易引起呼吸道不舒适,室外温度较高时,宜遮阳关窗',
  51. },
  52. ]);
  53. const [paramObj, setParamObj] = useState({});
  54. const itemClick = (item) => {
  55. setParamObj(item);
  56. };
  57. const defaultType = () => {
  58. paramList.forEach((item) => {
  59. if (item.id.includes(selNav.id)) {
  60. itemClick(item);
  61. }
  62. });
  63. };
  64. useEffect(() => {
  65. defaultType(); // 默认展示类型
  66. }, [selNav]);
  67. // 拖拽
  68. const [disabled, setDisabled] = useState(false);
  69. const [bounds, setBounds] = useState({
  70. left: 0,
  71. top: 0,
  72. bottom: 0,
  73. right: 0,
  74. });
  75. const draggleRef = useRef(null);
  76. const onStart = (_event, uiData) => {
  77. const { clientWidth, clientHeight } = window.document.documentElement;
  78. const targetRect = draggleRef.current?.getBoundingClientRect();
  79. if (!targetRect) {
  80. return;
  81. }
  82. setBounds({
  83. left: -targetRect.left + uiData.x,
  84. right: clientWidth - (targetRect.right - uiData.x),
  85. top: -targetRect.top + uiData.y,
  86. bottom: clientHeight - (targetRect.bottom - uiData.y),
  87. });
  88. };
  89. return (
  90. <>
  91. <Modal
  92. width={550}
  93. visible
  94. maskClosable={false}
  95. closable={false}
  96. footer={null}
  97. style={{
  98. width: '100%',
  99. cursor: 'move',
  100. }}
  101. modalRender={(modal) => (
  102. <Draggable
  103. disabled={disabled}
  104. bounds={bounds}
  105. onStart={(event, uiData) => onStart(event, uiData)}
  106. >
  107. <div ref={draggleRef}>{modal}</div>
  108. </Draggable>
  109. )}
  110. >
  111. <div
  112. className={styles.main}
  113. onMouseDown={(e) => {
  114. e.preventDefault();
  115. }}
  116. >
  117. <div className={styles.header}>
  118. <div className={styles.title}>{showSpace.localName}</div>
  119. <div className={styles.close} onClick={onClose}>
  120. <Icon type="close" />
  121. </div>
  122. </div>
  123. <div className={styles.content}>
  124. <div className={styles.navigator}>
  125. {paramList.map((item, index) => {
  126. return (
  127. <div
  128. className={cx(styles.nitem, { [styles.sel]: item.id == paramObj.id })}
  129. key={'navc' + item.id}
  130. onClick={() => {
  131. itemClick(item);
  132. }}
  133. >
  134. {item.name}
  135. </div>
  136. );
  137. })}
  138. </div>
  139. <div className={styles.chart}>
  140. <LineChart paramObj={paramObj} spaceId={showSpace.spaceId} />
  141. </div>
  142. <div className={styles.foot}>
  143. <div className={styles.l}>{paramObj.name}</div>
  144. <div className={styles.r}>{paramObj.content}</div>
  145. </div>
  146. <div className={styles.leveSt}>
  147. <span>{paramObj.level}</span>
  148. </div>
  149. {paramObj.srcImg && (
  150. <div className={styles.ruleBox}>
  151. <img className={styles.ruleImg} src={paramObj.srcImg} />
  152. </div>
  153. )}
  154. </div>
  155. </div>
  156. </Modal>
  157. </>
  158. );
  159. };