carbonEmission.vue 6.9 KB

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