消毒机设备
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.8 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <script lang="ts" setup>
  2. import * as echarts from 'echarts'
  3. import { formatDateTime } from 'libs/utils'
  4. import { onMounted, ref, watch } from 'vue'
  5. const props = defineProps<{
  6. envData: any
  7. }>()
  8. const titles = {
  9. Internal: '仓内',
  10. WiredExtSensor: '探头',
  11. WirelessExtSensor: '探头',
  12. }
  13. watch(
  14. () => props.envData,
  15. (newValue) => {
  16. if (!chartRef.value) {
  17. return
  18. }
  19. let myChart = echarts.getInstanceByDom(chartRef.value)
  20. if (!myChart) {
  21. myChart = echarts.init(chartRef.value, null, { renderer: 'svg' })
  22. }
  23. const option = {
  24. title: {
  25. text: (titles[newValue?.type || ''] || '') + (newValue.type !== 'Internal' ? newValue?.id || '' : ''),
  26. left: 'center', // 水平居中
  27. top: 0,
  28. },
  29. grid: {
  30. top: 100,
  31. },
  32. tooltip: {
  33. trigger: 'axis',
  34. position: [10, 10],
  35. formatter: (params: any[]) => {
  36. if (!params || !params.length)
  37. return ''
  38. const time = params[0].axisValue
  39. let html = `<div>${time}</div>`
  40. params.forEach((item) => {
  41. let unit = ''
  42. switch (item.seriesName) {
  43. case '温度':
  44. unit = ' ℃'
  45. break
  46. case '相对湿度':
  47. unit = ' %RH'
  48. break
  49. case 'H₂O₂浓度':
  50. unit = ' ppm'
  51. break
  52. case 'H₂O₂相对饱和度':
  53. unit = ' %RS'
  54. break
  55. }
  56. // item.marker 就是 echarts 自动给你的小彩点
  57. html += `<div>${item.marker} ${item.seriesName}: ${item.data}${unit}</div>`
  58. })
  59. return html
  60. },
  61. },
  62. legend: {
  63. data: ['温度', '相对湿度', 'H₂O₂浓度', 'H₂O₂相对饱和度'],
  64. orient: 'horizontal', // 水平布局
  65. itemWidth: 10, // 图例图形宽度
  66. itemHeight: 10, // 图例图形高度
  67. columnWidth: 80, // 每列宽度,可按需调整
  68. top: '5%', // 距离容器顶部距离
  69. left: 'center', // 水平居中
  70. },
  71. xAxis: {
  72. type: 'category',
  73. boundaryGap: false,
  74. data: newValue.data?.map(item => formatDateTime('HH:mm:ss', item.timestamp)),
  75. },
  76. yAxis: {
  77. type: 'value',
  78. },
  79. series: [
  80. {
  81. name: '温度',
  82. type: 'line',
  83. data: newValue.data?.map(item => item.temp.toFixed(2)),
  84. symbol: 'circle',
  85. symbolSize: 2,
  86. lineStyle: {
  87. color: '#1e90ff',
  88. width: 1,
  89. },
  90. },
  91. {
  92. name: '相对湿度',
  93. type: 'line',
  94. data: newValue.data?.map(item => item.rh.toFixed(2)),
  95. symbol: 'circle',
  96. symbolSize: 2,
  97. lineStyle: {
  98. color: '#32cd32',
  99. width: 1,
  100. },
  101. },
  102. {
  103. name: 'H₂O₂浓度',
  104. type: 'line',
  105. data: newValue.data?.map(item => item.h2o2.toFixed(2)),
  106. symbol: 'circle',
  107. symbolSize: 2,
  108. lineStyle: {
  109. color: '#ffd700',
  110. width: 1,
  111. },
  112. },
  113. {
  114. name: 'H₂O₂相对饱和度',
  115. type: 'line',
  116. data: newValue.data?.map(item => item.rs.toFixed(2)),
  117. symbol: 'circle',
  118. symbolSize: 2,
  119. lineStyle: {
  120. color: '#ff0000',
  121. width: 1,
  122. },
  123. },
  124. ],
  125. }
  126. myChart.setOption(option)
  127. myChart.resize()
  128. },
  129. {
  130. deep: true,
  131. },
  132. )
  133. const chartRef = ref<HTMLElement | null>(null)
  134. onMounted(() => {
  135. echarts.init(chartRef.value, null, { renderer: 'svg' })
  136. })
  137. </script>
  138. <template>
  139. <div ref="chartRef" style="height: 100%; width: 50%" />
  140. </template>
  141. <style scoped></style>