卡片的自适应修改

This commit is contained in:
mmc
2026-05-14 09:37:15 +08:00
parent c0e8a1cd3e
commit 2ae097eed0
10 changed files with 874 additions and 790 deletions

View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { Card, Row, Col, Statistic, Button, Space, Tag, Typography } from 'antd';
import { Card, Row, Col, Statistic, Button, Space, Tag, Typography, Table } from 'antd';
import {
CloudOutlined, ThunderboltOutlined, BarChartOutlined,
RiseOutlined, BellOutlined, WalletOutlined,
@@ -193,10 +193,11 @@ export default function StationDashboard() {
{ device: 'INV-04', efficiency: 96.5 },
{ device: 'INV-05', efficiency: 95.8 }
],
// 关键:纠正坐标轴
// 恢复为竖向柱状图:X轴是设备,Y轴是效率
xField: 'device',
yField: 'efficiency',
// 关键:每个柱子不同颜色,效率越高越亮
// 每个柱子不同颜色,效率越高越亮
color: ({ efficiency }) => {
if (efficiency >= 98) return '#00B42A'; // 亮绿(最高效)
if (efficiency >= 97) return '#52C41A'; // 草绿
@@ -204,9 +205,12 @@ export default function StationDashboard() {
if (efficiency >= 95) return '#4080FF'; // 蓝色
return '#808695'; // 灰色(最低效)
},
barStyle: {
radius: [4, 4, 0, 0] // 顶部圆角,更美观
radius: [4, 4, 0, 0] // 顶部圆角,和第二张图效果一致
},
// 标签放在柱子顶部,显示百分比
label: {
position: 'top',
style: {
@@ -216,22 +220,28 @@ export default function StationDashboard() {
},
formatter: (item) => `${item}%`
},
// 关键:Y轴从90开始,让柱子更饱满
// Y轴从60开始(和第二张图的刻度一致),让柱子更饱满
yAxis: {
min: 90,
min: 60,
max: 100,
tickCount: 6,
tickCount: 5, // 控制刻度数量,显示60/70/80/90/100
label: {
formatter: (v) => `${v}%`
formatter: (v) => `${v}`
}
},
// 隐藏X轴上的线,保持简洁
xAxis: {
line: null
},
grid: {
line: { style: { stroke: '#eee', lineWidth: 0.5 } }
},
animation: { appear: { animation: 'scale-in-y', duration: 1000 } }
};
const taskProgressConfig = {
data: [
{ type: '已完成', value: 40 },
@@ -250,187 +260,39 @@ export default function StationDashboard() {
const cardStyle = { borderRadius: 8, };
return (
<div style={{ background: '#f0f2f5', paddingTop: "12px", minHeight: '100vh', width: '100%', boxSizing: 'border-box', overflow: "hidden" }}>
{/* 顶部一排6个卡片 —— 等宽、不换行、自适应 */}
<Row
gutter={[16, 16]}
style={{
marginBottom: 16,
width: '100%',
margin: '0 0 16px 0',
flexWrap: 'wrap',
}}
>
{/* 今日发电量 */}
<Col flex="1 1 16.666%" style={{ height: '140px' }}>
<Card bordered={false} style={{ ...cardStyle, height: "100%" }} bodyStyle={{ padding: '16px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<div style={{ color: '#000', fontSize: 14, fontWeight: 600, marginBottom: 8 }}>今日发电量</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ color: '#00B42A', fontSize: 24, fontWeight: 800 }}>4,752</span>
<span style={{ color: '#666', fontSize: 14, marginLeft: 4 }}>kWh</span>
<div style={{ background: '#f0f2f5', paddingTop: "12px", minHeight: '100vh', width: '100%', boxSizing: 'border-box', overflow: "auto" }}>
{/* 顶部统计卡片 */}
<Row gutter={[16, 16]} style={{ margin: '0 16px 16px 16px' }}>
{[
{ title: '今日发电量', value: '4,752', unit: 'kWh', sub: '日目标 5,000 kWh', color: '#00B42A', bg: '#E8FFEA', icon: <ThunderboltOutlined /> },
{ title: '当前功率', value: '812.6', unit: 'kW', sub: '装机容量 1,000 kWp', color: '#165DFF', bg: '#E8F3FF', icon: <DashboardOutlined /> },
{ title: 'Performance Ratio', value: '82.6%', unit: '', sub: '昨日 81.3% ↑1.3%', color: '#00B42A', bg: '#E8FFEA', icon: <BarChartOutlined /> },
{ title: '系统可用率', value: '99.35%', unit: '', sub: '昨日 99.12% ↑0.23%', color: '#165DFF', bg: '#E8F3FF', icon: <RiseOutlined /> },
{ title: '告警数量', value: '8', unit: '', sub: '未处理 5 / 已处理 3', color: '#F53F3F', bg: '#FFF1F0', icon: <BellOutlined /> },
{ title: '节省运维成本', value: '¥ 36,540', unit: '', sub: '本月累计节省', color: '#FF7D00', bg: '#FFF7E8', icon: <MoneyCollectOutlined /> },
].map((item, idx) => (
<Col key={idx} style={{ flex: "0 0 auto", minWidth: "200px" }}>
<Card bordered={false} style={{ ...cardStyle, height: "100%", minWidth: "200px" }} bodyStyle={{ padding: '16px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<div style={{ color: '#000', fontSize: 14, fontWeight: 600, marginBottom: 8 }}>{item.title}</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ color: item.color, fontSize: 24, fontWeight: 800 }}>{item.value}</span>
{item.unit && <span style={{ color: '#666', fontSize: 14, marginLeft: 4 }}>{item.unit}</span>}
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 8 }}>{item.sub}</div>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 8 }}>日目标 5,000 kWh</div>
</div>
<div style={{
width: 50,
height: 50,
background: '#E8FFEA',
borderRadius: '50%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
boxShadow: '0 2px 8px rgba(0, 180, 42, 0.1)'
}}>
<ThunderboltOutlined style={{ fontSize: 28, color: '#00B42A' }} />
</div>
</div>
</Card>
</Col>
{/* 当前功率 */}
<Col flex="1 1 16.666%" style={{ height: '140px' }}>
<Card bordered={false} style={{ ...cardStyle, height: "100%" }} bodyStyle={{ padding: '16px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<div style={{ color: '#000', fontSize: 14, fontWeight: 600, marginBottom: 8 }}>当前功率</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ color: '#165DFF', fontSize: 24, fontWeight: 800 }}>812.6</span>
<span style={{ color: '#165DFF', fontSize: 14, marginLeft: 4 }}>kW</span>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 8 }}>装机容量 1,000 kWp</div>
</div>
<div style={{
width: 50,
height: 50,
background: '#E8F3FF',
borderRadius: '50%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
boxShadow: '0 2px 8px rgba(22, 93, 255, 0.1)'
}}>
<DashboardOutlined style={{ fontSize: 28, color: '#165DFF' }} />
</div>
</div>
</Card>
</Col>
{/* Performance Ratio(PR) */}
<Col flex="1 1 16.666%">
<Card bordered={false} style={cardStyle} bodyStyle={{ padding: '16px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<div style={{ color: '#000', fontSize: 14, fontWeight: 600, marginBottom: 8 }}>Performance Ratio</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ color: '#00B42A', fontSize: 24, fontWeight: 800 }}>82.6%</span>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 8 }}>
昨日 81.3% &nbsp; 环比 <span style={{ color: '#00B42A' }}>↑1.3%</span>
<div style={{
width: 50, height: 50, background: item.bg, borderRadius: '50%',
display: 'flex', justifyContent: 'center', alignItems: 'center',
boxShadow: `0 2px 8px ${item.color}1A`
}}>
{React.cloneElement(item.icon as React.ReactElement, { style: { fontSize: 28, color: item.color } })}
</div>
</div>
<div style={{
width: 50,
height: 50,
background: '#E8FFEA',
borderRadius: '50%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
boxShadow: '0 2px 8px rgba(0, 180, 42, 0.1)'
}}>
<BarChartOutlined style={{ fontSize: 28, color: '#00B42A' }} />
</div>
</div>
</Card>
</Col>
{/* 系统可用率 */}
<Col flex="1 1 16.666%">
<Card bordered={false} style={cardStyle} bodyStyle={{ padding: '16px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<div style={{ color: '#000', fontSize: 14, fontWeight: 600, marginBottom: 8 }}>系统可用率</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ color: '#165DFF', fontSize: 24, fontWeight: 800 }}>99.35%</span>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 8 }}>
昨日 99.12% &nbsp; 环比 <span style={{ color: '#00B42A' }}>↑0.23%</span>
</div>
</div>
<div style={{
width: 50,
height: 50,
background: '#E8F3FF',
borderRadius: '50%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
boxShadow: '0 2px 8px rgba(22, 93, 255, 0.1)'
}}>
<RiseOutlined style={{ fontSize: 28, color: '#165DFF' }} />
</div>
</div>
</Card>
</Col>
{/* 告警数量 */}
<Col flex="1 1 16.666%">
<Card bordered={false} style={cardStyle} bodyStyle={{ padding: '16px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<div style={{ color: '#000', fontSize: 14, fontWeight: 600, marginBottom: 8 }}>告警数量</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ color: '#F53F3F', fontSize: 24, fontWeight: 800 }}>8</span>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 8 }}>
未处理 <span style={{ color: '#F53F3F' }}>5</span> &nbsp; 已处理 <span style={{ color: '#666' }}>3</span>
</div>
</div>
<div style={{
width: 50,
height: 50,
background: '#FFF1F0',
borderRadius: '50%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
boxShadow: '0 2px 8px rgba(245, 63, 63, 0.1)'
}}>
<BellOutlined style={{ fontSize: 28, color: '#F53F3F' }} />
</div>
</div>
</Card>
</Col>
{/* 节省运维成本 */}
<Col flex="1 1 16.666%">
<Card bordered={false} style={cardStyle} bodyStyle={{ padding: '16px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<div style={{ color: '#000', fontSize: 14, fontWeight: 600, marginBottom: 8 }}>节省运维成本</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ color: '#FF7D00', fontSize: 24, fontWeight: 800 }}>¥ 36,540</span>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 8 }}>本月累计节省</div>
</div>
<div style={{
width: 50,
height: 50,
background: '#FFF7E8',
borderRadius: '50%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
boxShadow: '0 2px 8px rgba(255, 125, 0, 0.1)'
}}>
<MoneyCollectOutlined style={{ fontSize: 28, color: '#FF7D00' }} />
</div>
</div>
</Card>
</Col>
</Card>
</Col>
))}
</Row>
{/* 主体:左侧图表 + 中间电站 + 右侧告警 —— 强制一行不换行 */}