import React, { useState, useEffect, useRef } from 'react'; import { Card, Row, Col, Statistic, Button, Space, Tag, Typography, Table, message } from 'antd'; import { CloudOutlined, ThunderboltOutlined, BarChartOutlined, RiseOutlined, BellOutlined, WalletOutlined, MinusOutlined, PlusOutlined, SyncOutlined, MoneyCollectOutlined, DashboardOutlined, FullscreenOutlined, RocketOutlined, VideoCameraOutlined, AppstoreOutlined, ExperimentOutlined, BranchesOutlined, RobotOutlined } from '@ant-design/icons'; import { Line, Bar, Pie } from '@ant-design/charts'; import { getWeatherData, getWeatherType } from '../lib/utils'; import WeatherDisplay from '../components/Weather'; import bgMain from '../assets/images/bgmain.jpg'; import { UniversalBarChart, UniversalLineChart, UniversalPieChart } from '../components/recharts'; // 👇 在这里引入你的工单接口(改成你真实的接口地址) import { addWorkOrder } from '../api/workOrder'; import { useSelector } from 'react-redux'; const { Text } = Typography; export default function StationDashboard() { // 👇 消息提示(修复缺失) const [messageApi, contextHolder] = message.useMessage(); // 👇 获取当前选中的电站(从redux拿,修复缺失) const { currentStation } = useSelector((state) => state.station); const { userInfo } = useSelector((state) => state.user); // 天气数据 const [weatherdata, setWeatherData] = useState({ province: "江苏省", city: "南通市", district: "崇川区", adcode: "320613", weather: "晴", weather_icon: "100", temperature: 18, wind_direction: "西南风", wind_power: "2级", humidity: 53, report_time: "2026-03-27 12:35:08" }); const weatherType = getWeatherType(weatherdata.weather); // 请求天气 useEffect(() => { const fetchWeather = async () => { try { const res = await getWeatherData(); setWeatherData(res); } catch (err) { console.error("天气接口请求失败", err); } }; fetchWeather(); }, []); // 模拟数据 const stationOverview = { todayEnergy: 4752.0, currentPower: 812.6, systemEfficiency: 82.6, yesterdayEfficiency: 81.3, systemAvailability: 99.35, onlineDevices: "12/13", alarmCount: 8, costSaved: 36540 }; const realtimeAlerts = [ { level: "INFO", type: "设备离线", time: "04-28 18:44" }, { level: "严重", type: "逆变器温度过高", time: "04-28 18:44" } ]; const deviceStatus = [ { name: "汇流箱", count: "2/2", status: "异常 1" }, { name: "逆变器", count: "3/3", status: "异常 1" }, { name: "电表", count: "1/1", status: "正常" }, { name: "巡检机器人", count: "1/1", status: "正常" } ]; const patrolRecords = [ { name: "升压站安防巡检任务", device: "UAV-01", status: "草稿", time: "04-29T...", person: "张运维" }, { name: "B区清洗任务", device: "CLEAN-01", status: "待执行", time: "04-29T...", person: "张运维" }, { name: "A区巡检任务", device: "ROBOT-01", status: "已派发", time: "04-29T...", person: "张运维" } ]; const aiAnalysis = [ { type: "AI分析", content: "AI发现逆变器温度与组串电流存在轻微异常,建议优先复核A区设备。", desc: "发现2处组件存在异常热斑" }, { type: "严重", content: "INV-A02散热检修建议:建议检查INV-A02散热风扇、风道和运行负载,持续高温时转维修工单。", desc: "3个组串存在发电异常" }, { type: "严重", content: "A05阵列热斑处置建议:建议现场复核PV-A05-018至PV-A05-020组件接线和旁路二极管状态,必要时更换异常组件。", desc: "整体发电偏差-2.8%" } ]; // 图表数据 const powerTrendData = [ { time: '00:00', actual: 1800, predict: 1600 }, { time: '04:00', actual: 1500, predict: 1400 }, { time: '06:00', actual: 8000, predict: 7500 }, { time: '08:00', actual: 32000, predict: 30000 }, { time: '10:00', actual: 58000, predict: 56000 }, { time: '12:00', actual: 62000, predict: 60000 }, { time: '14:00', actual: 59000, predict: 57000 }, { time: '16:00', actual: 42000, predict: 40000 }, { time: '18:00', actual: 12000, predict: 10000 }, { time: '20:00', actual: 3000, predict: 2500 }, { time: '24:00', actual: 1800, predict: 1600 }, ]; const irradianceData = [ { time: '00:00', irradiance: 40, temperature: 14 }, { time: '04:00', irradiance: 30, temperature: 12 }, { time: '06:00', irradiance: 180, temperature: 16 }, { time: '08:00', irradiance: 460, temperature: 21 }, { time: '10:00', irradiance: 780, temperature: 27 }, { time: '12:00', irradiance: 860, temperature: 31 }, { time: '14:00', irradiance: 820, temperature: 30 }, { time: '16:00', irradiance: 620, temperature: 26 }, { time: '18:00', irradiance: 220, temperature: 20 }, { time: '20:00', irradiance: 60, temperature: 16 }, { time: '24:00', irradiance: 40, temperature: 14 }, ]; const invEfficiencyData = [ { device: 'INV-01', efficiency: 98.6 }, { device: 'INV-02', efficiency: 97.8 }, { device: 'INV-03', efficiency: 97.2 }, { device: 'INV-04', efficiency: 96.5 }, { device: 'INV-05', efficiency: 95.8 }, ]; const taskProgressData = [ { name: '已完成', value: 40, color: '#1890ff' }, { name: '进行中', value: 35, color: '#52c41a' }, { name: '待开始', value: 20, color: '#faad14' }, { name: '异常', value: 5, color: '#ff4d4f' }, ]; const cardStyle = { borderRadius: 12, border: '1px solid #f0f0f0', boxShadow: '0 2px 8px rgba(0,0,0,0.04)' }; // ============================================== // 👇 【完整完善】生成清洗工单(核心修复) // ============================================== // ============================================== // 【正确匹配接口字段】生成清洗工单 // ============================================== const handleaddOrder = async () => { if (!currentStation) { messageApi.warning('请先选择电站'); return; } try { // 严格按照你给的接口字段传参 const params = { id: '', // 主键ID(新增为空) orderNo: '', // 工单编号(后端生成) orderTitle: '光伏组件清洗工单', // 工单标题 sourceType: 3, // 来源 3=清洗 orderType: 3, // 类型 3=清洗 priorityLevel: 2, // 优先级 2=中 deviceId: currentStation.id || '', deviceName: currentStation.siteName || '电站', deviceType: 1, // 设备类型:电站 siteId: currentStation.id || '', siteName: currentStation.siteName || '', orgId: userInfo?.orgId || '', assigneeId: '', assigneeName: '', collaboratorIds: '', collaboratorNames: '', planStartTime: '', planEndTime: '', deadlineTime: '', actualStartTime: '', actualEndTime: '', orderStatus: 1, // 状态 1=待处理 alarmId: '', alarmNo: '', taskDescription: '根据电站清洁度建议进行组件清洗,提升发电效率', aiSuggestion: '系统自动生成清洗建议,预计提升发电量2.6%', requiredEquipment: '清洗设备、水枪、抹布', estimatedImpact: '2.6', // 影响发电量(%) 数字 handleResult: '', handleRemark: '' }; const res = await addWorkOrder(params); if (res.code === 0 || res.code === 200) { messageApi.success('✅ 清洗工单生成成功'); } else { messageApi.error(res.msg || '❌ 工单生成失败'); } } catch (error) { messageApi.error('❌ 工单生成接口调用失败'); console.error(error); } }; return (
{/* 👇 必须加这个,message才能正常显示 */} {contextHolder} {/* 顶部统计卡片 */} {[ { title: '今日发电量', value: '4,752', unit: 'kWh', sub: '日目标 5,000 kWh', color: '#00B42A', bg: '#E8FFEA', icon: }, { title: '当前功率', value: '812.6', unit: 'kW', sub: '装机容量 1,000 kWp', color: '#165DFF', bg: '#E8F3FF', icon: }, { title: 'Performance Ratio', value: '82.6%', unit: '', sub: '昨日 81.3% ↑1.3%', color: '#00B42A', bg: '#E8FFEA', icon: }, { title: '系统可用率', value: '99.35%', unit: '', sub: '昨日 99.12% ↑0.23%', color: '#165DFF', bg: '#E8F3FF', icon: }, { title: '告警数量', value: '8', unit: '', sub: '未处理 5 / 已处理 3', color: '#F53F3F', bg: '#FFF1F0', icon: }, { title: '节省运维成本', value: '¥ 36,540', unit: '', sub: '本月累计节省', color: '#FF7D00', bg: '#FFF7E8', icon: }, ].map((item, idx) => (
{item.title}
{item.value} {item.unit && {item.unit}}
{item.sub}
{React.cloneElement(item.icon, { style: { fontSize: 22, color: item.color } })}
))}
{/* 主体布局 */} {/* 左侧图表 */} 发电趋势} extra={} bordered={false} style={cardStyle} bodyStyle={{ padding: '8px' }}>
今日发电功率趋势 (kW)
辐照度与温度趋势} bordered={false} style={cardStyle} bodyStyle={{ padding: '8px' }}> 逆变器效率对比} bordered={false} style={cardStyle} bodyStyle={{ padding: '12px' }}> 运维任务进度} extra={} bordered={false} style={cardStyle} bodyStyle={{ padding: '12px' }}>
总任务
12
{/* 中间 */} 电站概览
正常 告警 离线 维护中
} bordered={false} style={cardStyle} bodyStyle={{ padding: 0, position: 'relative', overflow: 'hidden', height: 500 }} >