eventList.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 weekDays = [];
  39. const option = {
  40. xAxis: {
  41. type: 'category',
  42. data: weekDays,
  43. axisLabel: {
  44. color: '#fff'
  45. },
  46. },
  47. tooltip: {
  48. trigger: 'axis',
  49. axisPointer: {
  50. type: 'cross',
  51. crossStyle: {
  52. color: '#999'
  53. }
  54. }
  55. },
  56. grid: {
  57. top: '10%',
  58. bottom: '10%',
  59. right: '0%',
  60. },
  61. yAxis: {
  62. type: 'value',
  63. axisLabel: {
  64. show: true,
  65. color: '#fff'
  66. },
  67. splitLine: {
  68. show: false,
  69. lineStyle: {
  70. color: '#44585e'
  71. }
  72. },
  73. axisTick: {
  74. show: false
  75. },
  76. },
  77. series: [
  78. // 仅保留曲线表示运行异常
  79. {
  80. name: '超载预警次数',
  81. type: 'line',
  82. // data: generateRandomData(7, 50),
  83. data: [],
  84. lineStyle: {
  85. color: '#3b90d7',
  86. },
  87. showSymbol: false,
  88. smooth: true,
  89. areaStyle: {
  90. color: new echarts.graphic.LinearGradient(
  91. 0,
  92. 0,
  93. 0,
  94. 1,
  95. [{
  96. offset: 0,
  97. color: 'rgba(59,144,215, .6)',
  98. },
  99. {
  100. offset: 0.8,
  101. color: 'rgba(59,144,215, .2)',
  102. },
  103. ],
  104. false
  105. ),
  106. shadowColor: 'rgba(0, 0, 0, 0.1)',
  107. shadowBlur: 10,
  108. },
  109. }
  110. ]
  111. };
  112. chart.setOption(option);
  113. }
  114. window.addEventListener('resize', handleResize);
  115. });
  116. watch(() => props.resultData, (newVal) => {
  117. if (chart) {
  118. chart.setOption({
  119. xAxis: {
  120. data: Object.keys(newVal),
  121. },
  122. series: [{
  123. type: 'line',
  124. data: Object.entries(newVal),
  125. }],
  126. })
  127. }
  128. }, { deep: true, immediate: true } // 开启深度监听
  129. )
  130. onUnmounted(() => {
  131. window.removeEventListener('resize', handleResize);
  132. if (chart) {
  133. chart.dispose();
  134. }
  135. });
  136. </script>
  137. <style lang="scss">
  138. ._divider {
  139. height: 1px;
  140. border: 1px dashed #168cdb;
  141. flex: 1;
  142. margin: 0 10px;
  143. }
  144. ._consume {
  145. display: flex;
  146. flex-direction: column;
  147. &_mains {
  148. margin: 10px 30px;
  149. flex: 1;
  150. display: flex;
  151. &_item {
  152. display: flex;
  153. justify-content: space-between;
  154. align-items: center;
  155. padding: 10px;
  156. &_name {
  157. width: 30px;
  158. height: 30px;
  159. background: url("@/assets/images/content_circle_num.png");
  160. background-size: 100% 100%;
  161. background-position: center;
  162. background-repeat: no-repeat;
  163. // animation: scanning 4s linear infinite;
  164. border: 1px solid red;
  165. }
  166. &_flag {
  167. display: flex;
  168. align-items: center;
  169. gap: 3px;
  170. &_item {
  171. width: 30px;
  172. height: 30px;
  173. border: 3px dashed #168cdb;
  174. box-sizing: border-box;
  175. background: #0e6ead;
  176. color: #fff;
  177. border-radius: 50%;
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. font-size: 14px;
  182. }
  183. }
  184. }
  185. &_item:hover {
  186. cursor: pointer;
  187. background-image: linear-gradient(to right, #168cdb, transparent);
  188. }
  189. }
  190. }
  191. </style>