299 lines
16 KiB
TypeScript
299 lines
16 KiB
TypeScript
import { useState } from 'react';
|
||
import { ArrowDownRight, Cog, Ruler, ShieldCheck, Wrench } from 'lucide-react';
|
||
import { useTheme } from '../../context/ThemeContext';
|
||
import { useText } from '../../i18n/useText';
|
||
import { PanelBody } from '../layout/PanelShell';
|
||
import { alertColor, fmt } from '../../lib/metric';
|
||
import { periodLabel } from '../../lib/time';
|
||
import { ROLES, qualityStats, type QIcon } from '../../lib/qualityFlow';
|
||
|
||
/**
|
||
* 质量预防流程看板(PE → IE → QE → ME 四角色 · 过程指标层)。
|
||
*
|
||
* 版式照抄三菱电机那版「流程效能」:瓶颈横幅 → 自上而下的角色轨道卡,
|
||
* 段与段之间用虚线箭头连起来,线上标在制品堆了多少。
|
||
* 原本顶部那四个汇总砖(闭环周期 / 一次通过 / KPI 达标 / 在制品)已提到整页抬头
|
||
* (见 MecHeader 的核心指标带,同一个 qualityStats 源),这里不再重复,直接进瓶颈与角色段。
|
||
* 与结果看板的分工写在标题下那句 hint 里:这里看**过程**(一张风险点检单在四个质量口
|
||
* 各停多久、一次通过多少、退回多少),良率/客诉/质量成本那些**结果**仍归指标树。
|
||
*
|
||
* 每张卡下方是该企业质量职责表拆出来的 4 项质量 KPI(共 16 项):
|
||
* 基线取「当前实施情况」那一列,目标取改善方向,数字为确定性模拟、随底部时间轴演变。
|
||
*/
|
||
interface Props {
|
||
/** 全局时间游标:与中央看板同一时点读数 */
|
||
period: number;
|
||
expanded: boolean;
|
||
}
|
||
|
||
const ICONS: Record<QIcon, typeof Wrench> = {
|
||
wrench: Wrench, ruler: Ruler, shield: ShieldCheck, cog: Cog,
|
||
};
|
||
|
||
/** 左侧轨道节点(角色图标)的列宽;段间连线已独立居中,不再占用这一列 */
|
||
const RAIL = 26;
|
||
|
||
/**
|
||
* 段间连线的高度。留出一截能看见单据往下流的路即可;
|
||
* 104px 显得拖沓,收到 52px,让四段卡更紧凑。
|
||
*/
|
||
const LINK = 52;
|
||
|
||
export default function QualityFlowPanel({ period, expanded }: Props) {
|
||
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);
|
||
/* 带下标的四段:stats[] 与段间连线都要按原顺序取数 */
|
||
const segs = ROLES.map((r, i) => ({ r, i }));
|
||
|
||
/** 过程量小格:标签 + 值 + 目标提示 */
|
||
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.textSub, marginBottom: 8,
|
||
padding: '6px 9px', borderRadius: 8, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
|
||
}}>
|
||
{t.qflow.hint}
|
||
</div>
|
||
|
||
{/* 瓶颈横幅:达成率最低的一段,和约束段一起说清楚 */}
|
||
<div
|
||
title={`${t.flow.bottleneckTip};${t.flow.constraint}:${ROLES[constraint].zh}`}
|
||
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.qflow.bottleneck}</span>
|
||
<span style={{ color: tokens.text, fontWeight: 700, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||
{ROLES[bottleneck].key} · {ROLES[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>
|
||
|
||
{/* 四段角色流程 */}
|
||
{segs.map(({ r, i }, si) => {
|
||
const st = stats[i];
|
||
const c = alertColor(st.status, tokens);
|
||
const Icon = ICONS[r.icon];
|
||
/* 段间连线取前一段,线上标该段积压的在制品 */
|
||
const from = si > 0 ? segs[si - 1] : null;
|
||
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;
|
||
|
||
return (
|
||
<div key={r.key}>
|
||
{/* 段间连线:单据沿链流转,线上标上一段积压 */}
|
||
{from && (
|
||
/* 段间箭头放在整栏水平中央,不再贴着左缘的轨道图标;
|
||
标签跟在箭头右侧,居中留白左右对称 */
|
||
<div style={{ position: 'relative', width: '100%', height: LINK }}>
|
||
<svg
|
||
width={RAIL} height={LINK}
|
||
style={{ position: 'absolute', left: '50%', top: 0, transform: 'translateX(-50%)', overflow: 'visible' }}
|
||
>
|
||
{/* 上端探出 2px 贴住上一张卡的下沿,箭头正好落在下一张卡的上沿 */}
|
||
<line x1={13} y1={-2} x2={13} y2={LINK} stroke={tokens.border} strokeWidth={2} />
|
||
<line
|
||
className="dash-flow" x1={13} y1={-2} x2={13} y2={LINK}
|
||
stroke={alertColor(stats[from.i].status, tokens)} strokeWidth={2.4} strokeDasharray="4 5" strokeLinecap="round"
|
||
/>
|
||
<path d={`M 8.5,${LINK - 6} L 13,${LINK} L 17.5,${LINK - 6}`} fill="none" stroke={tokens.border} strokeWidth={2} strokeLinecap="round" />
|
||
</svg>
|
||
<span style={{
|
||
position: 'absolute', left: 'calc(50% + 20px)', top: LINK / 2 - 7,
|
||
fontSize: 10, lineHeight: '14px', whiteSpace: 'nowrap', color: tokens.textMuted,
|
||
fontVariantNumeric: 'tabular-nums',
|
||
}}>
|
||
{from.r.key}→{r.key} · {t.flow.wip} {stats[from.i].wip}
|
||
</span>
|
||
</div>
|
||
)}
|
||
|
||
<div style={{ display: 'flex', gap: 8 }}>
|
||
{/* 轨道节点 */}
|
||
<div style={{ width: RAIL, flexShrink: 0, display: 'flex', justifyContent: 'center', paddingTop: 8 }}>
|
||
<span style={{
|
||
display: 'grid', placeItems: 'center', width: RAIL, height: RAIL, borderRadius: 9, flexShrink: 0,
|
||
background: `${c}1f`, border: `1px solid ${c}66`, color: c,
|
||
}}>
|
||
<Icon size={14} />
|
||
</span>
|
||
</div>
|
||
|
||
{/* 角色卡 */}
|
||
<div style={{
|
||
flex: 1, minWidth: 0, marginBottom: 2, borderRadius: 10, padding: '7px 9px',
|
||
background: tokens.panelBgAlt,
|
||
border: `1px solid ${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 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: 11, fontWeight: 800, color: c, flexShrink: 0, letterSpacing: '0.06em',
|
||
fontFamily: 'ui-monospace, monospace',
|
||
}}>{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>
|
||
<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' }}>
|
||
{r.duty} · {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>
|
||
|
||
{/* 流转三行:输入 → 输出 → 后续动作。收起态宽度不够,只在展开态显示 */}
|
||
{expanded && (
|
||
<div style={{
|
||
fontSize: 10, lineHeight: 1.5, color: tokens.textSub, marginBottom: 6,
|
||
padding: '5px 7px', borderRadius: 8, background: tokens.cardBg, border: `1px solid ${tokens.border}`,
|
||
}}>
|
||
<div style={{ display: 'flex', gap: 4, minWidth: 0 }}>
|
||
<span style={{ color: tokens.textMuted, flexShrink: 0 }}>{t.qflow.input}</span>
|
||
<span style={{ minWidth: 0 }}>{r.input}</span>
|
||
</div>
|
||
<div style={{ display: 'flex', gap: 4, minWidth: 0 }}>
|
||
<span style={{ color: tokens.textMuted, flexShrink: 0 }}>{t.qflow.output}</span>
|
||
<span style={{ minWidth: 0, color: tokens.text, fontWeight: 600 }}>{r.output}</span>
|
||
</div>
|
||
<div style={{ display: 'flex', alignItems: 'baseline', gap: 4, minWidth: 0 }}>
|
||
<ArrowDownRight size={11} style={{ flexShrink: 0, color: c }} />
|
||
<span style={{ color: tokens.textMuted, flexShrink: 0 }}>{t.qflow.next}</span>
|
||
<span style={{ minWidth: 0 }}>{r.next}</span>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{/* 本段质量 KPI:4 项/角色,点开看职责表现状原文 */}
|
||
<div style={{ display: 'flex', alignItems: 'center', gap: 5, marginBottom: 4 }}>
|
||
<span style={{ fontSize: 10, color: tokens.textMuted, flexShrink: 0 }}>{t.qflow.kpiGroup}</span>
|
||
<span style={{ flex: 1, height: 1, background: tokens.border }} />
|
||
{/* 现状原文要两行才放得下,收起态宽度不够,只在展开态给这个入口 */}
|
||
{expanded && (
|
||
<button
|
||
onClick={() => setOpen(isOpen ? null : r.key)}
|
||
className="ghost-btn"
|
||
style={{
|
||
fontSize: 9.5, fontWeight: 700, cursor: 'pointer', padding: '1px 5px', borderRadius: 6,
|
||
color: isOpen ? tokens.onAccent : tokens.textMuted,
|
||
background: isOpen ? tokens.accent : tokens.cardBg,
|
||
border: `1px solid ${isOpen ? tokens.accent : tokens.border}`,
|
||
}}
|
||
>
|
||
{isOpen ? t.common.collapse : t.common.detail}
|
||
</button>
|
||
)}
|
||
</div>
|
||
|
||
<div style={{ display: 'grid', gridTemplateColumns: expanded ? '1fr 1fr' : '1fr', gap: 4 }}>
|
||
{st.kpis.map(k => {
|
||
const kc = alertColor(k.status, tokens);
|
||
return (
|
||
<div
|
||
key={k.code}
|
||
title={`${k.code} · ${k.zh}|${t.qflow.situation}:${k.now}|${t.qflow.targetShort} ${k.target}${k.unit}(现状 ${k.base}${k.unit})`}
|
||
style={{
|
||
minWidth: 0, padding: '4px 6px', borderRadius: 8,
|
||
background: tokens.cardBg, border: `1px solid ${tokens.border}`,
|
||
}}
|
||
>
|
||
<div style={{
|
||
fontSize: 10, color: tokens.textSub, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
|
||
}}>{k.zh}</div>
|
||
<div style={{ display: 'flex', alignItems: 'baseline', gap: 4 }}>
|
||
<span style={{
|
||
fontSize: 13, fontWeight: 800, color: kc, fontVariantNumeric: 'tabular-nums',
|
||
fontFamily: 'ui-monospace, monospace', lineHeight: 1.3,
|
||
}}>{fmt(k.value, k.decimals)}{k.unit}</span>
|
||
<span style={{ fontSize: 9.5, color: tokens.textMuted, flexShrink: 0 }}>
|
||
/{k.target}
|
||
</span>
|
||
<span style={{ flex: 1 }} />
|
||
<span style={{
|
||
fontSize: 9.5, fontWeight: 700, color: tokens.textMuted, flexShrink: 0,
|
||
fontVariantNumeric: 'tabular-nums',
|
||
}}>{k.achieve}%</span>
|
||
</div>
|
||
{/* 现状原文:只在展开态且点了「详情」时铺出来,避免左栏变成文档堆 */}
|
||
{isOpen && expanded && (
|
||
<div style={{ fontSize: 9.5, color: tokens.textMuted, lineHeight: 1.45, marginTop: 2 }}>
|
||
{/* 比率类指标的差值用百分点表述,写成「+46.6%」会被读成相对增幅 */}
|
||
{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>
|
||
</div>
|
||
);
|
||
})}
|
||
|
||
{/* 数据来源口径:明确标注这是模拟读数,以及换成真实数据要接哪几张表 */}
|
||
<div style={{
|
||
fontSize: 9.5, color: tokens.textMuted, lineHeight: 1.6, marginTop: 8,
|
||
padding: '6px 8px', borderRadius: 8, background: tokens.cardBg, border: `1px solid ${tokens.border}`,
|
||
}}>
|
||
{periodLabel(period)} · {t.flow.wipTip}
|
||
<br />{t.qflow.dataSource}
|
||
<br />{t.qflow.kpiTip}
|
||
</div>
|
||
</PanelBody>
|
||
);
|
||
}
|