Explorar el Código

fix(User): 修复pH统计计算逻辑并更新显示文本

修正pH统计中面积占比计算逻辑,改为基于有pH数据的地块总面积计算
添加对无pH值数据的处理显示
更新界面文本从"乐昌县"改为"南雄"
yes-yes-yes-k hace 3 semanas
padre
commit
96a3c6729a
Se han modificado 1 ficheros con 12 adiciones y 9 borrados
  1. 12 9
      src/views/User/introduction/TotalIntroduction.vue

+ 12 - 9
src/views/User/introduction/TotalIntroduction.vue

@@ -236,12 +236,12 @@ function getPHComment(avgPH) {
       const numericPh = parsePHValue(feature.properties[config.phField])
       const area = parseFloat(feature.properties.area) || 0
       
-      // 累加总面积
+      // 累加总面积(所有地块)
       if (area > 0) {
         totalArea += area
       }
       
-      // 过滤无效 pH 值
+      // 过滤无效 pH 值,只统计有数据的地块
       if (numericPh && numericPh > 0 && !isNaN(numericPh)) {
         phCount++
         const delta = numericPh - avgPH;
@@ -264,10 +264,13 @@ function getPHComment(avgPH) {
       }
     });
 
-    // 计算面积占比
-    const strongAcidPercent = totalArea > 0 ? parseFloat(((strongAcidArea / totalArea) * 100).toFixed(2)) : 0
-    const mildAcidPercent = totalArea > 0 ? parseFloat(((mildAcidArea / totalArea) * 100).toFixed(2)) : 0
-    const normalPercent = totalArea > 0 ? parseFloat(((normalArea / totalArea) * 100).toFixed(2)) : 0
+    // 计算有 pH 数据的地块总面积(用于占比计算)
+    const totalPHArea = strongAcidArea + mildAcidArea + normalArea;
+    
+    // 计算面积占比(基于有 pH 数据的地块)
+    const strongAcidPercent = totalPHArea > 0 ? parseFloat(((strongAcidArea / totalPHArea) * 100).toFixed(2)) : 0
+    const mildAcidPercent = totalPHArea > 0 ? parseFloat(((mildAcidArea / totalPHArea) * 100).toFixed(2)) : 0
+    const normalPercent = totalPHArea > 0 ? parseFloat(((normalArea / totalPHArea) * 100).toFixed(2)) : 0
 
     statistics.value = {
       totalBlocks: samplePointsData.value.length,
@@ -482,7 +485,7 @@ onUnmounted(()=>{
      </div>
     <!-- pH 统计 -->
     <div class="statistics-panel">
-      <h4>📊 乐昌县土壤 pH 统计</h4>
+      <h4>📊 南雄土壤 pH 统计</h4>
       
       <div class="stat-row">
         <span class="stat-label">地块总数:</span>
@@ -616,13 +619,13 @@ onUnmounted(()=>{
         <div class="detail-row">
           <span class="detail-label">酸化程度:</span>
           <span :class="['detail-value', getPHLevelClass(selectedPoint.ph)]">
-            {{ selectedPoint.ph <= 5.2 ? '强酸性' : selectedPoint.ph < 6.0 ? '弱酸性' : '正常' }}
+            {{ !selectedPoint.ph || selectedPoint.ph <= 0 ? '无数据' : selectedPoint.ph <= 5.2 ? '强酸性' : selectedPoint.ph < 6.0 ? '弱酸性' : '正常' }}
           </span>
         </div>
         <div class="detail-row">
           <span class="detail-label">建议:</span>
           <span class="detail-suggestion">
-            {{ selectedPoint.ph <= 5.2 ? '立即治理,施用石灰改良' : selectedPoint.ph < 6.0 ? '注意保持,适量施用有机肥' : '继续保持当前管理措施' }}
+            {{ !selectedPoint.ph || selectedPoint.ph <= 0 ? '无数据' :selectedPoint.ph <= 5.2 ? '立即治理,施用石灰改良' : selectedPoint.ph < 6.0 ? '注意保持,适量施用有机肥' : '继续保持当前管理措施' }}
           </span>
         </div>
       </div>