首页发电趋势 支持放大

This commit is contained in:
mmc
2026-09-04 10:22:49 +08:00
parent a85497299a
commit c30f0544c2

View File

@@ -7,6 +7,7 @@ import {
MoneyCollectOutlined,
DashboardOutlined,
FullscreenOutlined,
FullscreenExitOutlined,
RocketOutlined,
VideoCameraOutlined,
AppstoreOutlined,
@@ -21,27 +22,57 @@ 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';
import { getAlarmList } from '../api/alarmApi';
import { RootState } from '../store';
import { useTranslation } from 'react-i18next';
const { Text } = Typography;
export default function StationDashboard() {
const { t } = useTranslation();
// 👇 消息提示(修复缺失)
const [messageApi, contextHolder] = message.useMessage();
// 👇 获取当前选中的电站(从redux拿,修复缺失)
const { currentStation } = useSelector((state) => state.station);
const { userInfo } = useSelector((state) => state.user);
const { stationId } = useSelector((state: RootState) => state.station);
const [alarmList, setAlarmList] = useState([]);
// ========== 发电趋势卡片全屏相关 ==========
const powerTrendCardRef = useRef<HTMLDivElement>(null);
const [isPowerCardFullscreen, setIsPowerCardFullscreen] = useState(false);
const togglePowerCardFullScreen = async () => {
const el = powerTrendCardRef.current;
if (!el) return;
try {
if (!document.fullscreenElement) {
await el.requestFullscreen();
} else {
await document.exitFullscreen();
}
} catch (err) {
console.error('全屏切换异常:', err);
}
};
const handleRefreshPowerTrend = () => {
console.log('刷新发电趋势数据');
// 这里可以写重新请求接口逻辑
};
useEffect(() => {
const onFullScreenChange = () => {
setIsPowerCardFullscreen(!!document.fullscreenElement);
};
document.addEventListener('fullscreenchange', onFullScreenChange);
return () => {
document.removeEventListener('fullscreenchange', onFullScreenChange);
};
}, []);
// =========================================
// 天气数据
const [weatherdata, setWeatherData] = useState({
@@ -58,7 +89,6 @@ export default function StationDashboard() {
report_time: "2026-03-27 12:35:08"
});
const weatherType = getWeatherType(weatherdata.weather);
// 请求天气
useEffect(() => {
const fetchWeather = async () => {
@@ -71,7 +101,6 @@ export default function StationDashboard() {
};
fetchWeather();
}, []);
// 模拟数据
const stationOverview = {
todayEnergy: 4752.0,
@@ -85,27 +114,22 @@ export default function StationDashboard() {
};
// 组件内部
const navigate = useNavigate();
const deviceStatus = [
{ name: t('home.combinerBox'), count: "2/2", status: "异常 1" },
{ name: t('home.inverter'), count: "3/3", status: "异常 1" },
{ name: "电表", count: "1/1", status: t('roles.normal') },
{ name: t('home.inspectionRobot'), count: "1/1", status: t('roles.normal') }
];
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: t('home.fixed2AiInverterFixed2TemperatureAbnormalADevice'), desc: "发现2处组件存在异常热斑" },
{ type: t('constants.critical'), content: t('home.invA02MaintenanceInvA02Repair'), desc: "3个组串存在发电异常" },
{ type: t('constants.critical'), content: t('home.a05HotspotPvA05018PvA05020StatusAbnormal'), desc: "整体发电偏差-2.8%" }
];
// 图表数据
const powerTrendData = [
{ time: '00:00', actual: 1800, predict: 1600 },
@@ -120,7 +144,6 @@ export default function StationDashboard() {
{ 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 },
@@ -141,16 +164,13 @@ export default function StationDashboard() {
{ device: 'INV-04', efficiency: 96.5 },
{ device: 'INV-05', efficiency: 95.8 },
];
const taskProgressData = [
{ name: t('workOrder.completed'), value: 40, color: '#1890ff' },
{ name: '进行中', value: 35, color: '#52c41a' },
{ name: '待开始', value: 20, color: '#faad14' },
{ name: t('home.abnormal'), value: 5, color: '#ff4d4f' },
];
const cardStyle = { borderRadius: 12, border: '1px solid #f0f0f0', boxShadow: '0 2px 8px rgba(0,0,0,0.04)' };
// ==============================================
// 👇 【完整完善】生成清洗工单(核心修复)
// ==============================================
@@ -165,12 +185,12 @@ export default function StationDashboard() {
try {
// 严格按照你给的接口字段传参
const params = {
id: '', // 主键ID(新增为空)
orderNo: '', // 工单编号(后端生成)
id: '', // 主键ID(新增为空)
orderNo: '', // 工单编号(后端生成)
orderTitle: '光伏组件清洗工单', // 工单标题
sourceType: 3, // 来源 3=清洗
orderType: 3, // 类型 3=清洗
priorityLevel: 2, // 优先级 2=中
sourceType: 3, // 来源 3=清洗
orderType: 3, // 类型 3=清洗
priorityLevel: 2, // 优先级 2=中
deviceId: currentStation.id || '',
deviceName: currentStation.siteName || '电站',
deviceType: 1, // 设备类型:电站
@@ -186,7 +206,7 @@ export default function StationDashboard() {
deadlineTime: '',
actualStartTime: '',
actualEndTime: '',
orderStatus: 1, // 状态 1=待处理
orderStatus: 1, // 状态 1=待处理
alarmId: '',
alarmNo: '',
taskDescription: '根据电站清洁度建议进行组件清洗,提升发电效率',
@@ -196,9 +216,7 @@ export default function StationDashboard() {
handleResult: '',
handleRemark: ''
};
const res = await addWorkOrder(params);
if (res.code === 0 || res.code === 200) {
messageApi.success(t('home.cleaningOrderGeneratedSuccessfullyFixed2'));
} else {
@@ -220,24 +238,19 @@ export default function StationDashboard() {
if (res.code === 200) {
setAlarmList(res?.rows || []);
}
} catch (err) {
messageApi.error(t('common.loadFailed'));
} finally {
}
};
useEffect(() => {
fetchList()
}, [stationId])
return (
<div style={{ background: '#f8fafc', padding: '0px', minHeight: '100vh', width: '100%', boxSizing: 'border-box' }}>
{/* 👇 必须加这个,message才能正常显示 */}
{contextHolder}
{/* 顶部统计卡片 */}
<Row gutter={[8, 8]} style={{ margin: '0 4px 0px 4px' }}>
{[
@@ -276,27 +289,45 @@ export default function StationDashboard() {
</Col>
))}
</Row>
{/* 主体布局 */}
<Row gutter={[8, 8]}>
{/* 左侧图表 */}
<Col xs={24} xl={6}>
<Space direction="vertical" size={8} style={{ width: '100%' }}>
<Card title={<span style={{ fontWeight: 800 }}>{t('home.generationTrend')}</span>} extra={<Space><SyncOutlined /><FullscreenOutlined /></Space>} variant="borderless" style={cardStyle} styles={{ body: { padding: '8px' } }}>
<div style={{ fontSize: 11, color: '#666', marginBottom: 8 }}>今日发电功率趋势 (kW)</div>
<UniversalLineChart
data={powerTrendData}
xKey="time"
height={200}
smooth
dot
backgroundColor="transparent"
series={[
{ key: 'actual', name: t('home.actual'), color: '#165DFF', strokeWidth: 3 },
{ key: 'predict', name: t('home.predict'), color: '#00B42A', strokeWidth: 2 },
]}
/>
</Card>
{/* ========== 发电趋势卡片,增加ref与全屏逻辑 ========== */}
<div ref={powerTrendCardRef} style={{ alignItems: 'center', display: "flex", justifyContent: "center" }}>
<Card
title={<span style={{ fontWeight: 800 }}>{t('home.generationTrend')}</span>}
extra={
<Space>
<SyncOutlined onClick={handleRefreshPowerTrend} style={{ cursor: 'pointer' }} />
{isPowerCardFullscreen ? (
<FullscreenExitOutlined onClick={togglePowerCardFullScreen} style={{ cursor: 'pointer' }} />
) : (
<FullscreenOutlined onClick={togglePowerCardFullScreen} style={{ cursor: 'pointer' }} />
)}
</Space>
}
variant="borderless"
style={{ ...cardStyle, width: "100%" }}
styles={{ body: { padding: '8px' } }}
>
<div style={{ fontSize: 11, color: '#666', marginBottom: 8 }}>今日发电功率趋势 (kW)</div>
<UniversalLineChart
data={powerTrendData}
xKey="time"
height={isPowerCardFullscreen ? window.innerHeight : 200}
smooth
dot
backgroundColor="transparent"
series={[
{ key: 'actual', name: t('home.actual'), color: '#165DFF', strokeWidth: 3 },
{ key: 'predict', name: t('home.predict'), color: '#00B42A', strokeWidth: 2 },
]}
/>
</Card>
</div>
<Card title={<span style={{ fontWeight: 800 }}>{t('home.irradianceTempTrend')}</span>} variant="borderless" style={cardStyle} styles={{ body: { padding: '8px' } }}>
<UniversalLineChart
data={irradianceData}
@@ -342,7 +373,6 @@ export default function StationDashboard() {
</Card>
</Space>
</Col>
{/* 中间 */}
<Col xs={24} xl={12}>
<Space direction="vertical" size={8} style={{ width: '100%' }}>
@@ -364,18 +394,15 @@ export default function StationDashboard() {
>
<div style={{ height: "100%", background: '#111827', borderRadius: 8, width: '100%', overflow: 'hidden', position: "relative" }}>
{/*<iframe
src="https://pvs.satabot.com/?platform=web"
style={{ width: '100%', height: '100%', border: 'none', borderRadius: '8px', position: "absolute" }}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
title={t('home.s20')}
/>*/}
src="https://pvs.satabot.com/?platform=web"
style={{ width: '100%', height: '100%', border: 'none', borderRadius: '8px', position: "absolute" }}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
title={t('home.s20')}
/>*/}
<CesiumMap from="other" mapLayer={currentStation?.siteMapName} />
</div>
</Card>
<Row gutter={16}>
<Col span={12}>
<Card title={<span style={{ fontWeight: 800 }}>{t('home.recentInspection')}</span>} extra={<Button type="link" size="small">{t('home.fixed2MoreGt')}</Button>} variant="borderless" style={{ ...cardStyle, height: "100%" }} styles={{ body: { padding: '0 12px' } }}>
@@ -438,7 +465,6 @@ export default function StationDashboard() {
</Row>
</Space>
</Col>
{/* 右侧 */}
<Col xs={24} xl={6}>
<Space direction="vertical" size={8} style={{ width: '100%' }}>
@@ -507,7 +533,6 @@ export default function StationDashboard() {
</div>
</div>
</Card>
{/* ====================================== */}
{/* 👇 清洗建议 + 生成工单按钮(已完善) */}
{/* ====================================== */}