Преглед изворни кода

refactor(stationProfile/runData): 优化日均扣押面积数据处理逻辑

重构了rawData的分组和日期对齐逻辑,先按日期和分组名初始化数据结构,再填充具体数值,修复可能的数据错位问题,提升代码可读性和可维护性
huoyi пре 3 недеља
родитељ
комит
24788cccb0
1 измењених фајлова са 16 додато и 7 уклоњено
  1. 16 7
      src/views/portraitManagement/stationProfile/component/runData.vue

+ 16 - 7
src/views/portraitManagement/stationProfile/component/runData.vue

@@ -426,15 +426,24 @@ const initDailySeizedArea = () => {
426 426
   }
427 427
   const rawData = countSeizureSingleQuantityData.value
428 428
   if (!rawData || rawData.length === 0) return
429
+
430
+  const dates = [...new Set(rawData.map(item => item.recordDate))].sort()
431
+  const groupNames = [...new Set(rawData.flatMap(d => d.items.map(i => i.groupName)))]
432
+
429 433
   const groupMap = {}
430
-  rawData.forEach(item => {
431
-    if (!groupMap[item.groupName]) {
432
-      groupMap[item.groupName] = []
433
-    }
434
-    groupMap[item.groupName].push(item.seizeQuantity)
434
+  groupNames.forEach(name => {
435
+    groupMap[name] = new Array(dates.length).fill(0)
435 436
   })
436
-  const groupNames = Object.keys(groupMap)
437
-  const dates = [...new Set(rawData.map(item => item.recordDate))]
437
+
438
+  rawData.forEach(record => {
439
+    const dateIndex = dates.indexOf(record.recordDate)
440
+    record.items.forEach(item => {
441
+      if (groupMap[item.groupName] && dateIndex >= 0) {
442
+        groupMap[item.groupName][dateIndex] = item.seizeQuantity
443
+      }
444
+    })
445
+  })
446
+
438 447
   const countryColors = ['#4da6ff', '#7eff7e', '#bd03fb', '#ffd93d', '#ff6b6b', '#00f5ff', '#ffa500', '#71B138']
439 448
   const series = groupNames.map((name, idx) => {
440 449
     const color = countryColors[idx % countryColors.length]