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

254 lines
7.9 KiB
TypeScript
Raw Normal View History

2026-08-28 15:06:01 +08:00
import type { EChartsOption } from 'echarts';
import type { DashboardData, Station } from '../types';
2026-08-28 15:06:01 +08:00
import { EChart } from '../components/EChart';
const C = {
cyan: '#22d3ee',
green: '#34d399',
blue: '#60a5fa',
amber: '#fbbf24',
panel: '#0d1a33',
border: 'rgba(56,189,248,0.22)',
text: '#e2e8f0',
sub: '#94a3b8',
dim: '#64748b',
2026-08-28 15:06:01 +08:00
};
const statusColor: Record<Station['status'], string> = {
running: C.green,
idle: C.blue,
alarm: '#f87171',
offline: '#475569',
};
const gridLabel = { color: '#8fa3bf', fontSize: 13 };
2026-08-28 15:06:01 +08:00
export function ProductionBoard({ data }: { data: DashboardData }) {
const { production, progress, trends, equipment } = data;
2026-08-28 15:06:01 +08:00
const trendOption: EChartsOption = {
grid: { left: 48, right: 20, top: 28, bottom: 28 },
2026-08-28 15:06:01 +08:00
tooltip: { trigger: 'axis' },
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,
},
2026-08-28 15:06:01 +08:00
series: [
{
name: '日产量',
2026-08-28 15:06:01 +08:00
type: 'line',
smooth: true,
data: trends.production.map((t) => t.output),
itemStyle: { color: C.cyan },
areaStyle: { color: 'rgba(34,211,238,0.18)' },
2026-08-28 15:06:01 +08:00
},
],
};
return (
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14 }}>
<Kpi value={production.outputToday} label="今日产量" sub={`目标 ${production.targetToday}`} color={C.cyan} />
<Kpi value={production.passCount} label="一次通过" sub="件 · 全工序合格" color={C.green} />
<Kpi value={production.inLine} label="在制工件" sub="产线流转中" color={C.blue} />
<Kpi
value={production.deviceOnline}
label="设备在线"
sub={`共 ${production.deviceTotal} 台 · 全部在线`}
color={C.green}
/>
<Panel title="近 7 日产量趋势" style={{ gridColumn: 'span 2' }}>
<EChart option={trendOption} height={230} />
</Panel>
<Panel title="当前订单" style={{ gridColumn: 'span 2' }} accent>
2026-08-28 15:06:01 +08:00
<div
style={{
display: 'grid',
gridTemplateColumns: 'auto 1fr',
rowGap: 10,
columnGap: 14,
alignItems: 'center',
2026-08-28 15:06:01 +08:00
}}
>
<Field label="合同号" />
<span style={{ fontSize: 15, fontWeight: 500 }}>{progress.contractNo || progress.orderNo}</span>
<Field label="产品" />
<span style={{ fontSize: 14 }}>{progress.productName}</span>
2026-08-28 15:06:01 +08:00
<Field label="负责人" />
<span style={{ fontSize: 14, color: C.cyan }}>{progress.owner || '—'}</span>
<Field label="工期" />
<span style={{ fontSize: 14 }}>
{progress.planStart} ~ {progress.planEnd}
<span style={{ marginLeft: 10, color: progress.remainDays >= 0 ? C.green : C.amber }}>
剩余 {Math.max(progress.remainDays, 0)} 天
</span>
2026-08-28 15:06:01 +08:00
</span>
</div>
<div style={{ marginTop: 16 }}>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'baseline',
marginBottom: 8,
}}
>
<span style={{ fontSize: 13, color: C.sub }}>完成度</span>
<span style={{ fontSize: 13, color: C.sub }}>
<span style={{ fontSize: 20, fontWeight: 500, color: C.cyan }}>{progress.doneQty}</span>
{' / '}
{progress.totalQty} 台
</span>
</div>
<Bar percent={progress.progress} />
2026-08-28 15:06:01 +08:00
</div>
<div style={{ display: 'flex', gap: 10, marginTop: 16 }}>
<Chip label="工序进度" value={`${progress.processDone} / ${progress.processTotal} 序`} color={C.cyan} />
<Chip label="当前工序" value={progress.currentProcess || '—'} color={C.blue} />
<Chip
label="责任追溯"
value={progress.traceable ? `${progress.traceStepCount} 条 · 全程可追溯` : '待采集'}
color={progress.traceable ? C.green : C.dim}
/>
2026-08-28 15:06:01 +08:00
</div>
</Panel>
<Panel title="工位状态(12 工位 · 扫码枪 + 拧紧枪)" style={{ gridColumn: 'span 4' }}>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: 10 }}>
{equipment.map((s) => (
<div
key={s.id}
style={{
border: `1px solid ${statusColor[s.status]}55`,
borderLeft: `3px solid ${statusColor[s.status]}`,
borderRadius: 6,
padding: '8px 10px',
background: 'rgba(255,255,255,0.02)',
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span style={{ fontSize: 13, fontWeight: 500 }}>{s.name}</span>
<span style={{ fontSize: 11, color: statusColor[s.status] }}>
{s.status === 'running'
? '作业中'
: s.status === 'idle'
? '待料'
: s.status === 'alarm'
? '异常'
: '离线'}
</span>
</div>
<div style={{ fontSize: 11, color: C.dim, marginTop: 4 }}>
{s.currentOperator || '—'}
</div>
{s.currentSn && <div style={{ fontSize: 11, color: C.sub, marginTop: 2 }}>{s.currentSn}</div>}
</div>
))}
2026-08-28 15:06:01 +08:00
</div>
<div style={{ marginTop: 12, fontSize: 12, color: C.dim }}>
运行中 {production.stationSummary.running} · 待料 {production.stationSummary.idle} · 离线{' '}
{production.stationSummary.offline}
2026-08-28 15:06:01 +08:00
</div>
</Panel>
</div>
);
}
2026-08-28 15:06:01 +08:00
function Field({ label }: { label: string }) {
return <span style={{ fontSize: 12, color: C.dim }}>{label}</span>;
}
function Kpi({ value, label, sub, color }: { value: number; label: string; sub: string; color: string }) {
return (
<div
style={{
background: C.panel,
border: `1px solid ${C.border}`,
borderRadius: 8,
padding: '16px 18px',
}}
>
<div style={{ fontSize: 12, color: C.sub }}>{label}</div>
<div style={{ fontSize: 32, fontWeight: 500, color, lineHeight: 1.3 }}>{value}</div>
<div style={{ fontSize: 11, color: C.dim }}>{sub}</div>
2026-08-28 15:06:01 +08:00
</div>
);
}
function Panel({
title,
children,
style,
accent,
}: {
title: string;
children: React.ReactNode;
style?: React.CSSProperties;
accent?: boolean;
}) {
2026-08-28 15:06:01 +08:00
return (
<div
style={{
background: C.panel,
border: `1px solid ${accent ? 'rgba(34,211,238,0.42)' : C.border}`,
borderRadius: 8,
padding: '14px 16px',
...style,
}}
>
<div
style={{
fontSize: 13,
fontWeight: 500,
color: accent ? C.cyan : C.text,
marginBottom: 12,
letterSpacing: 0.5,
}}
>
{title}
</div>
{children}
2026-08-28 15:06:01 +08:00
</div>
);
}
function Bar({ percent }: { percent: number }) {
const p = Math.max(0, Math.min(100, percent));
return (
<div style={{ height: 8, background: '#1e293b', borderRadius: 4, overflow: 'hidden' }}>
<div style={{ width: `${p}%`, height: '100%', background: C.cyan, transition: 'width 0.6s ease' }} />
</div>
);
}
function Chip({ label, value, color }: { label: string; value: string; color: string }) {
return (
<div
style={{
flex: 1,
border: `1px solid ${color}44`,
borderRadius: 6,
padding: '8px 10px',
background: 'rgba(255,255,255,0.02)',
}}
>
<div style={{ fontSize: 11, color: C.dim }}>{label}</div>
<div style={{ fontSize: 13, color, marginTop: 3 }}>{value}</div>
</div>
);
}