2026-08-28 15:06:01 +08:00
|
|
|
import type { EChartsOption } from 'echarts';
|
2026-09-04 17:31:18 +08:00
|
|
|
import type { DashboardData, Station, ProgressGanttStep } from '../types';
|
2026-08-28 15:06:01 +08:00
|
|
|
import { EChart } from '../components/EChart';
|
|
|
|
|
|
2026-09-04 14:18:53 +08:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2026-09-04 14:18:53 +08:00
|
|
|
const statusColor: Record<Station['status'], string> = {
|
|
|
|
|
running: C.green,
|
|
|
|
|
idle: C.blue,
|
2026-09-15 16:37:39 +08:00
|
|
|
// 大屏「报喜不报忧」:不把异常状态渲染成负面色,统一按中性呈现
|
|
|
|
|
alarm: C.blue,
|
2026-09-04 14:18:53 +08:00
|
|
|
offline: '#475569',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const gridLabel = { color: '#8fa3bf', fontSize: 13 };
|
|
|
|
|
|
2026-08-28 15:06:01 +08:00
|
|
|
export function ProductionBoard({ data }: { data: DashboardData }) {
|
2026-09-04 14:18:53 +08:00
|
|
|
const { production, progress, trends, equipment } = data;
|
2026-08-28 15:06:01 +08:00
|
|
|
|
|
|
|
|
const trendOption: EChartsOption = {
|
2026-09-04 14:18:53 +08:00
|
|
|
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,
|
|
|
|
|
},
|
2026-09-04 14:18:53 +08:00
|
|
|
yAxis: {
|
|
|
|
|
type: 'value',
|
|
|
|
|
name: '产量',
|
|
|
|
|
splitLine: { lineStyle: { color: '#1f2a3f' } },
|
|
|
|
|
axisLabel: gridLabel,
|
|
|
|
|
},
|
2026-08-28 15:06:01 +08:00
|
|
|
series: [
|
|
|
|
|
{
|
2026-09-04 14:18:53 +08:00
|
|
|
name: '日产量',
|
2026-08-28 15:06:01 +08:00
|
|
|
type: 'line',
|
|
|
|
|
smooth: true,
|
|
|
|
|
data: trends.production.map((t) => t.output),
|
2026-09-04 14:18:53 +08:00
|
|
|
itemStyle: { color: C.cyan },
|
|
|
|
|
areaStyle: { color: 'rgba(34,211,238,0.18)' },
|
2026-08-28 15:06:01 +08:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-09-04 17:31:18 +08:00
|
|
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14, gridAutoRows: 'min-content' }}>
|
2026-09-04 14:18:53 +08:00
|
|
|
<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' }}>
|
2026-09-04 17:31:18 +08:00
|
|
|
<EChart option={trendOption} height={200} />
|
2026-09-04 14:18:53 +08:00
|
|
|
</Panel>
|
|
|
|
|
|
2026-09-04 17:31:18 +08:00
|
|
|
<Panel title="当前订单 · 工期横道" style={{ gridColumn: 'span 2' }} accent>
|
2026-08-28 15:06:01 +08:00
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: 'grid',
|
2026-09-04 14:18:53 +08:00
|
|
|
gridTemplateColumns: 'auto 1fr',
|
2026-09-04 17:31:18 +08:00
|
|
|
rowGap: 8,
|
2026-09-04 14:18:53 +08:00
|
|
|
columnGap: 14,
|
|
|
|
|
alignItems: 'center',
|
2026-09-04 17:31:18 +08:00
|
|
|
marginBottom: 12,
|
2026-08-28 15:06:01 +08:00
|
|
|
}}
|
|
|
|
|
>
|
2026-09-04 14:18:53 +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
|
|
|
|
2026-09-04 14:18:53 +08:00
|
|
|
<Field label="负责人" />
|
|
|
|
|
<span style={{ fontSize: 14, color: C.cyan }}>{progress.owner || '—'}</span>
|
|
|
|
|
|
|
|
|
|
<Field label="工期" />
|
2026-09-04 17:31:18 +08:00
|
|
|
<span style={{ fontSize: 13 }}>
|
|
|
|
|
{progress.planStart || '—'} ~ {progress.planEnd || '—'}
|
2026-09-04 14:18:53 +08:00
|
|
|
<span style={{ marginLeft: 10, color: progress.remainDays >= 0 ? C.green : C.amber }}>
|
2026-09-04 17:31:18 +08:00
|
|
|
剩余 {progress.remainDays >= 0 ? progress.remainDays : 0} 天
|
2026-09-04 14:18:53 +08:00
|
|
|
</span>
|
2026-08-28 15:06:01 +08:00
|
|
|
</span>
|
|
|
|
|
</div>
|
2026-09-04 14:18:53 +08:00
|
|
|
|
2026-09-04 17:31:18 +08:00
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'baseline',
|
|
|
|
|
marginBottom: 8,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<span style={{ fontSize: 13, color: C.sub }}>
|
|
|
|
|
完成度 {progress.progress}% · 工序 {progress.processDone}/{progress.processTotal}
|
|
|
|
|
</span>
|
|
|
|
|
<span style={{ fontSize: 13, color: C.sub }}>
|
|
|
|
|
<span style={{ fontSize: 18, fontWeight: 500, color: C.cyan }}>{progress.doneQty}</span>
|
|
|
|
|
{' / '}{progress.totalQty} 台
|
|
|
|
|
</span>
|
2026-08-28 15:06:01 +08:00
|
|
|
</div>
|
2026-09-04 17:31:18 +08:00
|
|
|
<Bar percent={progress.progress} />
|
2026-09-04 14:18:53 +08:00
|
|
|
|
2026-09-04 17:31:18 +08:00
|
|
|
<div style={{ marginTop: 14, height: 260 }}>
|
|
|
|
|
{progress.steps.length > 0 ? (
|
|
|
|
|
<GanttChart steps={progress.steps} />
|
|
|
|
|
) : (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
height: '100%',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
color: C.dim,
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
border: `1px dashed ${C.border}`,
|
|
|
|
|
borderRadius: 6,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
暂无工序横道数据
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-08-28 15:06:01 +08:00
|
|
|
</div>
|
2026-09-04 14:18:53 +08:00
|
|
|
</Panel>
|
|
|
|
|
|
2026-09-04 17:31:18 +08:00
|
|
|
<Panel title="工位作业(12 工位 · 详见产线 2D 顶视)" style={{ gridColumn: 'span 4' }}>
|
|
|
|
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(12, 1fr)', gap: 6 }}>
|
|
|
|
|
{equipment.map((s, i) => (
|
2026-09-04 14:18:53 +08:00
|
|
|
<div
|
|
|
|
|
key={s.id}
|
2026-09-04 17:31:18 +08:00
|
|
|
title={`${s.name} · ${s.currentOperator || '—'} · ${s.currentSn || ''}`}
|
2026-09-04 14:18:53 +08:00
|
|
|
style={{
|
2026-09-04 17:31:18 +08:00
|
|
|
border: `1px solid ${statusColor[s.status]}33`,
|
|
|
|
|
borderTop: `3px solid ${statusColor[s.status]}`,
|
|
|
|
|
borderRadius: 4,
|
|
|
|
|
padding: '4px 4px',
|
2026-09-04 14:18:53 +08:00
|
|
|
background: 'rgba(255,255,255,0.02)',
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-09-04 17:31:18 +08:00
|
|
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 10 }}>
|
|
|
|
|
<span style={{ color: C.text, fontWeight: 600 }}>{s.name}</span>
|
|
|
|
|
<span style={{ color: C.dim, fontVariantNumeric: 'tabular-nums' }}>{i + 1}</span>
|
2026-09-04 14:18:53 +08:00
|
|
|
</div>
|
2026-09-15 16:37:39 +08:00
|
|
|
{/* 报喜不报忧:不展示「异常/报警」等负面状态,异常位统一按「待料」中性展示 */}
|
2026-09-04 17:31:18 +08:00
|
|
|
<div style={{ fontSize: 10, color: statusColor[s.status], marginTop: 2, fontWeight: 500 }}>
|
2026-09-15 16:37:39 +08:00
|
|
|
{s.status === 'running' ? '作业中' : s.status === 'offline' ? '离线' : '待料'}
|
2026-09-04 14:18:53 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2026-08-28 15:06:01 +08:00
|
|
|
</div>
|
2026-09-04 17:31:18 +08:00
|
|
|
<div style={{ marginTop: 6, fontSize: 11, color: C.dim }}>
|
2026-09-04 14:18:53 +08:00
|
|
|
运行中 {production.stationSummary.running} · 待料 {production.stationSummary.idle} · 离线{' '}
|
|
|
|
|
{production.stationSummary.offline}
|
2026-08-28 15:06:01 +08:00
|
|
|
</div>
|
2026-09-04 14:18:53 +08:00
|
|
|
</Panel>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-08-28 15:06:01 +08:00
|
|
|
|
2026-09-04 14:18:53 +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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-04 14:18:53 +08:00
|
|
|
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 (
|
2026-09-04 14:18:53 +08:00
|
|
|
<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>
|
|
|
|
|
);
|
2026-09-04 14:18:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-04 17:31:18 +08:00
|
|
|
function GanttChart({ steps }: { steps: ProgressGanttStep[] }) {
|
|
|
|
|
const names = steps.map((s) => s.name);
|
|
|
|
|
const now = new Date();
|
|
|
|
|
|
|
|
|
|
const planData = steps.map((s, i) => ({
|
|
|
|
|
value: [i, new Date(s.planStart).getTime(), new Date(s.planEnd).getTime(), 'plan'],
|
|
|
|
|
itemStyle: { color: 'rgba(148, 163, 184, 0.12)' },
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const actualData = steps
|
|
|
|
|
.filter((s) => s.actualStart)
|
|
|
|
|
.map((s, i) => {
|
|
|
|
|
const start = new Date(s.actualStart!).getTime();
|
|
|
|
|
const end = s.actualEnd ? new Date(s.actualEnd).getTime() : now.getTime();
|
|
|
|
|
const color = s.status === 'done' ? C.green : C.cyan;
|
|
|
|
|
return {
|
|
|
|
|
value: [i, start, end, 'actual'],
|
|
|
|
|
itemStyle: { color },
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const option: EChartsOption = {
|
|
|
|
|
tooltip: {
|
|
|
|
|
formatter: (params: any) => {
|
|
|
|
|
const s = steps[params.value[0] as number];
|
|
|
|
|
const start = new Date(params.value[1] as number).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });
|
|
|
|
|
const end = new Date(params.value[2] as number).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });
|
|
|
|
|
return `<div style="font-size:12px"><b>${s.name}</b><br/>负责人:${s.owner}<br/>状态:${s.status === 'done' ? '已完成' : s.status === 'running' ? '进行中' : '未开始'}<br/>${start} ~ ${end}</div>`;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
grid: { left: 96, right: 24, top: 10, bottom: 24 },
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'time',
|
|
|
|
|
axisLine: { lineStyle: { color: '#335' } },
|
|
|
|
|
axisLabel: { color: '#8fa3bf', fontSize: 11, formatter: '{MM}-{dd}' },
|
|
|
|
|
splitLine: { lineStyle: { color: '#1f2a3f' } },
|
|
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
type: 'category',
|
|
|
|
|
data: names,
|
|
|
|
|
inverse: true,
|
|
|
|
|
axisLine: { lineStyle: { color: '#335' } },
|
|
|
|
|
axisLabel: { color: '#94a3b8', fontSize: 11 },
|
|
|
|
|
splitLine: { show: false },
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
type: 'custom',
|
|
|
|
|
name: '计划工期',
|
|
|
|
|
renderItem: (_params: any, api: any) => {
|
|
|
|
|
const categoryIndex = api.value(0);
|
|
|
|
|
const start = api.coord([api.value(1), categoryIndex]);
|
|
|
|
|
const end = api.coord([api.value(2), categoryIndex]);
|
|
|
|
|
const height = api.size([0, 1])[1] * 0.55;
|
|
|
|
|
return {
|
|
|
|
|
type: 'rect',
|
|
|
|
|
shape: {
|
|
|
|
|
x: start[0],
|
|
|
|
|
y: start[1] - height / 2,
|
|
|
|
|
width: Math.max(end[0] - start[0], 2),
|
|
|
|
|
height,
|
|
|
|
|
},
|
|
|
|
|
style: api.style(),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
encode: { x: [1, 2], y: 0 },
|
|
|
|
|
data: planData,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'custom',
|
|
|
|
|
name: '实际进度',
|
|
|
|
|
renderItem: (_params: any, api: any) => {
|
|
|
|
|
const categoryIndex = api.value(0);
|
|
|
|
|
const start = api.coord([api.value(1), categoryIndex]);
|
|
|
|
|
const end = api.coord([api.value(2), categoryIndex]);
|
|
|
|
|
const height = api.size([0, 1])[1] * 0.32;
|
|
|
|
|
return {
|
|
|
|
|
type: 'rect',
|
|
|
|
|
shape: {
|
|
|
|
|
x: start[0],
|
|
|
|
|
y: start[1] - height / 2,
|
|
|
|
|
width: Math.max(end[0] - start[0], 2),
|
|
|
|
|
height,
|
|
|
|
|
},
|
|
|
|
|
style: api.style(),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
encode: { x: [1, 2], y: 0 },
|
|
|
|
|
data: actualData,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return <EChart option={option} height={260} />;
|
2026-09-04 14:18:53 +08:00
|
|
|
}
|