Files
bj_power/bj_power_dashboard/src/pages/ProductionBoard.tsx
T

157 lines
5.0 KiB
TypeScript
Raw Normal View History

2026-08-28 15:06:01 +08:00
import { Card, Progress, Tag, Typography } from '@douyinfe/semi-ui';
import type { EChartsOption } from 'echarts';
import type { DashboardData } from '../types';
import { EChart } from '../components/EChart';
const gridLabel = {
color: '#8fa3bf',
fontSize: 13,
};
export function ProductionBoard({ data }: { data: DashboardData }) {
const { production, progress, trends } = data;
const st = production.stationSummary;
const prog =
progress.totalQty > 0 ? (progress.completedQty / progress.totalQty) * 100 : 0;
const ringOption: EChartsOption = {
tooltip: {
formatter: '{b}: {c}({d}%)',
},
series: [
{
type: 'pie',
radius: ['62%', '82%'],
silent: true,
label: { show: true, position: 'center', formatter: '{value}%'.replace('{value}', String(production.qualifiedRate)), fontSize: 30, fontWeight: 'bold', color: '#00d68f' },
data: [
{ value: production.qualityOk, name: '合格', itemStyle: { color: '#00d68f' } },
{ value: production.qualityNg, name: '不合格', itemStyle: { color: '#ff5252' } },
],
},
],
};
const trendOption: EChartsOption = {
grid: { left: 40, right: 16, top: 28, bottom: 24 },
tooltip: { trigger: 'axis' },
legend: { textStyle: gridLabel, top: 0, data: ['当日产量', '合格率'] },
xAxis: {
type: 'category',
data: trends.production.map((t) => t.time),
axisLine: { lineStyle: { color: '#335' } },
axisLabel: gridLabel,
},
yAxis: [
{
type: 'value',
name: '产量',
splitLine: { lineStyle: { color: '#1f2a3f' } },
axisLabel: gridLabel,
},
{
type: 'value',
name: '合格率',
min: 80,
max: 100,
splitLine: { show: false },
axisLabel: gridLabel,
},
],
series: [
{
name: '当日产量',
type: 'line',
smooth: true,
data: trends.production.map((t) => t.output),
itemStyle: { color: '#36a3f7' },
areaStyle: { color: 'rgba(54,163,247,0.2)' },
},
{
name: '合格率',
type: 'line',
yAxisIndex: 1,
smooth: true,
data: trends.production.map((t) => t.qualifiedRate),
itemStyle: { color: '#00d68f' },
},
],
};
return (
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16 }}>
<Card title="产线运行状态" style={{ gridColumn: 'span 2' }}>
<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(4, 1fr)',
gap: 12,
textAlign: 'center',
}}
>
<Cell value={st.running} label="运行中" color="#00d68f" />
<Cell value={st.idle} label="空闲" color="#36a3f7" />
<Cell value={st.alarm} label="报警" color="#ff5252" />
<Cell value={st.offline} label="离线" color="#8fa3bf" />
</div>
</Card>
<Card title="当日产量">
<div style={{ display: 'flex', alignItems: 'baseline', gap: 8 }}>
<span style={{ fontSize: 36, fontWeight: 700, color: '#36a3f7' }}>
{production.outputToday}
</span>
<span style={{ color: '#8fa3bf' }}>/ {production.targetToday}</span>
</div>
<div style={{ marginTop: 8 }}>
<Typography.Text type="tertiary">日计划达成率</Typography.Text>
<Progress
percent={
production.targetToday
? Math.round((production.outputToday / production.targetToday) * 100)
: 0
}
showInfo
style={{ marginTop: 8 }}
/>
</div>
</Card>
<Card title="合格率">
<EChart option={ringOption} height={170} />
</Card>
<Card title="工单进度">
<div style={{ marginBottom: 8 }}>
<Typography.Text strong>{progress.orderNo}</Typography.Text>
<Tag size="small" style={{ marginLeft: 8 }} color="green">
{progress.status}
</Tag>
</div>
<Typography.Text type="tertiary">{progress.productName}</Typography.Text>
<div style={{ margin: '10px 0' }}>
<Typography.Text>
完成 {progress.completedQty} / {progress.totalQty}
</Typography.Text>
</div>
<Progress percent={Math.round(prog)} showInfo stroke="#5cabff" />
<div style={{ marginTop: 12 }}>
<Typography.Text type="secondary">当前工序:{progress.currentProcess}</Typography.Text>
</div>
</Card>
<Card title="产量与合格率趋势" style={{ gridColumn: 'span 4' }}>
<EChart option={trendOption} height={280} />
</Card>
</div>
);
}
function Cell({ value, label, color }: { value: number; label: string; color: string }) {
return (
<div>
<div style={{ fontSize: 32, fontWeight: 600, color }}>{value}</div>
<div style={{ color: '#8fa3bf', fontSize: 13 }}>{label}</div>
</div>
);
}