feat: 大屏改为纯流式自适应布局,新增KPI带与产线动态拓扑地图
This commit is contained in:
@@ -1,345 +1,109 @@
|
||||
import type { EChartsOption } from 'echarts';
|
||||
import type { DashboardData, Station, ProgressGanttStep } from '../types';
|
||||
import type { DashboardData } from '../types';
|
||||
import { EChart } from '../components/EChart';
|
||||
import { dash0 } from './WarehouseBoard';
|
||||
|
||||
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',
|
||||
};
|
||||
|
||||
const statusColor: Record<Station['status'], string> = {
|
||||
running: C.green,
|
||||
idle: C.blue,
|
||||
// 大屏「报喜不报忧」:不把异常状态渲染成负面色,统一按中性呈现
|
||||
alarm: C.blue,
|
||||
offline: '#475569',
|
||||
};
|
||||
|
||||
const gridLabel = { color: '#8fa3bf', fontSize: 13 };
|
||||
|
||||
/** 底部左块 · 当前订单(合同/工期/完成度)+ 近 7 日产量趋势 */
|
||||
export function ProductionBoard({ data }: { data: DashboardData }) {
|
||||
const { production, progress, trends, equipment } = data;
|
||||
const { progress, trends } = data;
|
||||
|
||||
const trendOption: EChartsOption = {
|
||||
grid: { left: 48, right: 20, top: 28, bottom: 28 },
|
||||
grid: { left: 8, right: 12, top: 14, bottom: 4, containLabel: true },
|
||||
tooltip: { trigger: 'axis' },
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: trends.production.map((t) => t.time),
|
||||
axisLine: { lineStyle: { color: '#335' } },
|
||||
axisLabel: gridLabel,
|
||||
axisTick: { show: false },
|
||||
axisLine: { lineStyle: { color: 'rgba(56,189,248,0.25)' } },
|
||||
axisLabel: { color: '#8fa3bf', fontSize: 11 },
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
name: '产量',
|
||||
splitLine: { lineStyle: { color: '#1f2a3f' } },
|
||||
axisLabel: gridLabel,
|
||||
splitLine: { lineStyle: { color: 'rgba(56,189,248,0.1)' } },
|
||||
axisLabel: { color: '#8fa3bf', fontSize: 11 },
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '日产量',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'circle',
|
||||
symbolSize: 6,
|
||||
data: trends.production.map((t) => t.output),
|
||||
itemStyle: { color: C.cyan },
|
||||
lineStyle: { width: 2.5 },
|
||||
areaStyle: { color: 'rgba(34,211,238,0.18)' },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14, gridAutoRows: 'min-content' }}>
|
||||
<div style={{ gridColumn: 'span 4', display: 'grid', gridTemplateColumns: 'repeat(5, 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}
|
||||
/>
|
||||
<Kpi
|
||||
value={production.cycleTime > 0 ? production.cycleTime.toFixed(1) : '—'}
|
||||
label="生产节拍"
|
||||
sub="相邻完工间隔均值(分)"
|
||||
color={C.amber}
|
||||
/>
|
||||
<div className="panel">
|
||||
<div className="panel-head">
|
||||
当前订单
|
||||
<span className="note">合同 · 工期 · 完成度</span>
|
||||
</div>
|
||||
<div className="panel-body" style={{ flexDirection: 'row', gap: 'clamp(8px, 0.9vw, 40px)' }}>
|
||||
{/* 左:订单信息 */}
|
||||
<div style={{ flex: '1 1 46%', minWidth: 0, display: 'flex', flexDirection: 'column', gap: 'clamp(4px, 0.7vh, 9px)' }}>
|
||||
<div style={{ fontSize: 'clamp(15px, 1.25vw, 48px)', fontWeight: 600, color: '#eaf6ff', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
{progress.contractNo || progress.orderNo || '暂无在产订单'}
|
||||
</div>
|
||||
|
||||
<Panel title="近 7 日产量趋势" style={{ gridColumn: 'span 2' }}>
|
||||
<EChart option={trendOption} height={200} />
|
||||
</Panel>
|
||||
<div style={{ fontSize: 'clamp(11px, 0.85vw, 33px)', color: C.sub, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
{progress.productName || '—'}
|
||||
</div>
|
||||
|
||||
<Panel title="当前订单 · 工期横道" style={{ gridColumn: 'span 2' }} accent>
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'auto 1fr',
|
||||
rowGap: 8,
|
||||
columnGap: 14,
|
||||
alignItems: 'center',
|
||||
marginBottom: 12,
|
||||
}}
|
||||
>
|
||||
<Field label="合同号" />
|
||||
<span style={{ fontSize: 15, fontWeight: 500 }}>{progress.contractNo || progress.orderNo}</span>
|
||||
|
||||
<Field label="产品" />
|
||||
<span style={{ fontSize: 14 }}>{progress.productName}</span>
|
||||
|
||||
<Field label="负责人" />
|
||||
<span style={{ fontSize: 14, color: C.cyan }}>{progress.owner || '—'}</span>
|
||||
|
||||
<Field label="工期" />
|
||||
<span style={{ fontSize: 13 }}>
|
||||
{progress.planStart || '—'} ~ {progress.planEnd || '—'}
|
||||
<span style={{ marginLeft: 10, color: progress.remainDays >= 0 ? C.green : C.amber }}>
|
||||
剩余 {progress.remainDays >= 0 ? progress.remainDays : 0} 天
|
||||
<div style={{ display: 'flex', gap: 'clamp(10px, 1vw, 44px)', fontSize: 'clamp(10px, 0.8vw, 31px)', color: C.sub, flexWrap: 'nowrap' }}>
|
||||
<span style={{ whiteSpace: 'nowrap' }}>
|
||||
交期 <span style={{ color: C.text }}>{progress.planEnd || '—'}</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<span style={{ whiteSpace: 'nowrap', color: progress.remainDays >= 0 ? C.green : '#fbbf24' }}>
|
||||
剩余 {progress.planEnd ? Math.max(progress.remainDays, 0) : '—'} 天
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
<Bar percent={progress.progress} />
|
||||
|
||||
<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 style={{ marginTop: 'auto' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 8 }}>
|
||||
<span style={{ fontSize: 'clamp(10px, 0.8vw, 31px)', color: C.sub }}>完成进度</span>
|
||||
<span style={{ fontVariantNumeric: 'tabular-nums' }}>
|
||||
<span style={{ fontSize: 'clamp(17px, 1.5vw, 62px)', fontWeight: 700, color: C.cyan }}>{dash0(progress.doneQty)}</span>
|
||||
<span style={{ fontSize: 'clamp(10px, 0.8vw, 31px)', color: C.sub }}> / {dash0(progress.totalQty)} 台</span>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<Panel title="工位作业(12 工位 · 详见产线 2D 顶视)" style={{ gridColumn: 'span 4' }}>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(12, 1fr)', gap: 6 }}>
|
||||
{equipment.map((s, i) => (
|
||||
<div
|
||||
key={s.id}
|
||||
title={`${s.name} · ${s.currentOperator || '—'} · ${s.currentSn || ''}`}
|
||||
style={{
|
||||
border: `1px solid ${statusColor[s.status]}33`,
|
||||
borderTop: `3px solid ${statusColor[s.status]}`,
|
||||
borderRadius: 4,
|
||||
padding: '4px 4px',
|
||||
background: 'rgba(255,255,255,0.02)',
|
||||
}}
|
||||
>
|
||||
<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>
|
||||
</div>
|
||||
{/* 报喜不报忧:不展示「异常/报警」等负面状态,异常位统一按「待料」中性展示 */}
|
||||
<div style={{ fontSize: 10, color: statusColor[s.status], marginTop: 2, fontWeight: 500 }}>
|
||||
{s.status === 'running' ? '作业中' : s.status === 'offline' ? '离线' : '待料'}
|
||||
</div>
|
||||
<div style={{ height: 'clamp(6px, 0.9vh, 10px)', background: '#16233a', borderRadius: 6, overflow: 'hidden', marginTop: 6 }}>
|
||||
<div
|
||||
style={{
|
||||
width: `${Math.max(0, Math.min(100, progress.progress))}%`,
|
||||
height: '100%',
|
||||
background: 'linear-gradient(90deg, #0ea5e9, #22d3ee)',
|
||||
transition: 'width 0.6s ease',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<div style={{ fontSize: 'clamp(10px, 0.78vw, 29px)', color: C.dim, marginTop: 4, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
工序 {dash0(progress.processDone)}/{dash0(progress.processTotal)}
|
||||
{progress.currentProcess ? ` · 当前 ${progress.currentProcess}` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginTop: 6, fontSize: 11, color: C.dim }}>
|
||||
运行中 {production.stationSummary.running} · 待料 {production.stationSummary.idle} · 离线{' '}
|
||||
{production.stationSummary.offline}
|
||||
|
||||
{/* 右:近 7 日产量趋势(height:100% 跟随容器) */}
|
||||
<div style={{ flex: '1 1 54%', minWidth: 0, display: 'flex', flexDirection: 'column' }}>
|
||||
<div style={{ fontSize: 'clamp(10px, 0.8vw, 31px)', color: C.sub, flexShrink: 0, marginBottom: 2 }}>近 7 日产量</div>
|
||||
<div style={{ flex: 1, minHeight: 0, position: 'relative' }}>
|
||||
<EChart option={trendOption} height="100%" />
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Field({ label }: { label: string }) {
|
||||
return <span style={{ fontSize: 12, color: C.dim }}>{label}</span>;
|
||||
}
|
||||
|
||||
function Kpi({ value, label, sub, color }: { value: number | string; 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>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Panel({
|
||||
title,
|
||||
children,
|
||||
style,
|
||||
accent,
|
||||
}: {
|
||||
title: string;
|
||||
children: React.ReactNode;
|
||||
style?: React.CSSProperties;
|
||||
accent?: boolean;
|
||||
}) {
|
||||
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}
|
||||
</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 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} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user