236 lines
12 KiB
TypeScript
236 lines
12 KiB
TypeScript
import { CircleDollarSign, FlaskConical, ShoppingCart, Target, Factory, Truck } from 'lucide-react';
|
|
import { useTheme } from '../../context/ThemeContext';
|
|
import { useText } from '../../i18n/useText';
|
|
import { PanelBody } from '../layout/PanelShell';
|
|
import type { MetricNode } from '../../data/sqlite';
|
|
import { alertColor, fmt } from '../../lib/metric';
|
|
import { achieveAt, levelAt, periodLabel, valueAt } from '../../lib/time';
|
|
import { STAGES, flowStats, type FlowIcon } from '../../lib/process';
|
|
|
|
/**
|
|
* 流程效能看板(研产供销六段价值链 · 过程指标层)。
|
|
*
|
|
* 与指标树的分工写在标题下那句话里:指标树是**结果**(钱和率的达成),
|
|
* 这里是**过程**(一批商机/项目/工单在链上每段停留多久、流过多少、返工多少)。
|
|
* 每段下方的指标片是真实 metric_node,点开即联动中央看板;
|
|
* 过程量则是可复现的模拟值,随底部时间轴游标一起演变。
|
|
*/
|
|
interface Props {
|
|
byCode: Map<string, MetricNode>;
|
|
selected: string;
|
|
onSelect: (code: string) => void;
|
|
period: number;
|
|
}
|
|
|
|
const ICONS: Record<FlowIcon, typeof Target> = {
|
|
target: Target, flask: FlaskConical, cart: ShoppingCart, factory: Factory, truck: Truck, cash: CircleDollarSign,
|
|
};
|
|
|
|
export default function ProcessFlowPanel({ byCode, selected, onSelect, period }: Props) {
|
|
const { tokens } = useTheme();
|
|
const { t } = useText();
|
|
|
|
const { stats, summary } = flowStats(period);
|
|
const bottleneck = STAGES.findIndex(s => s.key === summary.bottleneckKey);
|
|
const constraint = STAGES.findIndex(s => s.key === summary.constraintKey);
|
|
/* 在制品堆得最高的一段:比“总和”更能指出哪里在堵 */
|
|
const wipTop = stats.reduce((mi, x, i) => (x.wip > stats[mi].wip ? i : mi), 0);
|
|
|
|
const tile = (label: string, value: string, sub: string | null, color: string) => (
|
|
<div style={{
|
|
background: tokens.cardBg, border: `1px solid ${tokens.border}`, borderRadius: 9, padding: '5px 8px', minWidth: 0,
|
|
}}>
|
|
<div style={{ fontSize: 10, color: tokens.textMuted, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{label}</div>
|
|
<div style={{
|
|
fontSize: 16, fontWeight: 800, color, lineHeight: 1.25, fontVariantNumeric: 'tabular-nums',
|
|
fontFamily: 'ui-monospace, monospace', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
|
|
}}>{value}</div>
|
|
{sub && <div style={{ fontSize: 9.5, color: tokens.textMuted, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{sub}</div>}
|
|
</div>
|
|
);
|
|
|
|
/** 过程量小格:标签 + 值 + 目标/环比提示 */
|
|
const stat = (label: string, value: string, tone: string) => (
|
|
<div style={{ display: 'flex', alignItems: 'baseline', gap: 4, minWidth: 0 }}>
|
|
<span style={{ fontSize: 10, color: tokens.textMuted, flexShrink: 0 }}>{label}</span>
|
|
<span style={{
|
|
fontSize: 12, fontWeight: 700, color: tone, fontVariantNumeric: 'tabular-nums',
|
|
fontFamily: 'ui-monospace, monospace', whiteSpace: 'nowrap',
|
|
}}>{value}</span>
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<PanelBody>
|
|
{/* 口径提示:过程 vs 结果 */}
|
|
<div style={{
|
|
fontSize: 11, lineHeight: 1.55, color: tokens.textMuted, marginBottom: 8,
|
|
padding: '6px 9px', borderRadius: 8, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
|
|
}}>
|
|
{t.flow.hint}
|
|
</div>
|
|
|
|
{/* 全链汇总 */}
|
|
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 6, marginBottom: 4 }}>
|
|
{tile(t.flow.cycle, `${fmt(summary.cycle)}${t.flow.unitDay}`, `${t.flow.base} ${fmt(summary.cycleBase)}${t.flow.unitDay}`, tokens.text)}
|
|
{tile(t.flow.e2e, `${fmt(summary.e2e)}%`, `${t.flow.base} ${fmt(summary.e2eBase)}%`, summary.e2e >= 55 ? tokens.success : summary.e2e >= 40 ? tokens.warning : tokens.danger)}
|
|
{tile(t.flow.throughput, summary.throughput.toLocaleString(), `${t.flow.constraint} · ${STAGES[constraint].zh}`, tokens.info)}
|
|
{tile(t.flow.wip, summary.wip.toLocaleString(), `max · ${STAGES[wipTop].zh}`, tokens.textSub)}
|
|
</div>
|
|
<div
|
|
title={t.flow.bottleneckTip}
|
|
style={{
|
|
display: 'flex', alignItems: 'center', gap: 6, fontSize: 11, marginBottom: 10,
|
|
padding: '4px 8px', borderRadius: 8,
|
|
background: `${alertColor(stats[bottleneck].status, tokens)}14`,
|
|
border: `1px solid ${alertColor(stats[bottleneck].status, tokens)}3a`,
|
|
}}>
|
|
<span style={{ width: 6, height: 6, borderRadius: '50%', background: alertColor(stats[bottleneck].status, tokens), flexShrink: 0 }} />
|
|
<span style={{ color: tokens.textSub, flexShrink: 0 }}>{t.flow.bottleneck}</span>
|
|
<span style={{ color: tokens.text, fontWeight: 700, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
|
{STAGES[bottleneck].zh}
|
|
</span>
|
|
<span style={{ flex: 1 }} />
|
|
<span style={{ color: alertColor(stats[bottleneck].status, tokens), fontWeight: 800, fontVariantNumeric: 'tabular-nums' }}>
|
|
{fmt(stats[bottleneck].score)}%
|
|
</span>
|
|
</div>
|
|
|
|
{/* 六段流程 */}
|
|
{STAGES.map((s, i) => {
|
|
const st = stats[i];
|
|
const c = alertColor(st.status, tokens);
|
|
const Icon = ICONS[s.icon];
|
|
const active = s.codes.includes(selected);
|
|
const dwellTone = st.dwell <= st.dwellTarget ? tokens.success : st.dwell <= st.dwellTarget * 1.12 ? tokens.warning : tokens.danger;
|
|
const fpqcTone = st.fpqc >= st.fpqcTarget ? tokens.success : st.fpqc >= st.fpqcTarget - 4 ? tokens.warning : tokens.danger;
|
|
const reworkTone = st.rework <= st.reworkTarget ? tokens.success : st.rework <= st.reworkTarget * 1.15 ? tokens.warning : tokens.danger;
|
|
const trend = st.dwellDelta === null ? t.flow.flat
|
|
: st.dwellDelta < -0.05 ? `${t.flow.faster} ${fmt(Math.abs(st.dwellDelta))}${t.flow.unitDay}`
|
|
: st.dwellDelta > 0.05 ? `${t.flow.slower} ${fmt(st.dwellDelta)}${t.flow.unitDay}`
|
|
: t.flow.flat;
|
|
|
|
return (
|
|
<div key={s.key}>
|
|
{/* 段间连线:在制品沿链流动 */}
|
|
{i > 0 && (
|
|
<div style={{ display: 'flex', gap: 8 }}>
|
|
<div style={{ width: 26, flexShrink: 0, position: 'relative', height: 26 }}>
|
|
<svg width={26} height={26} style={{ position: 'absolute', inset: 0, overflow: 'visible' }}>
|
|
<line x1={13} y1={-2} x2={13} y2={28} stroke={tokens.border} strokeWidth={1.4} />
|
|
<line
|
|
className="dash-flow" x1={13} y1={-2} x2={13} y2={28}
|
|
stroke={alertColor(stats[i - 1].status, tokens)} strokeWidth={1.6} strokeDasharray="3 5" strokeLinecap="round"
|
|
/>
|
|
<path d="M 9.5,23 L 13,28 L 16.5,23" fill="none" stroke={tokens.border} strokeWidth={1.4} strokeLinecap="round" />
|
|
</svg>
|
|
<span style={{
|
|
position: 'absolute', left: 30, top: 4, fontSize: 10, whiteSpace: 'nowrap', color: tokens.textMuted,
|
|
fontVariantNumeric: 'tabular-nums',
|
|
}}>
|
|
{t.flow.wip} {stats[i - 1].wip.toLocaleString()}
|
|
</span>
|
|
</div>
|
|
<div style={{ flex: 1, minWidth: 0 }} />
|
|
</div>
|
|
)}
|
|
|
|
<div style={{ display: 'flex', gap: 8 }}>
|
|
{/* 轨道节点 */}
|
|
<div style={{ width: 26, flexShrink: 0, display: 'flex', justifyContent: 'center', paddingTop: 8 }}>
|
|
<span style={{
|
|
display: 'grid', placeItems: 'center', width: 26, height: 26, borderRadius: 9, flexShrink: 0,
|
|
background: `${c}1f`, border: `1px solid ${c}66`, color: c,
|
|
boxShadow: active ? `0 0 10px ${c}66` : 'none',
|
|
}}>
|
|
<Icon size={14} />
|
|
</span>
|
|
</div>
|
|
|
|
{/* 段卡 */}
|
|
<div style={{
|
|
flex: 1, minWidth: 0, marginBottom: 2, borderRadius: 10, padding: '7px 9px',
|
|
background: tokens.panelBgAlt,
|
|
border: `1px solid ${active ? c : tokens.border}`,
|
|
boxShadow: active ? `0 0 0 1px ${c}44, 0 4px 14px ${c}22` : 'none',
|
|
transition: 'border-color 0.2s ease, box-shadow 0.2s ease',
|
|
}}>
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
|
<span className={st.status === 'red' ? 'net-breathe' : undefined} style={{
|
|
width: 7, height: 7, borderRadius: '50%', flexShrink: 0, background: c, boxShadow: `0 0 6px ${c}`,
|
|
}} />
|
|
<span style={{ fontSize: 13.5, fontWeight: 800, color: tokens.text, minWidth: 0, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
|
{s.zh}
|
|
</span>
|
|
<span style={{
|
|
fontSize: 11.5, fontWeight: 800, color: c, flexShrink: 0, fontVariantNumeric: 'tabular-nums',
|
|
fontFamily: 'ui-monospace, monospace',
|
|
}}>{fmt(st.score)}%</span>
|
|
</div>
|
|
<div style={{ fontSize: 10, color: tokens.textMuted, marginBottom: 5, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
|
{s.roleZh} · {trend}
|
|
</div>
|
|
|
|
{/* 段达成条 */}
|
|
<div style={{ height: 3, borderRadius: 99, background: tokens.border, overflow: 'hidden', marginBottom: 6 }}>
|
|
<span style={{
|
|
display: 'block', height: '100%', width: `${Math.min(100, st.score)}%`, background: c,
|
|
transition: 'width 0.4s ease',
|
|
}} />
|
|
</div>
|
|
|
|
{/* 过程四量 */}
|
|
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '2px 8px', marginBottom: 6 }}>
|
|
{stat(t.flow.dwell, `${fmt(st.dwell)}${t.flow.unitDay}`, dwellTone)}
|
|
{stat(t.flow.flow, `${st.flow.toLocaleString()}`, tokens.textSub)}
|
|
{stat(t.flow.fpqc, `${fmt(st.fpqc)}%`, fpqcTone)}
|
|
{stat(t.flow.rework, `${st.rework}`, reworkTone)}
|
|
</div>
|
|
|
|
{/* 关联指标片:真实 metric_node,点开联动中央看板 */}
|
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
|
|
{s.codes.map(cd => {
|
|
const n = byCode.get(cd);
|
|
if (!n) return null;
|
|
const nc = alertColor(levelAt(n, period), tokens);
|
|
const on = cd === selected;
|
|
const val = valueAt(n, period);
|
|
return (
|
|
<button
|
|
key={cd} onClick={() => onSelect(cd)} className="ghost-btn"
|
|
title={`${t.flow.linked} ${n.code} · ${n.name_zh} · ${t.flow.clickTip}`}
|
|
style={{
|
|
display: 'flex', alignItems: 'center', gap: 4, maxWidth: '100%', cursor: 'pointer',
|
|
padding: '2px 6px', borderRadius: 7, fontSize: 10.5,
|
|
background: on ? `${nc}22` : tokens.cardBg,
|
|
border: `1px solid ${on ? nc : tokens.border}`,
|
|
color: tokens.textSub,
|
|
}}
|
|
>
|
|
<span style={{ width: 5, height: 5, borderRadius: '50%', background: nc, flexShrink: 0 }} />
|
|
<span style={{ minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', color: on ? tokens.text : undefined }}>
|
|
{n.name_zh}
|
|
</span>
|
|
<span style={{ color: nc, fontWeight: 700, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace', flexShrink: 0 }}>
|
|
{fmt(val)}{n.unit}
|
|
</span>
|
|
<span style={{ color: tokens.textMuted, fontVariantNumeric: 'tabular-nums', flexShrink: 0 }}>
|
|
{fmt(achieveAt(n, period), 0)}%
|
|
</span>
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
|
|
<div style={{ fontSize: 10, color: tokens.textMuted, lineHeight: 1.6, padding: '8px 2px 12px' }}>
|
|
{periodLabel(period)} · {t.flow.wipTip}
|
|
</div>
|
|
</PanelBody>
|
|
);
|
|
}
|