sameDay.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div class="_consume">
  3. <HeadlineTag type="right" value="异常震动(周)"></HeadlineTag>
  4. <div class="_consume_mains">
  5. <div ref="chartRef" style="width: 100%; height: 100%;"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script setup>
  10. import { ref, onMounted, onUnmounted } from 'vue';
  11. import * as echarts from 'echarts';
  12. import HeadlineTag from '@/components/HeadlineTag';
  13. const props = defineProps({
  14. resultData: {
  15. type: Object,
  16. default: {}
  17. }
  18. })
  19. const chartRef = ref(null);
  20. let chart = null;
  21. const generateRandomData = (length, max) => {
  22. const randomData = [];
  23. for (let i = 0; i < length; i++) {
  24. randomData.push(Math.floor(Math.random() * max));
  25. }
  26. return randomData;
  27. };
  28. const handleResize = () => {
  29. if (chart) {
  30. chart.resize();
  31. }
  32. };
  33. onMounted(() => {
  34. if (chartRef.value) {
  35. chart = echarts.init(chartRef.value);
  36. // 生成一周的日期数据
  37. const weekDays = [];
  38. const option = {
  39. xAxis: {
  40. type: 'category',
  41. data: weekDays,
  42. axisLabel: {
  43. color: '#fff'
  44. },
  45. },
  46. tooltip: {
  47. trigger: 'axis',
  48. axisPointer: {
  49. type: 'cross',
  50. crossStyle: {
  51. color: '#999'
  52. }
  53. },
  54. textStyle: {
  55. color: '#fafafa',
  56. },
  57. borderColor: 'transparent',
  58. backgroundColor: 'rgba(0, 0, 0, 0.5)',
  59. extraCssText: 'backdrop-filter: blur(6px);',
  60. },
  61. grid: {
  62. top: '10%',
  63. bottom: '10%',
  64. right: '0%',
  65. },
  66. yAxis: {
  67. type: 'value',
  68. axisLabel: {
  69. show: true,
  70. color: '#fff'
  71. },
  72. splitLine: {
  73. show: false,
  74. lineStyle: {
  75. color: '#44585e'
  76. }
  77. },
  78. axisTick: {
  79. show: false
  80. },
  81. },
  82. series: [
  83. // 仅保留曲线表示运行异常
  84. {
  85. name: '异常震动次数',
  86. type: 'line',
  87. // data: generateRandomData(7, 50),
  88. data: [],
  89. lineStyle: {
  90. color: '#de4337',
  91. },
  92. showSymbol: false,
  93. smooth: true,
  94. areaStyle: {
  95. color: new echarts.graphic.LinearGradient(
  96. 0,
  97. 0,
  98. 0,
  99. 1,
  100. [{
  101. offset: 0,
  102. color: 'rgba(222, 67, 55, .6)',
  103. },
  104. {
  105. offset: 0.8,
  106. color: 'rgba(222, 67, 55, .2)',
  107. },
  108. ],
  109. false
  110. ),
  111. shadowColor: 'rgba(0, 0, 0, 0.1)',
  112. shadowBlur: 10,
  113. },
  114. }
  115. ]
  116. };
  117. chart.setOption(option);
  118. }
  119. window.addEventListener('resize', handleResize);
  120. });
  121. watch(() => props.resultData, (newVal) => {
  122. if (chart) {
  123. chart.setOption({
  124. xAxis: {
  125. data: Object.keys(newVal),
  126. },
  127. series: [{
  128. type: 'line',
  129. data: Object.entries(newVal),
  130. }],
  131. })
  132. }
  133. }, { deep: true, immediate: true } // 开启深度监听
  134. )
  135. onUnmounted(() => {
  136. window.removeEventListener('resize', handleResize);
  137. if (chart) {
  138. chart.dispose();
  139. }
  140. });
  141. </script>
  142. <style lang="scss">
  143. ._divider {
  144. height: 1px;
  145. border: 1px dashed #168cdb;
  146. flex: 1;
  147. margin: 0 10px;
  148. }
  149. ._consume {
  150. display: flex;
  151. flex-direction: column;
  152. &_mains {
  153. margin: 10px 30px;
  154. flex: 1;
  155. display: flex;
  156. &_item {
  157. display: flex;
  158. justify-content: space-between;
  159. align-items: center;
  160. padding: 10px;
  161. &_name {
  162. width: 30px;
  163. height: 30px;
  164. background: url("@/assets/images/content_circle_num.png");
  165. background-size: 100% 100%;
  166. background-position: center;
  167. background-repeat: no-repeat;
  168. // animation: scanning 4s linear infinite;
  169. border: 1px solid red;
  170. }
  171. &_flag {
  172. display: flex;
  173. align-items: center;
  174. gap: 3px;
  175. &_item {
  176. width: 30px;
  177. height: 30px;
  178. border: 3px dashed #168cdb;
  179. box-sizing: border-box;
  180. background: #0e6ead;
  181. color: #fff;
  182. border-radius: 50%;
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. font-size: 14px;
  187. }
  188. }
  189. }
  190. &_item:hover {
  191. cursor: pointer;
  192. background-image: linear-gradient(to right, #168cdb, transparent);
  193. }
  194. }
  195. }
  196. </style>