Forráskód Böngészése

接口位置修复

yes-yes-yes-k 3 hónapja
szülő
commit
b1a44074c0

+ 24 - 6
src/components/soilcdStatistics/cropcdStatictics.vue

@@ -49,6 +49,7 @@
 import { ref, onMounted, watch, nextTick } from 'vue';
 import * as echarts from 'echarts';
 import axios from 'axios';
+import {api8000} from '@/utils/request'
 
 
 // 图表实例引用
@@ -124,15 +125,32 @@ const fieldConfig = {
 };
 
 
-// 数据请求(作物态Cd接口)
+// 数据请求 - 增强错误处理和调试
 const fetchData = async () => {
   try {
-    const apiUrl = 'http://localhost:8000/api/vector/stats/CropCd_input_data';
-    const response = await axios.get(apiUrl);
-    console.log("接口原始返回:", response.data);
-    return response.data.data;
+    isLoading.value = true;
+    const apiUrl = '/api/vector/stats/CropCd_input_data';
+    console.log('正在请求数据:', apiUrl);
+    
+    const response = await api8000.get(apiUrl);
+    console.log('API响应:', response);
+    
+    // 调试:输出响应结构
+    console.log('响应数据:', response.data);
+    
+    // 处理不同的响应格式
+    let processedData;
+    processedData = response.data.data;
+    
+    if (!processedData) {
+      throw new Error('无法解析API返回的数据结构');
+    }
+    
+    console.log('处理后的数据:', processedData);
+    return processedData;
   } catch (err) {
-    throw new Error('数据加载失败: ' + err.message);
+    console.error('数据请求失败:', err);
+    throw new Error(`数据加载失败: ${err.message || '网络或服务器错误'}`);
   }
 };
 

+ 23 - 6
src/components/soilcdStatistics/effcdStatistics.vue

@@ -47,6 +47,7 @@
 import { ref, onMounted, watch, nextTick } from 'vue';
 import * as echarts from 'echarts';
 import axios from 'axios';
+import {api8000} from '@/utils/request'
 
 // 图表实例引用
 const cdBarChart = ref(null);
@@ -103,15 +104,31 @@ const fieldConfig = {
 };
 
 
-// 数据请求
 const fetchData = async () => {
   try {
-    // 实际项目中替换为真实API
-     const res = await axios.get("http://localhost:8000/api/vector/stats/EffCd_input_data");
-     return res.data.data;
-
+    isLoading.value = true;
+    const apiUrl = '/api/vector/stats/EffCd_input_data';
+    console.log('正在请求数据:', apiUrl);
+    
+    const response = await api8000.get(apiUrl);
+    console.log('API响应:', response);
+    
+    // 调试:输出响应结构
+    console.log('响应数据:', response.data);
+    
+    // 处理不同的响应格式
+    let processedData;
+    processedData = response.data.data;
+    
+    if (!processedData) {
+      throw new Error('无法解析API返回的数据结构');
+    }
+    
+    console.log('处理后的数据:', processedData);
+    return processedData;
   } catch (err) {
-    throw new Error('数据加载失败: ' + err.message);
+    console.error('数据请求失败:', err);
+    throw new Error(`数据加载失败: ${err.message || '网络或服务器错误'}`);
   }
 };
 

+ 24 - 23
src/components/soilcdStatistics/fluxcdStatictics.vue

@@ -56,6 +56,7 @@
 import { ref, onMounted, nextTick } from 'vue';
 import * as echarts from 'echarts';
 import axios from 'axios';
+import {api8000} from '@/utils/request'
 
 // 图表容器 & 实例
 const initialCdChart = ref(null);   // 初始Cd图表
@@ -89,35 +90,35 @@ const fieldConfig = {
   ]
 };
 
-// 数据请求
+// 数据请求 - 增强错误处理和调试
 const fetchData = async () => {
   try {
-    const apiUrl = 'http://localhost:8000/api/vector/stats/FluxCd_input_data';
-    const response = await axios.get(apiUrl);
-    const rawData = response.data.features 
-      ? response.data.features.map(f => f.properties) 
-      : response.data.data;
-    return rawData;
+    isLoading.value = true;
+    const apiUrl = '/api/vector/stats/FluxCd_input_data';
+    console.log('正在请求数据:', apiUrl);
+    
+    const response = await api8000.get(apiUrl);
+    console.log('API响应:', response);
+    
+    // 调试:输出响应结构
+    console.log('响应数据:', response.data);
+    
+    // 处理不同的响应格式
+    let processedData;
+    processedData = response.data.data;
+    
+    if (!processedData) {
+      throw new Error('无法解析API返回的数据结构');
+    }
+    
+    console.log('处理后的数据:', processedData);
+    return processedData;
   } catch (err) {
-    throw new Error('数据加载失败: ' + err.message);
+    console.error('数据请求失败:', err);
+    throw new Error(`数据加载失败: ${err.message || '网络或服务器错误'}`);
   }
 };
 
-// 分位数计算(QUARTILE.INC)
-const calculatePercentile = (sortedArray, percentile) => {
-  const n = sortedArray.length;
-  if (n === 0) return null;
-  if (percentile <= 0) return sortedArray[0];
-  if (percentile >= 100) return sortedArray[n - 1];
-  
-  const index = (n - 1) * (percentile / 100);
-  const lowerIndex = Math.floor(index);
-  const upperIndex = lowerIndex + 1;
-  const fraction = index - lowerIndex;
-  
-  if (upperIndex >= n) return sortedArray[lowerIndex];
-  return sortedArray[lowerIndex] + fraction * (sortedArray[upperIndex] - sortedArray[lowerIndex]);
-};
 
 // 计算单个字段的统计量
 const calculateFieldStats = (statsData, fieldKey, fieldName) => {