ConditionDetection.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // 优化任务
  2. import { queryRealEstimate, queryRealEstimateChart } from '@/services/SmartOps';
  3. import { useParams, useRequest } from '@umijs/max';
  4. import { Col, Row } from 'antd';
  5. import * as echarts from 'echarts';
  6. import { useEffect, useMemo, useRef } from 'react';
  7. import PageContent from '@/components/PageContent';
  8. import PageTitle from '@/components/PageTitle';
  9. import styles from './ConditionDetection.less';
  10. import CircleScore from './components/CircleScore';
  11. const ConditionDetection = (props) => {
  12. const { projectId } = useParams();
  13. let pid = Number(projectId);
  14. // 查询工况
  15. const { data } = useRequest(queryRealEstimate, {
  16. defaultParams: [pid],
  17. });
  18. const { score, real, best, grade } = useMemo(() => {
  19. let score = '-',
  20. grade = '-',
  21. real = {},
  22. best = {};
  23. if (data) {
  24. score = data.score;
  25. if (score >= 90) {
  26. grade = '优秀';
  27. } else if (score >= 80) {
  28. grade = '良好';
  29. } else if (score >= 70) {
  30. grade = '较好';
  31. } else if (score >= 60) {
  32. grade = '一般';
  33. } else {
  34. grade = '较差';
  35. }
  36. real = data.list[0] || {};
  37. best = data.list[1] || {};
  38. }
  39. return { score, real, best, grade };
  40. }, [data]);
  41. return (
  42. <PageContent closeable={false}>
  43. <PageTitle returnable>工况检测</PageTitle>
  44. <div className="content-title">
  45. <div className={styles.circle}>
  46. <CircleScore big>
  47. <span className={styles.circleText}>{score}</span>
  48. </CircleScore>
  49. {/* <p>{desc}</p> */}
  50. <p>膜车间当前运行状态{grade}</p>
  51. </div>
  52. <div className={styles.content}>
  53. <Row gutter={16}>
  54. <Col span={12} style={{ padding: "0.2rem" }}>
  55. <div className={`${styles.card} card-box`}>
  56. <h3>
  57. 实时工况 <span>{real.score}分</span>
  58. </h3>
  59. <ul>
  60. <li>
  61. <i></i>水质达标率评分:{real.water}
  62. </li>
  63. <li>
  64. <i></i>能耗评分:{real.energy}
  65. </li>
  66. <li>
  67. <i></i>药耗评分:{real.medicine}
  68. </li>
  69. <li>
  70. <i></i>设施设备利用率评分:{real.device_rate}
  71. </li>
  72. <li>
  73. <i></i>设施设备完好率评分:{real.device_intact}
  74. </li>
  75. </ul>
  76. </div>
  77. </Col>
  78. <Col span={12} style={{ padding: "0.2rem" }}>
  79. <div className={`${styles.card2} card-box`}>
  80. <h3>
  81. 目标工况 <span>{best.score}分</span>
  82. </h3>
  83. <ul>
  84. <li>
  85. <i></i>水质达标率评分:{best.water}
  86. </li>
  87. <li>
  88. <i></i>能耗评分:{best.energy}
  89. </li>
  90. <li>
  91. <i></i>药耗评分:{best.medicine}
  92. </li>
  93. <li>
  94. <i></i>设施设备利用率评分:{best.device_rate}
  95. </li>
  96. <li>
  97. <i></i>设施设备完好率评分:{best.device_intact}
  98. </li>
  99. </ul>
  100. </div>
  101. </Col>
  102. </Row>
  103. <div className={styles.img}></div>
  104. </div>
  105. <ChartContent projectId={pid} />
  106. </div>
  107. </PageContent>
  108. );
  109. };
  110. const ChartContent = ({ projectId }) => {
  111. const domRef = useRef(null);
  112. const chartRef = useRef(null);
  113. useRequest(queryRealEstimateChart, {
  114. defaultParams: [projectId],
  115. onSuccess(data) {
  116. let options = getOption([
  117. data.device_rate,
  118. data.device_intact,
  119. data.water,
  120. data.energy,
  121. data.medicine,
  122. ]);
  123. chartRef.current.setOption(options, true);
  124. },
  125. });
  126. function getOption(data = []) {
  127. const option = {
  128. color: [
  129. '#F5A623',
  130. '#4B9FEC',
  131. '#91cc75',
  132. '#5470c6',
  133. '#fac858',
  134. '#ee6666',
  135. '#73c0de',
  136. '#3ba272',
  137. '#fc8452',
  138. '#9a60b4',
  139. '#ea7ccc',
  140. ],
  141. tooltip: {
  142. trigger: 'axis',
  143. textStyle: {
  144. fontSize: 8,
  145. },
  146. },
  147. legend: {
  148. textStyle: {
  149. // color: '#fff',
  150. fontSize: 8,
  151. },
  152. },
  153. grid: {
  154. left: '3%',
  155. right: '4%',
  156. bottom: '3%',
  157. containLabel: true,
  158. },
  159. xAxis: {
  160. type: 'category',
  161. boundaryGap: false,
  162. data: data[0].list?.map((item) => item.name.split(' ')[1]),
  163. nameTextStyle: {
  164. fontSize: 8,
  165. },
  166. axisLabel: {
  167. fontSize: 8,
  168. },
  169. },
  170. yAxis: {
  171. type: 'value',
  172. boundaryGap: true,
  173. splitNumber: 5,
  174. nameTextStyle: {
  175. fontSize: 8,
  176. },
  177. axisLabel: {
  178. fontSize: 8,
  179. },
  180. },
  181. series: data.map((item) => ({
  182. name: item.name,
  183. type: 'line',
  184. showSymbol: false,
  185. type: 'line',
  186. smooth: true,
  187. data: item?.list.map((v) => v.value),
  188. })),
  189. };
  190. return option;
  191. }
  192. useEffect(() => {
  193. chartRef.current = echarts.init(domRef.current);
  194. return () => {
  195. chartRef.current.dispose();
  196. };
  197. }, []);
  198. return (
  199. <div className={`${styles.card} card-box`}>
  200. <div className={styles.title}>近一日工况统计</div>
  201. <div ref={domRef} style={{ height: '38vh' }}></div>
  202. </div>
  203. );
  204. };
  205. export default ConditionDetection;