|
|
@@ -85,7 +85,6 @@ const fieldConfig = {
|
|
|
]
|
|
|
};
|
|
|
|
|
|
-// 数据请求 - 增强错误处理和调试
|
|
|
const fetchData = async () => {
|
|
|
try {
|
|
|
isLoading.value = true;
|
|
|
@@ -100,24 +99,7 @@ const fetchData = async () => {
|
|
|
|
|
|
// 处理不同的响应格式
|
|
|
let processedData;
|
|
|
- if (response.data && typeof response.data === 'object') {
|
|
|
- // 情况1: 直接返回统计对象
|
|
|
- if (response.data.Initial_Cd || response.data.DQCJ_Cd) {
|
|
|
- processedData = response.data;
|
|
|
- }
|
|
|
- // 情况2: 包含features数组
|
|
|
- else if (response.data.features && Array.isArray(response.data.features)) {
|
|
|
- processedData = response.data.features.map(f => f.properties);
|
|
|
- }
|
|
|
- // 情况3: 包含data数组
|
|
|
- else if (response.data.data && Array.isArray(response.data.data)) {
|
|
|
- processedData = response.data.data;
|
|
|
- }
|
|
|
- // 情况4: 数组直接返回
|
|
|
- else if (Array.isArray(response.data)) {
|
|
|
- processedData = response.data;
|
|
|
- }
|
|
|
- }
|
|
|
+ processedData = response.data.data;
|
|
|
|
|
|
if (!processedData) {
|
|
|
throw new Error('无法解析API返回的数据结构');
|
|
|
@@ -131,44 +113,33 @@ const fetchData = async () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 计算统计量 - 支持原始数据和预统计数据
|
|
|
-const calculateFieldStats = (data, fieldKey, fieldName) => {
|
|
|
- // 如果已经是预统计好的数据
|
|
|
- if (data[fieldKey] && typeof data[fieldKey] === 'object') {
|
|
|
- const fieldStats = data[fieldKey];
|
|
|
- return {
|
|
|
- key: fieldKey,
|
|
|
- name: fieldName,
|
|
|
- min: fieldStats.min || null,
|
|
|
- q1: fieldStats.q1 || null,
|
|
|
- median: fieldStats.median || null,
|
|
|
- q3: fieldStats.q3 || null,
|
|
|
- max: fieldStats.max || null,
|
|
|
- count: fieldStats.count || 0
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- // 如果是原始数据数组,需要手动计算统计量
|
|
|
- if (Array.isArray(data)) {
|
|
|
- const values = data
|
|
|
- .map(item => parseFloat(item[fieldKey]))
|
|
|
- .filter(val => !isNaN(val) && val !== null);
|
|
|
-
|
|
|
- if (values.length === 0) {
|
|
|
- return { key: fieldKey, name: fieldName, min: null, q1: null, median: null, q3: null, max: null, count: 0 };
|
|
|
- }
|
|
|
-
|
|
|
- values.sort((a, b) => a - b);
|
|
|
- const min = values[0];
|
|
|
- const max = values[values.length - 1];
|
|
|
- const median = values[Math.floor(values.length / 2)];
|
|
|
- const q1 = values[Math.floor(values.length / 4)];
|
|
|
- const q3 = values[Math.floor(values.length * 3 / 4)];
|
|
|
-
|
|
|
- return { key: fieldKey, name: fieldName, min, q1, median, q3, max, count: values.length };
|
|
|
+
|
|
|
+// 计算单个字段的统计量
|
|
|
+const calculateFieldStats = (statsData, fieldKey, fieldName) => {
|
|
|
+ // 从接口数据中获取当前字段的统计结果
|
|
|
+ const fieldStats = statsData[fieldKey];
|
|
|
+ if (!fieldStats) {
|
|
|
+ return { key: fieldKey, name: fieldName, min: null, q1: null, median: null, q3: null, max: null };
|
|
|
}
|
|
|
-
|
|
|
- return { key: fieldKey, name: fieldName, min: null, q1: null, median: null, q3: null, max: null, count: 0 };
|
|
|
+
|
|
|
+ // 提取预统计值
|
|
|
+ let min = fieldStats.min;
|
|
|
+ let q1 = fieldStats.q1;
|
|
|
+ let median = fieldStats.median;
|
|
|
+ let q3 = fieldStats.q3;
|
|
|
+ let max = fieldStats.max;
|
|
|
+
|
|
|
+ // 强制校正统计量顺序(确保 min ≤ q1 ≤ median ≤ q3 ≤ max)
|
|
|
+ const sortedStats = [min, q1, median, q3, max].sort((a, b) => a - b);
|
|
|
+ return {
|
|
|
+ key: fieldKey,
|
|
|
+ name: fieldName,
|
|
|
+ min: sortedStats[0],
|
|
|
+ q1: sortedStats[1],
|
|
|
+ median: sortedStats[2],
|
|
|
+ q3: sortedStats[3],
|
|
|
+ max: sortedStats[4]
|
|
|
+ };
|
|
|
};
|
|
|
|
|
|
// 计算所有统计数据
|