From 2aa93f941eb1d13248d428c5489ef70969de44c7 Mon Sep 17 00:00:00 2001 From: peng Date: Thu, 30 Oct 2025 10:53:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E7=AE=A1=E7=90=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=89=8D=E7=AB=AF=20-=20=E6=B0=94=E8=B1=A1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E4=B8=8E=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/SoilQualityAnalysis.tsx | 862 ++++++++++++++++++ .../components/soilQualityService.ts | 558 ++++++++++++ .../soil-quality/components/soilTypes.ts | 256 ++++++ .../analysis/soil-quality/page.tsx | 15 +- .../environment/components/DataTrends.tsx | 207 +++++ .../environment/components/DeviceDialog.tsx | 298 ++++++ .../components/DeviceManagement.tsx | 109 +++ .../environment/components/DeviceOverview.tsx | 60 ++ .../components/RealTimeMonitoring.tsx | 167 ++++ .../environmentMonitoringReducer.tsx | 247 +++++ .../monitoring/environment/page.tsx | 225 ++++- .../weather/components/ControlPanel.tsx | 78 ++ .../components/RealtimeWeatherCards.tsx | 155 ++++ .../weather/components/UsageGuide.tsx | 27 + .../weather/components/WeatherAlerts.tsx | 86 ++ .../weather/components/WeatherAnalysis.tsx | 227 +++++ .../weather/components/WeatherCharts.tsx | 227 +++++ .../weather/components/WeatherContent.tsx | 125 +++ .../weather/components/WeatherForecast.tsx | 160 ++++ .../weather/components/WeatherHistory.tsx | 243 +++++ .../weather/components/weatherDataReducer.tsx | 479 ++++++++++ .../monitoring/weather/page.tsx | 25 +- 22 files changed, 4808 insertions(+), 28 deletions(-) create mode 100644 crop-x/src/app/(app)/land-information/analysis/soil-quality/components/SoilQualityAnalysis.tsx create mode 100644 crop-x/src/app/(app)/land-information/analysis/soil-quality/components/soilQualityService.ts create mode 100644 crop-x/src/app/(app)/land-information/analysis/soil-quality/components/soilTypes.ts create mode 100644 crop-x/src/app/(app)/land-information/monitoring/environment/components/DataTrends.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/environment/components/DeviceDialog.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/environment/components/DeviceManagement.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/environment/components/DeviceOverview.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/environment/components/RealTimeMonitoring.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/environment/components/environmentMonitoringReducer.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/ControlPanel.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/RealtimeWeatherCards.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/UsageGuide.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/WeatherAlerts.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/WeatherAnalysis.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/WeatherCharts.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/WeatherContent.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/WeatherForecast.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/WeatherHistory.tsx create mode 100644 crop-x/src/app/(app)/land-information/monitoring/weather/components/weatherDataReducer.tsx diff --git a/crop-x/src/app/(app)/land-information/analysis/soil-quality/components/SoilQualityAnalysis.tsx b/crop-x/src/app/(app)/land-information/analysis/soil-quality/components/SoilQualityAnalysis.tsx new file mode 100644 index 0000000..1312b19 --- /dev/null +++ b/crop-x/src/app/(app)/land-information/analysis/soil-quality/components/SoilQualityAnalysis.tsx @@ -0,0 +1,862 @@ +/** + * 土壤质量评价组件 + * 提供土壤质量分析、评价和改良建议功能 + */ + +'use client'; + +import { useState, useEffect } from 'react'; +import { Card } from '@/components/ui/card'; +import { Button } from '@/components/ui/button'; +import { Badge } from '@/components/ui/badge'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; +import { Textarea } from '@/components/ui/textarea'; +import { + BarChart3, + TrendingUp, + TrendingDown, + Activity, + AlertCircle, + CheckCircle, + Info, + Droplets, + Leaf, + Zap, + Beaker, + Calculator, + FileText, + Calendar, + MapPin, + User, + Download, + RefreshCw, + Eye, + Settings, + Target, + Award, + AlertTriangle, + ThumbsUp +} from 'lucide-react'; +import { toast } from 'sonner'; +import { + SoilQualityService, + SoilQualityEvaluation, + SoilIndicator, + SoilRecommendation, + SoilQualityHistory, + SoilAnalysisForm, + formatSoilScore, + getSoilGradeColor, + getIndicatorStatusColor, + formatDate +} from './soilQualityService'; +import { + SOIL_TYPES, + SOIL_TEXTURES, + DRAINAGE_LEVELS +} from './soilTypes'; + +export function SoilQualityAnalysis() { + const [activeTab, setActiveTab] = useState<'analysis' | 'evaluation' | 'history' | 'recommendations'>('analysis'); + const [selectedField, setSelectedField] = useState('field-1'); + const [isLoading, setIsLoading] = useState(false); + const [currentEvaluation, setCurrentEvaluation] = useState(null); + const [historicalData, setHistoricalData] = useState([]); + const [showForm, setShowForm] = useState(false); + + // 表单数据 + const [formData, setFormData] = useState({ + fieldId: 'field-1', + sampleDate: new Date().toISOString().split('T')[0], + sampleDepth: 20, + ph: 6.5, + organicMatter: 2.5, + nitrogen: 1.2, + phosphorus: 18, + potassium: 120, + calcium: 1200, + magnesium: 250, + sulfur: 15, + iron: 10, + manganese: 5, + zinc: 2, + copper: 1, + boron: 0.8, + soilTexture: 'medium', + drainage: 'good', + notes: '' + }); + + // 模拟地块数据 + const mockFields = [ + { id: 'field-1', name: '东区1号地', code: 'DB001', area: 85.5 }, + { id: 'field-2', name: '西区2号地', code: 'DB002', area: 92.3 }, + { id: 'field-3', name: '南区3号地', code: 'DB003', area: 78.7 }, + ]; + + // 初始化数据 + useEffect(() => { + loadHistoricalData(); + }, [selectedField]); + + const loadHistoricalData = () => { + const history = SoilQualityService.getHistoricalData(selectedField); + setHistoricalData(history); + + // 如果有历史记录,显示最新的评价 + if (history.length > 0) { + setCurrentEvaluation(history[0].evaluation); + } + }; + + const handleFormSubmit = async () => { + setIsLoading(true); + try { + // 生成土壤质量评价 + const evaluation = SoilQualityService.generateEvaluation(formData); + setCurrentEvaluation(evaluation); + + // 更新历史数据 + const newHistory: SoilQualityHistory = { + date: evaluation.date, + overallScore: evaluation.overallScore, + indicatorChanges: [], + evaluation + }; + + setHistoricalData([newHistory, ...historicalData]); + setShowForm(false); + setActiveTab('evaluation'); + + toast.success('土壤质量评价完成!'); + } catch (error) { + toast.error('评价失败,请检查数据'); + } finally { + setIsLoading(false); + } + }; + + const handleInputChange = (field: keyof SoilAnalysisForm, value: any) => { + setFormData(prev => ({ + ...prev, + [field]: value + })); + }; + + const exportReport = () => { + if (!currentEvaluation) { + toast.error('没有可导出的评价报告'); + return; + } + + // 模拟导出功能 + toast.success('正在生成土壤质量评价报告...'); + setTimeout(() => { + toast.success('报告已生成并下载'); + }, 2000); + }; + + const getPriorityColor = (priority: string): string => { + switch (priority) { + case 'high': return 'text-red-600 dark:text-red-400'; + case 'medium': return 'text-yellow-600 dark:text-yellow-400'; + case 'low': return 'text-green-600 dark:text-green-400'; + default: return 'text-gray-600 dark:text-gray-400'; + } + }; + + const getPriorityBadgeVariant = (priority: string): string => { + switch (priority) { + case 'high': return 'destructive'; + case 'medium': return 'default'; + case 'low': return 'secondary'; + default: return 'outline'; + } + }; + + return ( +
+ {/* 页面头部 */} +
+
+

土壤质量评价

+

+ 专业的土壤质量分析与改良建议系统 +

+
+
+ + + +
+
+ + {/* 地块信息卡片 */} +
+ +
+ +
+
当前地块
+
{mockFields.find(f => f.id === selectedField)?.name}
+
+
+
+ +
+ +
+
总体评分
+
+ {currentEvaluation ? formatSoilScore(currentEvaluation.overallScore) : '--'} +
+
+
+
+ +
+ +
+
质量等级
+
+ {currentEvaluation ? currentEvaluation.overallGrade : '--'} +
+
+
+
+ +
+ +
+
历史记录
+
{historicalData.length} 条
+
+
+
+
+ + {/* 土壤分析表单 */} + {showForm && ( + +
+

土壤质量分析表单

+ +
+ +
+ {/* 基本信息 */} +
+

基本信息

+
+
+ + +
+
+ + handleInputChange('sampleDate', e.target.value)} + /> +
+
+ + handleInputChange('sampleDepth', Number(e.target.value))} + /> +
+
+ + +
+
+ + +
+
+
+ + {/* 化学指标 */} +
+

化学指标

+
+
+ + handleInputChange('ph', Number(e.target.value))} + /> +
+
+ + handleInputChange('organicMatter', Number(e.target.value))} + /> +
+
+ + handleInputChange('nitrogen', Number(e.target.value))} + /> +
+
+ + handleInputChange('phosphorus', Number(e.target.value))} + /> +
+
+ + handleInputChange('potassium', Number(e.target.value))} + /> +
+
+ +