statisticsInject.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import * as uecharts from "echarts";
  2. import { reactive } from "vue";
  3. import {
  4. StatisticsParams,
  5. getSceneStatistics,
  6. getCaseStatistics,
  7. getCameraTypeStatistics,
  8. getCaseTimeStatistics,
  9. getCasePlaceStatistics,
  10. getCaseReasonStatistics,
  11. } from "@/store/statistics";
  12. export const echarts = uecharts;
  13. export type { EChartsType } from "echarts";
  14. export type ConfigItem = {
  15. title: string;
  16. data: any;
  17. };
  18. export const statisticsConfigs: ConfigItem[] = reactive([
  19. {
  20. title: "火灾场景数据采集统计",
  21. data: {
  22. tooltip: {
  23. trigger: "item",
  24. },
  25. legend: {
  26. orient: "vertical",
  27. left: "right",
  28. type: "scroll",
  29. },
  30. series: [
  31. {
  32. itemStyle: {
  33. borderColor: "#fff",
  34. borderWidth: 3,
  35. },
  36. name: "火灾场景数据采集统计",
  37. type: "pie",
  38. label: {
  39. formatter: "{c}个",
  40. rich: {
  41. time: {
  42. fontSize: 10,
  43. color: "#999",
  44. },
  45. },
  46. },
  47. radius: "50%",
  48. center: ["40%", "50%"],
  49. data: [],
  50. },
  51. ],
  52. },
  53. },
  54. {
  55. title: "采集设备类型统计",
  56. data: {
  57. tooltip: {
  58. trigger: "axis",
  59. },
  60. xAxis: {
  61. type: "category",
  62. data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  63. },
  64. yAxis: {
  65. type: "value",
  66. },
  67. series: [
  68. {
  69. label: {
  70. show: true,
  71. },
  72. data: [120, 200, 150, 80, 70, 110, 130],
  73. type: "bar",
  74. },
  75. ],
  76. },
  77. },
  78. {
  79. title: "火灾场景数据采集统计",
  80. data: {
  81. tooltip: {
  82. trigger: "item",
  83. },
  84. legend: {
  85. orient: "vertical",
  86. left: "right",
  87. type: "scroll",
  88. // top: "center",
  89. },
  90. series: [
  91. {
  92. itemStyle: {
  93. borderColor: "#fff",
  94. borderWidth: 3,
  95. },
  96. name: "火灾场景数据采集统计",
  97. type: "pie",
  98. label: {
  99. formatter: "{d}%",
  100. rich: {
  101. time: {
  102. fontSize: 10,
  103. color: "#999",
  104. },
  105. },
  106. },
  107. radius: "50%",
  108. center: ["40%", "50%"],
  109. data: [],
  110. },
  111. ],
  112. },
  113. },
  114. {
  115. title: "火灾趋势分析",
  116. data: {
  117. tooltip: {
  118. trigger: "axis",
  119. },
  120. xAxis: {
  121. type: "category",
  122. data: [],
  123. },
  124. yAxis: {
  125. type: "value",
  126. },
  127. series: [
  128. {
  129. label: {
  130. show: true,
  131. },
  132. data: [],
  133. type: "line",
  134. },
  135. ],
  136. },
  137. },
  138. {
  139. title: "起火场所统计",
  140. data: {
  141. tooltip: {
  142. trigger: "axis",
  143. },
  144. xAxis: {
  145. type: "category",
  146. data: [],
  147. },
  148. yAxis: {
  149. type: "value",
  150. },
  151. series: [
  152. {
  153. label: {
  154. show: true,
  155. },
  156. data: [],
  157. type: "bar",
  158. },
  159. ],
  160. },
  161. },
  162. {
  163. title: "火灾原因统计",
  164. data: {
  165. tooltip: {
  166. trigger: "axis",
  167. },
  168. xAxis: {
  169. type: "category",
  170. data: [],
  171. },
  172. yAxis: {
  173. type: "value",
  174. },
  175. series: [
  176. {
  177. label: {
  178. show: true,
  179. },
  180. data: [],
  181. type: "bar",
  182. },
  183. ],
  184. },
  185. },
  186. ]);
  187. const numRotate = 8;
  188. const numSlide = 20;
  189. export const updateParams = async (params: StatisticsParams) => {
  190. const statisticsItemsArray = await Promise.all([
  191. getSceneStatistics(params),
  192. getCameraTypeStatistics(params),
  193. getCaseStatistics(params),
  194. getCaseTimeStatistics(params),
  195. getCasePlaceStatistics(params),
  196. getCaseReasonStatistics(params),
  197. ]);
  198. const radiusNds = [0, 2];
  199. for (let ndx = 0; ndx < statisticsConfigs.length; ndx++) {
  200. let items = statisticsItemsArray[ndx];
  201. if (radiusNds.includes(ndx)) {
  202. statisticsConfigs[ndx].data.series![0].data = items.map((item) => ({
  203. value: item.dataCount,
  204. name: item.groupKey,
  205. }));
  206. console.log(statisticsConfigs[ndx].data);
  207. } else {
  208. statisticsConfigs[ndx].data.xAxis.data = items.map(
  209. (item) => item.groupKey
  210. );
  211. statisticsConfigs[ndx].data.xAxis.axisLabel = {
  212. interval: "auto",
  213. rotate: 0,
  214. };
  215. statisticsConfigs[ndx].data.dataZoom = [
  216. {
  217. id: 1,
  218. type: "inside",
  219. start: 0,
  220. end: 100,
  221. disabled: true,
  222. zoomLock: true,
  223. show: false,
  224. },
  225. {
  226. id: 2,
  227. start: 0,
  228. end: 100,
  229. disabled: true,
  230. zoomLock: true,
  231. show: false,
  232. },
  233. ];
  234. if (items.length > numRotate && items.length < numSlide) {
  235. statisticsConfigs[ndx].data.xAxis.axisLabel = {
  236. interval: 0,
  237. rotate: 30,
  238. };
  239. } else if (items.length >= numSlide) {
  240. statisticsConfigs[ndx].data.dataZoom = [
  241. {
  242. id: 1,
  243. type: "inside",
  244. start: 0,
  245. end: 100,
  246. disabled: false,
  247. zoomLock: false,
  248. show: true,
  249. },
  250. {
  251. id: 2,
  252. start: 0,
  253. end: 100,
  254. disabled: false,
  255. zoomLock: false,
  256. show: true,
  257. },
  258. ];
  259. }
  260. statisticsConfigs[ndx].data.series![0].data = items.map(
  261. (item) => item.dataCount
  262. );
  263. }
  264. }
  265. };