消毒机设备
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.

80 lines
1.6 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
4 weeks ago
3 weeks ago
  1. <script lang="ts" setup>
  2. import { useSealStore } from '@/stores/sealStore'
  3. import * as echarts from 'echarts'
  4. import { onUnmounted, ref, watchEffect } from 'vue'
  5. const sealStore = useSealStore()
  6. const chartRef = ref<HTMLElement | null>(null)
  7. const realTimePressure = ref(sealStore.sealInfo.pressure)
  8. let myChart: echarts.ECharts | null = null
  9. watchEffect(() => {
  10. realTimePressure.value = sealStore.sealInfo.pressure
  11. const pressure = sealStore.sealInfo?.pressure || 0
  12. if (!myChart && chartRef.value) {
  13. initChart() // 首次初始化图表
  14. }
  15. if (myChart) {
  16. myChart.setOption({
  17. series: [{
  18. data: [{ value: pressure }],
  19. }],
  20. })
  21. }
  22. })
  23. const initChart = () => {
  24. if (!chartRef.value) {
  25. return
  26. }
  27. myChart = echarts.init(chartRef.value)
  28. const option = {
  29. tooltip: {
  30. formatter: '{a} <br/>{b} : {c}%',
  31. },
  32. series: [
  33. {
  34. name: 'Pressure',
  35. type: 'gauge',
  36. max: 6,
  37. progress: {
  38. show: true,
  39. width: 5,
  40. },
  41. axisLine: {
  42. lineStyle: {
  43. width: 5,
  44. },
  45. },
  46. detail: {
  47. valueAnimation: true,
  48. formatter: '{value}Kp',
  49. },
  50. data: [
  51. {
  52. value: realTimePressure.value,
  53. },
  54. ],
  55. },
  56. ],
  57. }
  58. myChart.setOption(option)
  59. }
  60. // 组件卸载时释放资源
  61. onUnmounted(() => {
  62. if (myChart) {
  63. myChart.dispose() // 销毁图表实例
  64. myChart = null
  65. }
  66. })
  67. </script>
  68. <template>
  69. <div ref="chartRef" style="width: 40vw; height: 30vw" />
  70. </template>
  71. <style>
  72. canvas{
  73. width: 60vw !important;
  74. height: 70vh !important;
  75. }
  76. </style>