import { Fragment, useState } from 'react'; import { ArrowDownRight, ChevronDown, ChevronUp, Cog, Ruler, ShieldCheck, Wrench } from 'lucide-react'; import { useTheme } from '../../context/ThemeContext'; import { useText } from '../../i18n/useText'; import { alertColor, fmt } from '../../lib/metric'; import { ROLES, qualityStats, type QIcon } from '../../lib/qualityFlow'; /** * 质量流程横条(PE → IE → QE → ME):与左栏 QualityFlowPanel 同一个 qualityStats 源, * 只换成横向一行等分的紧凑形态;点某段向下展开该段流转三行 + 4 项质量 KPI(含现状原文)。 */ const ICONS: Record = { wrench: Wrench, ruler: Ruler, shield: ShieldCheck, cog: Cog }; export default function QualityFlowStrip({ period }: { period: number }) { const { tokens } = useTheme(); const { t } = useText(); const [open, setOpen] = useState(null); const { stats, summary } = qualityStats(period); const bottleneck = ROLES.findIndex(r => r.key === summary.bottleneckKey); const constraint = ROLES.findIndex(r => r.key === summary.constraintKey); const openIdx = ROLES.findIndex(r => r.key === open); const stat = (label: string, value: string, tone: string) => (
{label}
{value}
); return (
{ROLES.map((r, i) => { const st = stats[i]; const c = alertColor(st.status, tokens); const Icon = ICONS[r.icon]; 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; const isOpen = open === r.key; const tag = i === bottleneck ? t.qflow.bottleneck : i === constraint ? t.flow.constraint : null; return ( {i > 0 && (
{stats[i - 1].wip}
)}
); })}
{openIdx >= 0 && (() => { const r = ROLES[openIdx]; const st = stats[openIdx]; const c = alertColor(st.status, tokens); return (
{r.key} · {r.zh}
{t.qflow.input} {r.input}
{t.qflow.output} {r.output}
{t.qflow.next} {r.next}
{st.kpis.map(k => { const kc = alertColor(k.status, tokens); return (
{k.zh}
{fmt(k.value, k.decimals)}{k.unit} /{k.target} {k.achieve}%
{t.qflow.situation}:{k.base}{k.unit} · {t.qflow.vsBase} {k.vsBase > 0 ? '+' : ''}{fmt(k.vsBase, k.decimals)}{k.unit === '%' ? 'pt' : k.unit}
{k.now}
); })}
); })()}
); }