|
|
@@ -232,6 +232,7 @@
|
|
|
import { reactive, ref, nextTick, onMounted, onUnmounted, computed } from "vue";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
import type { FormInstance } from "element-plus";
|
|
|
+import { api8000 } from "@/utils/request";
|
|
|
|
|
|
// 新增:反酸预测相关状态(区分降酸/反酸的显示)
|
|
|
const showInversionPrediction = ref(false); // 控制反酸预测区域显示
|
|
|
@@ -317,7 +318,7 @@ const acidInversionRules = reactive({
|
|
|
{ required: true, message: '请输入NO3', trigger: 'change' },
|
|
|
{ type: 'number', message: '请输入有效数字', trigger: 'change' },
|
|
|
{
|
|
|
- validator: (rule: any, value: number, callback: any) => {
|
|
|
+ validator: (_rule: any, value: number, callback: any) => {
|
|
|
if (value < 0) {
|
|
|
callback(new Error('值不能为负数'));
|
|
|
} else {
|
|
|
@@ -331,7 +332,7 @@ const acidInversionRules = reactive({
|
|
|
{ required: true, message: '请输入NH4', trigger: 'change' },
|
|
|
{ type: 'number', message: '请输入有效数字', trigger: 'change' },
|
|
|
{
|
|
|
- validator: (rule: any, value: number, callback: any) => {
|
|
|
+ validator: (_rule: any, value: number, callback: any) => {
|
|
|
if (value < 0) {
|
|
|
callback(new Error('值不能为负数'));
|
|
|
} else {
|
|
|
@@ -360,7 +361,7 @@ const acidReductionRules = reactive({
|
|
|
{ required: true, message: '请输入目标pH值', trigger: 'blur' },
|
|
|
{ type: 'number', message: '请输入有效数字', trigger: 'blur' },
|
|
|
{
|
|
|
- validator: (rule: any, value: number, callback: any) => {
|
|
|
+ validator: (_rule: any, value: number, callback: any) => {
|
|
|
if (value < 0 || value > 14) {
|
|
|
callback(new Error('值范围在0-14之间'));
|
|
|
} else {
|
|
|
@@ -374,7 +375,7 @@ const acidReductionRules = reactive({
|
|
|
{ required: true, message: '请输入NO3', trigger: 'blur' },
|
|
|
{ type: 'number', message: '请输入有效数字', trigger: 'blur' },
|
|
|
{
|
|
|
- validator: (rule: any, value: number, callback: any) => {
|
|
|
+ validator: (_rule: any, value: number, callback: any) => {
|
|
|
if (value < 0) {
|
|
|
callback(new Error('值不能为负数'));
|
|
|
} else {
|
|
|
@@ -388,7 +389,7 @@ const acidReductionRules = reactive({
|
|
|
{ required: true, message: '请输入NH4', trigger: 'blur' },
|
|
|
{ type: 'number', message: '请输入有效数字', trigger: 'blur' },
|
|
|
{
|
|
|
- validator: (rule: any, value: number, callback: any) => {
|
|
|
+ validator: (_rule: any, value: number, callback: any) => {
|
|
|
if (value < 0) {
|
|
|
callback(new Error('值不能为负数'));
|
|
|
} else {
|
|
|
@@ -510,7 +511,7 @@ const drawHighlightFeature = (geoJsonFeature: any) => {
|
|
|
};
|
|
|
|
|
|
// 获取地块信息
|
|
|
-const getFeatureInfo = async (latlng: any, point: any): Promise<boolean> => {
|
|
|
+const getFeatureInfo = async (_latlng: any, point: any): Promise<boolean> => {
|
|
|
if (!map.value) return false;
|
|
|
|
|
|
featureInfo.loading = true;
|
|
|
@@ -579,29 +580,29 @@ const getFeatureInfo = async (latlng: any, point: any): Promise<boolean> => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 新增:单独获取当前pH的方法(点击预测后先加载pH)
|
|
|
+// 新增:单独获取当前pH的方法(点击预测后先加载pH)
|
|
|
const fetchCurrentPH = async () => {
|
|
|
if (currentPH.value !== null) return true; // 已有pH,直接返回
|
|
|
if (phLoading.value) return false; // 正在加载,避免重复请求
|
|
|
|
|
|
phLoading.value = true;
|
|
|
try {
|
|
|
- const urlParams = new URLSearchParams();
|
|
|
- urlParams.append('target_lon', currentClickCoords.lng.toString());
|
|
|
- urlParams.append('target_lat', currentClickCoords.lat.toString());
|
|
|
- urlParams.append('NO3', defaultParams.NO3.toString());
|
|
|
- urlParams.append('NH4', defaultParams.NH4.toString());
|
|
|
-
|
|
|
- // 调用接口获取当前pH(接口会返回nearest_point.ph)
|
|
|
- const response = await fetch(
|
|
|
- `http://localhost:8000/api/vector/nearest-with-predictions?${urlParams.toString()}`
|
|
|
- );
|
|
|
+ // 准备请求参数
|
|
|
+ const params = {
|
|
|
+ target_lon: currentClickCoords.lng.toString(),
|
|
|
+ target_lat: currentClickCoords.lat.toString(),
|
|
|
+ NO3: defaultParams.NO3.toString(),
|
|
|
+ NH4: defaultParams.NH4.toString()
|
|
|
+ };
|
|
|
|
|
|
- if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
- const data = await response.json();
|
|
|
+ // 使用api8000模块调用API
|
|
|
+ const response = await api8000.get('/api/vector/nearest-with-predictions', { params });
|
|
|
|
|
|
- // 从接口提取当前pH(根据你的接口结构:data.nearest_point.ph)
|
|
|
- currentPH.value = data.nearest_point?.ph !== undefined ? Number(data.nearest_point.ph) : null;
|
|
|
+ // 从接口提取当前pH
|
|
|
+ currentPH.value = response.data.nearest_point?.ph !== undefined
|
|
|
+ ? Number(response.data.nearest_point.ph)
|
|
|
+ : null;
|
|
|
+
|
|
|
return currentPH.value !== null; // 返回是否获取成功
|
|
|
} catch (error) {
|
|
|
console.error('获取当前pH失败:', error);
|
|
|
@@ -717,42 +718,41 @@ const callPredictionAPI = async (
|
|
|
predictionResult.value = null;
|
|
|
|
|
|
try {
|
|
|
- const urlParams = new URLSearchParams();
|
|
|
- urlParams.append('target_lon', lng.toString());
|
|
|
- urlParams.append('target_lat', lat.toString());
|
|
|
+ // 构建请求参数对象
|
|
|
+ const requestParams: Record<string, string | number> = {
|
|
|
+ target_lon: lng,
|
|
|
+ target_lat: lat
|
|
|
+ };
|
|
|
|
|
|
- // 明确传递 prediction_type
|
|
|
+ // 添加预测类型参数
|
|
|
if (currentPredictionType.value === 'reduction') {
|
|
|
- urlParams.append('prediction_type', 'reduce');
|
|
|
+ requestParams.prediction_type = 'reduce';
|
|
|
} else if (currentPredictionType.value === 'inversion') {
|
|
|
- urlParams.append('prediction_type', 'reflux');
|
|
|
+ requestParams.prediction_type = 'reflux';
|
|
|
}
|
|
|
|
|
|
+ // 添加可选参数
|
|
|
if (params) {
|
|
|
Object.entries(params).forEach(([key, value]) => {
|
|
|
if (value !== undefined && value !== null) {
|
|
|
- urlParams.append(key, value.toString());
|
|
|
+ requestParams[key] = value;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- console.log('调用预测接口,参数:', urlParams.toString());
|
|
|
-
|
|
|
- const response = await fetch(
|
|
|
- `http://localhost:8000/api/vector/nearest-with-predictions?${urlParams.toString()}`
|
|
|
- );
|
|
|
+ console.log('调用预测接口,参数:', requestParams);
|
|
|
|
|
|
- if (!response.ok) {
|
|
|
- const errorData = await response.json();
|
|
|
- console.error('预测接口返回错误:', errorData);
|
|
|
- throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
- }
|
|
|
+ // 使用api8000调用API
|
|
|
+ const response = await api8000.get('/api/vector/nearest-with-predictions', {
|
|
|
+ params: requestParams
|
|
|
+ });
|
|
|
|
|
|
- const data = await response.json();
|
|
|
- predictionResult.value = data;
|
|
|
- console.log('预测结果:', data);
|
|
|
+ predictionResult.value = response.data;
|
|
|
+ console.log('预测结果:', response.data);
|
|
|
|
|
|
- currentPH.value = data.nearest_point?.ph !== undefined ? Number(data.nearest_point.ph) : null;
|
|
|
+ currentPH.value = response.data.nearest_point?.ph !== undefined
|
|
|
+ ? Number(response.data.nearest_point.ph)
|
|
|
+ : null;
|
|
|
|
|
|
// 显示预测结果
|
|
|
showPredictionResult.value = true;
|
|
|
@@ -762,8 +762,7 @@ const callPredictionAPI = async (
|
|
|
} catch (error) {
|
|
|
currentPH.value = null;
|
|
|
console.error('调用预测接口失败:', error);
|
|
|
- predictionError.value = `预测失败: ${error instanceof Error ? error.message : '未知错误'}`;
|
|
|
- ElMessage.error('预测请求失败,请检查后端服务是否启动');
|
|
|
+
|
|
|
} finally {
|
|
|
predictionLoading.value = false;
|
|
|
}
|