ConditionDetection.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. <div className={styles.circleBox}>
  50. <span className={styles.circleText}>{score}</span>
  51. </div>
  52. {/* <p>{desc}</p> */}
  53. <p>膜车间当前运行状态{grade}</p>
  54. </div>
  55. <div className={styles.content}>
  56. <Row gutter={16}>
  57. <Col span={12} style={{ padding: '0.2rem' }}>
  58. <div className={`${styles.card} card-box`}>
  59. <h3>
  60. 实时工况 <span>{real.score}分</span>
  61. </h3>
  62. <ul>
  63. <li>
  64. <i></i>水质达标率评分:{real.water}
  65. </li>
  66. <li>
  67. <i></i>能耗评分:{real.energy}
  68. </li>
  69. <li>
  70. <i></i>药耗评分:{real.medicine}
  71. </li>
  72. <li>
  73. <i></i>设施设备利用率评分:{real.device_rate}
  74. </li>
  75. <li>
  76. <i></i>设施设备完好率评分:{real.device_intact}
  77. </li>
  78. </ul>
  79. </div>
  80. </Col>
  81. <Col span={12} style={{ padding: '0.2rem' }}>
  82. <div className={`${styles.card2} card-box`}>
  83. <h3>
  84. 预测工况 <span>{best.score}分</span>
  85. </h3>
  86. <ul>
  87. <li>
  88. <i></i>水质达标率评分:{best.water}
  89. </li>
  90. <li>
  91. <i></i>能耗评分:{best.energy}
  92. </li>
  93. <li>
  94. <i></i>药耗评分:{best.medicine}
  95. </li>
  96. <li>
  97. <i></i>设施设备利用率评分:{best.device_rate}
  98. </li>
  99. <li>
  100. <i></i>设施设备完好率评分:{best.device_intact}
  101. </li>
  102. </ul>
  103. </div>
  104. </Col>
  105. </Row>
  106. <div className={styles.img}></div>
  107. </div>
  108. {/* <ChartContent projectId={pid} /> */}
  109. </div>
  110. </PageContent>
  111. );
  112. };
  113. const ChartContent = ({ projectId }) => {
  114. const domRef = useRef(null);
  115. const chartRef = useRef(null);
  116. useRequest(queryRealEstimateChart, {
  117. defaultParams: [projectId],
  118. onSuccess(data) {
  119. let options = getOption([
  120. data.device_rate,
  121. data.device_intact,
  122. data.water,
  123. data.energy,
  124. data.medicine,
  125. ]);
  126. chartRef.current.setOption(options, true);
  127. },
  128. });
  129. function getOption(data = []) {
  130. const option = {
  131. color: [
  132. '#F5A623',
  133. '#4B9FEC',
  134. '#91cc75',
  135. '#5470c6',
  136. '#fac858',
  137. '#ee6666',
  138. '#73c0de',
  139. '#3ba272',
  140. '#fc8452',
  141. '#9a60b4',
  142. '#ea7ccc',
  143. ],
  144. tooltip: {
  145. trigger: 'axis',
  146. textStyle: {
  147. fontSize: 8,
  148. },
  149. },
  150. legend: {
  151. textStyle: {
  152. // color: '#fff',
  153. fontSize: 8,
  154. },
  155. },
  156. grid: {
  157. left: '3%',
  158. right: '4%',
  159. bottom: '3%',
  160. containLabel: true,
  161. },
  162. xAxis: {
  163. type: 'category',
  164. boundaryGap: false,
  165. data: data[0].list?.map((item) => item.name.split(' ')[1]),
  166. nameTextStyle: {
  167. fontSize: 8,
  168. },
  169. axisLabel: {
  170. fontSize: 8,
  171. },
  172. },
  173. yAxis: {
  174. type: 'value',
  175. boundaryGap: true,
  176. splitNumber: 5,
  177. nameTextStyle: {
  178. fontSize: 8,
  179. },
  180. axisLabel: {
  181. fontSize: 8,
  182. },
  183. },
  184. series: data.map((item) => ({
  185. name: item.name,
  186. type: 'line',
  187. showSymbol: false,
  188. type: 'line',
  189. smooth: true,
  190. data: item?.list.map((v) => v.value),
  191. })),
  192. };
  193. return option;
  194. }
  195. useEffect(() => {
  196. chartRef.current = echarts.init(domRef.current);
  197. return () => {
  198. chartRef.current.dispose();
  199. };
  200. }, []);
  201. return (
  202. <div className={`${styles.card} card-box`}>
  203. <div className={styles.title}>近一日工况统计</div>
  204. <div ref={domRef} style={{ height: '38vh' }}></div>
  205. </div>
  206. );
  207. };
  208. export default ConditionDetection;