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; selected: string; onSelect: (code: string) => void; period: number; } const ICONS: Record = { 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) => (
{label}
{value}
{sub &&
{sub}
}
); /** 过程量小格:标签 + 值 + 目标/环比提示 */ const stat = (label: string, value: string, tone: string) => (
{label} {value}
); return ( {/* 口径提示:过程 vs 结果 */}
{t.flow.hint}
{/* 全链汇总 */}
{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)}
{t.flow.bottleneck} {STAGES[bottleneck].zh} {fmt(stats[bottleneck].score)}%
{/* 六段流程 */} {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 (
{/* 段间连线:在制品沿链流动 */} {i > 0 && (
{t.flow.wip} {stats[i - 1].wip.toLocaleString()}
)}
{/* 轨道节点 */}
{/* 段卡 */}
{s.zh} {fmt(st.score)}%
{s.roleZh} · {trend}
{/* 段达成条 */}
{/* 过程四量 */}
{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)}
{/* 关联指标片:真实 metric_node,点开联动中央看板 */}
{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 ( ); })}
); })}
{periodLabel(period)} · {t.flow.wipTip}
); }