index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div class="eventStat">
  3. <div class="eventStat-header">
  4. <el-card>
  5. <template #header>
  6. <div class="event-category">
  7. <span>监控点位违反统计</span>
  8. <el-radio-group v-model="eventDateType" @change="getBarData" size="small">
  9. <el-radio-button label="今天" value="1" />
  10. <el-radio-button label="近7天" value="7" />
  11. <el-radio-button label="近30天" value="30" />
  12. </el-radio-group>
  13. </div>
  14. </template>
  15. <BaseChart width="100%" height="250px" :option="barOptions" />
  16. </el-card>
  17. <el-card>
  18. <template #header>
  19. <div class="event-category">
  20. <span>区域违法分布</span>
  21. <el-radio-group v-model="regionDateType" @change="getPieData" size="small">
  22. <el-radio-button label="今天" value="1" />
  23. <el-radio-button label="近7天" value="7" />
  24. <el-radio-button label="近30天" value="30" />
  25. </el-radio-group>
  26. </div>
  27. </template>
  28. <BaseChart width="100%" height="250px" :option="pieOptions" />
  29. </el-card>
  30. </div>
  31. <el-card style="margin-top: 10px;">
  32. <template #header>
  33. <div class="event-category">
  34. <span>每分钟{{ formatDict(eventType) }}统计</span>
  35. <el-select v-model="eventType" @change="getLineData">
  36. <el-option v-for="item in eventTypeOptions" :key="item.dictValue" :label="item.dictLabel"
  37. :value="item.dictValue" />
  38. </el-select>
  39. </div>
  40. </template>
  41. <BaseChart width="100%" height="250px" :option="lineOptions" />
  42. </el-card>
  43. </div>
  44. </template>
  45. <script setup lang="ts">
  46. import BaseChart from '@/components/BaseChart/index.vue'
  47. import { pointEventsStat, regionEventsStat, minuteEventsStat } from '@/api/sense/events/index'
  48. import { getDicts } from '@/api/system/dict/data/index'
  49. const pieData = ref([])
  50. const barData = ref([])
  51. const lineData = ref([])
  52. const eventTypeOptions = ref([])
  53. const eventType = ref('1')
  54. const eventDateType = ref('1')
  55. const regionDateType = ref('1')
  56. const pieOptions = computed(() => {
  57. let options = {
  58. tooltip: {
  59. trigger: 'item'
  60. },
  61. legend: {
  62. orient: 'vertical',
  63. top: '8%',
  64. right: 0,
  65. itemWidth: 10,
  66. itemHeight: 10,
  67. itemGap: 10
  68. },
  69. grid: {
  70. },
  71. series: [
  72. {
  73. type: 'pie',
  74. radius: '50%',
  75. data: pieData.value,
  76. center: ['40%', '50%'],
  77. emphasis: {
  78. itemStyle: {
  79. shadowBlur: 10,
  80. shadowOffsetX: 0,
  81. shadowColor: 'rgba(0, 0, 0, 0.5)'
  82. }
  83. }
  84. }
  85. ]
  86. };
  87. return options
  88. })
  89. const barOptions = computed(() => {
  90. const colors = [
  91. "#FF5733",
  92. "#7B3F00",
  93. "#FFC300",
  94. "#DAF7A6",
  95. "#FF5733",
  96. "#008080",
  97. "#E8EAF6",
  98. "#FFEEC1",
  99. "#B39DDB",
  100. "#4CAF50"
  101. ];
  102. const barObj = {}
  103. barData.value.forEach(item => {
  104. barObj[item.area_name] = item.event_count
  105. })
  106. let options = {
  107. tooltip: {
  108. trigger: 'axis',
  109. axisPointer: {
  110. type: 'shadow'
  111. }
  112. },
  113. grid: {
  114. left: '5%',
  115. right: '3%',
  116. bottom: 0,
  117. top: '6%',
  118. containLabel: true
  119. },
  120. xAxis: {
  121. type: 'category',
  122. data: Object.keys(barObj),
  123. axisLabel: {
  124. interval: 0,
  125. // rotate: 15 // 表示倾斜的角度
  126. }
  127. },
  128. yAxis: {
  129. type: 'value'
  130. },
  131. series: [
  132. {
  133. data: Object.values(barObj),
  134. type: 'bar',
  135. barWidth: 20,
  136. itemStyle: {
  137. color: (params) => {
  138. return colors[params.dataIndex]
  139. }
  140. },
  141. label: {
  142. show: true, // 显示数值
  143. position: 'top' // 在顶部显示
  144. }
  145. }
  146. ]
  147. };
  148. return options
  149. })
  150. const lineOptions = computed(() => {
  151. const xData = lineData.value.map(item => item.time_format)
  152. const yData = lineData.value.map(item => item.count)
  153. const options = {
  154. tooltip: {
  155. trigger: 'axis',
  156. appendToBody: true
  157. },
  158. grid: {
  159. left: '1%',
  160. right: '3%',
  161. bottom: 0,
  162. top: '22%',
  163. containLabel: true
  164. },
  165. xAxis: {
  166. type: 'category',
  167. axisLabel: {
  168. show: true,
  169. // interval: 0,//横轴信息全部显示
  170. // margin: 5, //刻度标签与轴线之间的距离
  171. },
  172. data: xData
  173. },
  174. yAxis: {
  175. type: 'value'
  176. },
  177. series: [
  178. // {
  179. // name: '',
  180. // type: 'line',
  181. // symbol: 'circle', // 默认是空心圆(中间是白色的),改成实心圆
  182. // showAllSymbol: true,
  183. // symbolSize: 0,
  184. // data: yData
  185. // }
  186. {
  187. name: '',
  188. data: yData,
  189. type: 'pictorialBar',
  190. barMinHeight: 50,
  191. barCategoryGap: '80%',
  192. symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
  193. itemStyle: {
  194. normal: {
  195. color: '#65B1E9'
  196. }
  197. },
  198. },
  199. ]
  200. };
  201. return options
  202. })
  203. onMounted(() => {
  204. getPieData()
  205. getBarData()
  206. getLineData()
  207. getDicts('event_type').then(({ code, data }) => {
  208. if (code === 200) {
  209. eventTypeOptions.value = data || []
  210. }
  211. })
  212. })
  213. const getPieData = () => {
  214. regionEventsStat({ dateType: regionDateType.value }).then(({ code, data }) => {
  215. if (code === 200) {
  216. pieData.value = data || []
  217. }
  218. })
  219. }
  220. const getBarData = () => {
  221. pointEventsStat({ dateType: eventDateType.value }).then(({ code, data }) => {
  222. if (code === 200) {
  223. barData.value = data || []
  224. }
  225. })
  226. }
  227. const getLineData = () => {
  228. minuteEventsStat({ eventType: eventType.value }).then(({ code, data }) => {
  229. if (code === 200) {
  230. lineData.value = data || {}
  231. }
  232. })
  233. }
  234. const formatDict = (val) => {
  235. let name = ''
  236. eventTypeOptions.value.forEach(item => {
  237. if (item.dictValue === val) {
  238. name = item.dictLabel
  239. }
  240. })
  241. return name
  242. }
  243. </script>
  244. <style lang="scss" scoped>
  245. .eventStat {
  246. padding: 10px;
  247. height: 100%;
  248. background-color: #F0F2F5;
  249. position: relative;
  250. }
  251. .event-category {
  252. display: flex;
  253. align-items: center;
  254. justify-content: space-between;
  255. .el-select {
  256. width: 250px;
  257. }
  258. }
  259. .eventStat-header {
  260. display: flex;
  261. .el-card {
  262. flex: 1;
  263. &:not(:first-child) {
  264. margin-left: 10px;
  265. }
  266. }
  267. }
  268. </style>