oee
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
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<QIcon, typeof Wrench> = { 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<string | null>(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) => (
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<div style={{ fontSize: 10, color: tokens.textMuted, whiteSpace: 'nowrap' }}>{label}</div>
|
||||
<div style={{
|
||||
fontSize: 12.5, fontWeight: 700, color: tone, fontVariantNumeric: 'tabular-nums',
|
||||
fontFamily: 'ui-monospace, monospace', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
|
||||
}}>{value}</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'stretch', gap: 0, minWidth: 0 }}>
|
||||
{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 (
|
||||
<Fragment key={r.key}>
|
||||
{i > 0 && (
|
||||
<div
|
||||
title={`${ROLES[i - 1].key}→${r.key} · ${t.flow.wip} ${stats[i - 1].wip}\n${t.flow.wipTip}`}
|
||||
style={{ width: 34, flexShrink: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 2 }}
|
||||
>
|
||||
<svg width={30} height={10} style={{ overflow: 'visible' }}>
|
||||
<line x1={0} y1={5} x2={30} y2={5} stroke={tokens.border} strokeWidth={2} />
|
||||
<line className="dash-flow" x1={0} y1={5} x2={30} y2={5}
|
||||
stroke={alertColor(stats[i - 1].status, tokens)} strokeWidth={2.2} strokeDasharray="4 5" strokeLinecap="round" />
|
||||
<path d="M 24,1 L 30,5 L 24,9" fill="none" stroke={tokens.border} strokeWidth={2} strokeLinecap="round" />
|
||||
</svg>
|
||||
<span style={{ fontSize: 9.5, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap' }}>
|
||||
{stats[i - 1].wip}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
onClick={() => setOpen(isOpen ? null : r.key)}
|
||||
data-role={`qflow-${r.key}`}
|
||||
aria-expanded={isOpen}
|
||||
title={`${r.duty}|${t.qflow.hint}`}
|
||||
style={{
|
||||
flex: '1 1 0', minWidth: 0, textAlign: 'left', cursor: 'pointer', font: 'inherit', color: 'inherit',
|
||||
borderRadius: 11, padding: '7px 10px',
|
||||
background: isOpen ? tokens.accentBg : tokens.panelBgAlt,
|
||||
border: `1px solid ${isOpen ? tokens.accent : st.status === 'red' ? c : tokens.border}`,
|
||||
boxShadow: st.status === 'red' ? `0 0 0 1px ${c}33, 0 4px 14px ${c}1f` : 'none',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<span style={{
|
||||
display: 'grid', placeItems: 'center', width: 20, height: 20, borderRadius: 6, flexShrink: 0,
|
||||
background: `${c}1f`, border: `1px solid ${c}66`, color: c,
|
||||
}}><Icon size={12} /></span>
|
||||
<span style={{ fontSize: 11, fontWeight: 800, color: c, letterSpacing: '0.06em', fontFamily: 'ui-monospace, monospace', flexShrink: 0 }}>{r.key}</span>
|
||||
<span style={{ fontSize: 13, fontWeight: 800, color: tokens.text, minWidth: 0, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{r.zh}</span>
|
||||
{tag && (
|
||||
<span style={{
|
||||
fontSize: 9.5, fontWeight: 700, padding: '0 5px', borderRadius: 5, lineHeight: '15px', flexShrink: 0,
|
||||
color: c, background: `${c}14`, border: `1px solid ${c}44`,
|
||||
}}>{tag}</span>
|
||||
)}
|
||||
<span style={{ fontSize: 12, fontWeight: 800, color: c, flexShrink: 0, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace' }}>{fmt(st.score)}%</span>
|
||||
{isOpen ? <ChevronUp size={13} color={tokens.textMuted} /> : <ChevronDown size={13} color={tokens.textMuted} />}
|
||||
</div>
|
||||
<div style={{ fontSize: 10, color: tokens.textMuted, margin: '2px 0 4px', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
{r.duty} · {trend}
|
||||
</div>
|
||||
<div style={{ height: 3, borderRadius: 99, background: tokens.border, overflow: 'hidden', marginBottom: 5 }}>
|
||||
<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: 'repeat(4, minmax(0, 1fr))', gap: 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>
|
||||
</button>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{openIdx >= 0 && (() => {
|
||||
const r = ROLES[openIdx];
|
||||
const st = stats[openIdx];
|
||||
const c = alertColor(st.status, tokens);
|
||||
return (
|
||||
<div data-role="qflow-detail" className="card-in" style={{
|
||||
display: 'flex', gap: 12, alignItems: 'stretch', padding: '8px 10px', borderRadius: 11,
|
||||
background: tokens.panelBgAlt, border: `1px solid ${tokens.borderAccent}`,
|
||||
}}>
|
||||
<div style={{ flex: '0 0 260px', minWidth: 0, fontSize: 10.5, lineHeight: 1.55, color: tokens.textSub }}>
|
||||
<div style={{ fontSize: 11.5, fontWeight: 800, color: c, marginBottom: 3 }}>{r.key} · {r.zh}</div>
|
||||
<div><span style={{ color: tokens.textMuted }}>{t.qflow.input} </span>{r.input}</div>
|
||||
<div><span style={{ color: tokens.textMuted }}>{t.qflow.output} </span><b style={{ color: tokens.text, fontWeight: 600 }}>{r.output}</b></div>
|
||||
<div style={{ display: 'flex', alignItems: 'baseline', gap: 4 }}>
|
||||
<ArrowDownRight size={11} style={{ flexShrink: 0, color: c }} />
|
||||
<span><span style={{ color: tokens.textMuted }}>{t.qflow.next} </span>{r.next}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div title={t.qflow.kpiTip} style={{ flex: 1, minWidth: 0, display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: 8 }}>
|
||||
{st.kpis.map(k => {
|
||||
const kc = alertColor(k.status, tokens);
|
||||
return (
|
||||
<div key={k.code} title={`${k.code} · ${k.zh}`} style={{
|
||||
minWidth: 0, padding: '5px 8px', borderRadius: 8, background: tokens.cardBg, border: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<div style={{ fontSize: 10.5, color: tokens.textSub, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{k.zh}</div>
|
||||
<div style={{ display: 'flex', alignItems: 'baseline', gap: 4 }}>
|
||||
<span style={{ fontSize: 14, fontWeight: 800, color: kc, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace' }}>
|
||||
{fmt(k.value, k.decimals)}{k.unit}
|
||||
</span>
|
||||
<span style={{ fontSize: 9.5, color: tokens.textMuted }}>/{k.target}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 9.5, fontWeight: 700, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>{k.achieve}%</span>
|
||||
</div>
|
||||
<div style={{ fontSize: 9.5, color: tokens.textMuted, lineHeight: 1.45, marginTop: 2 }}>
|
||||
{t.qflow.situation}:{k.base}{k.unit} · {t.qflow.vsBase} {k.vsBase > 0 ? '+' : ''}{fmt(k.vsBase, k.decimals)}{k.unit === '%' ? 'pt' : k.unit}
|
||||
<br />{k.now}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user