WorkConditionAssessment.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import Panel from '@/pages/Smart/components/Panel';
  2. import { useMemo } from 'react';
  3. import BarChart from './BarChart';
  4. import RadarChartModule from './RadarChartModule';
  5. const WorkConditionAssessment = (props) => {
  6. const { process, projectId } = props;
  7. const radarData = useMemo(() => {
  8. let data = { value: [] };
  9. let indicator = [];
  10. [...process.base, ...process.control].forEach((item) => {
  11. data.value.push(item.value);
  12. indicator.push({
  13. name: item.name,
  14. max: item.max,
  15. });
  16. });
  17. return { indicator, data: [data] };
  18. }, [process]);
  19. const barData = useMemo(() => {
  20. let chartData = [];
  21. process.out.forEach((item, index) => {
  22. let data = {
  23. name: item.name,
  24. value: [
  25. {
  26. // 实际
  27. name: '实际',
  28. value: item.realValue,
  29. },
  30. {
  31. // 预测
  32. name: '预测',
  33. value: getRandomInRange(item.realValue),
  34. },
  35. ],
  36. };
  37. chartData.push(data);
  38. });
  39. return chartData;
  40. }, [process]);
  41. return (
  42. <Panel title="工况评估">
  43. <div style={{ position: 'relative', margin: '20px 0' }}>
  44. <div
  45. style={{
  46. fontSize: 20,
  47. padding: '0px 8px',
  48. color: '#FFF',
  49. background: '#fac858',
  50. borderRadius: 4,
  51. position: 'absolute',
  52. top: 0,
  53. left: 10,
  54. }}
  55. >
  56. 参数
  57. </div>
  58. <div style={{ height: 280 }}>
  59. <RadarChartModule color={'#fac858'} name={'参数'} {...radarData} />
  60. </div>
  61. </div>
  62. <div style={{ position: 'relative' }}>
  63. <div
  64. style={{
  65. fontSize: 20,
  66. padding: '0px 8px',
  67. color: '#FFF',
  68. background: '#ee6666',
  69. borderRadius: 4,
  70. position: 'absolute',
  71. top: 0,
  72. left: 10,
  73. }}
  74. >
  75. 输出
  76. </div>
  77. <div style={{ height: 320 }}>
  78. <BarChart data={barData} />
  79. </div>
  80. </div>
  81. </Panel>
  82. );
  83. };
  84. function getRandomInRange(num) {
  85. // 计算正负10%的范围
  86. var range = num * 0.1;
  87. // 生成随机值
  88. var randomValue = Math.random() * (2 * range) - range;
  89. // 计算结果并保留两位小数
  90. var result = (num + randomValue).toFixed(2);
  91. // 将结果转换为数值类型并返回
  92. return Number(result);
  93. }
  94. export default WorkConditionAssessment;