Files
ai-platform/src/modules/tfamd-oee/components/workspace/views.tsx
T
2026-11-19 10:09:33 +08:00

927 lines
51 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { ReactNode } from 'react';
import { AlertTriangle, ChevronRight } from 'lucide-react';
import { useTheme } from '../../context/ThemeContext';
import type { ThemeTokens } from '../../context/ThemeContext';
import type { MetricLink, MetricNode } from '../../data/sqlite';
import {
DEFECT_COLUMNS, DEFAULT_METRIC, METRICS, SEVERITY_WEIGHT,
defectByProcess, defectPareto, driftRows, duplicateHits, masterModel, methodCompareRows,
predictionRows, riskChecklistRows, riskPoints, rootCauseGroups, severityCount, watchList,
type DetailTable, type QualityMetric, type Status,
} from '../../lib/qualityMetrics';
import {
abnormalModelsAt, cockpitTilesAt, coverageModelAt, doeModelAt, featureModelsAt,
lineModelsAt, metricAt, overallDefectRateAt, radarModelAt, REPLAY_DETAIL_NOTE,
stationModelsAt, trendModelAt, yieldPctAt, defectPctAt,
} from '../../lib/replayQuality';
import { CURRENT_PERIOD, periodLabel } from '../../lib/oeeTime';
import { replayTag } from '../../lib/replay';
import { QAP_CALIBER, calc } from '../../data/qap';
import { alertKindLabel, type AlertKind } from '../../lib/qualityAlerts';
import { HBarChart, RadarChart, RiskMatrix, StackedBarChart, TrendChart, VBarChart } from './charts';
/** 保留给 App / 图谱 / 时间轴的旧指标树契约,六个可视化页签不再消费它 */
export interface ViewProps {
selected: string;
byCode: Map<string, MetricNode>;
flat: MetricNode[];
links: MetricLink[];
onSelect: (code: string) => void;
}
/** 可视化页签的契约:当前主体(品质指标编码)+ 下钻回调+全局回放游标 */
export interface VizProps {
subject: string;
onOpen: (code: string) => void;
/** 0-11:2025-11 → 2026-10;11 为源表当期 */
period: number;
}
/** 期次标记:当期显示源表快照,历史期显示回放推算 */
function PeriodTag({ period }: { period: number }) {
return <SnapshotTag label={period === CURRENT_PERIOD ? '源表现算快照' : `${replayTag(period)} · 源表反推`} />;
}
/* ══════════════════ 公共小块 ══════════════════ */
export const statusColor = (s: Status, tk: ThemeTokens): string =>
s === 'red' ? tk.danger : s === 'yellow' ? tk.warning : s === 'green' ? tk.success : tk.textMuted;
const STATUS_LABEL: Record<Status, string> = { red: '红档', yellow: '黄档', green: '达标', na: '源表未设判定线' };
function StatusChip({ status }: { status: Status }) {
const { tokens } = useTheme();
const c = statusColor(status, tokens);
return (
<span style={{
fontSize: 11, padding: '1px 8px', borderRadius: 9, fontWeight: 700, whiteSpace: 'nowrap',
background: `${c}1f`, color: c, border: `1px solid ${c}44`,
}}>{STATUS_LABEL[status]}</span>
);
}
/** 源表快照标记:本页读数由数据集现算,与底部时间轴无关 */
function SnapshotTag({ label = '源表现算快照' }: { label?: string }) {
const { tokens } = useTheme();
return (
<span style={{
fontSize: 10.5, color: tokens.textMuted, background: tokens.tableHeaderBg,
border: `1px solid ${tokens.border}`, borderRadius: 5, padding: '1px 6px', whiteSpace: 'nowrap',
}}>{label}</span>
);
}
export function Card({ title, right, children, tone, full }: {
title: string; right?: ReactNode; children: ReactNode; tone?: string; full?: boolean;
}) {
const { tokens } = useTheme();
return (
<div className="card-in" style={{
background: tokens.cardBg, border: `1px solid ${tokens.border}`, borderRadius: 11,
padding: '10px 13px 12px', boxShadow: tokens.cardShadow, minWidth: 0,
gridColumn: full ? '1 / -1' : undefined,
}}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
<span style={{ width: 3, height: 13, borderRadius: 2, background: tone ?? tokens.accent }} />
<span style={{ fontSize: 12.5, fontWeight: 700, color: tokens.text }}>{title}</span>
<span style={{ flex: 1 }} />
{right}
</div>
{children}
</div>
);
}
function Th({ children, right }: { children: ReactNode; right?: boolean }) {
const { tokens } = useTheme();
return (
<th style={{
textAlign: right ? 'right' : 'left', padding: '6px 8px', fontSize: 11, fontWeight: 600,
color: tokens.textSub, background: tokens.tableHeaderBg, whiteSpace: 'nowrap',
borderBottom: `1px solid ${tokens.border}`,
}}>{children}</th>
);
}
function Td({ children, right, mono, color }: { children: ReactNode; right?: boolean; mono?: boolean; color?: string }) {
const { tokens } = useTheme();
return (
<td style={{
textAlign: right ? 'right' : 'left', padding: '5px 8px', fontSize: 11.5,
color: color ?? tokens.textSub, borderBottom: `1px solid ${tokens.borderSub}`,
fontVariantNumeric: mono ? 'tabular-nums' : undefined,
fontFamily: mono ? 'ui-monospace, monospace' : undefined,
}}>{children}</td>
);
}
/** 一句口径说明,放在卡片底部,避免图上数字与原表口径各说各话 */
function Note({ children }: { children: ReactNode }) {
const { tokens } = useTheme();
return <div style={{ marginTop: 7, fontSize: 10.5, lineHeight: 1.5, color: tokens.textMuted }}>{children}</div>;
}
const cellText = (v: unknown) => (v === null || v === undefined || v === '' ? '—' : String(v));
/**
* 明细表:列名里带「现算」的表头标出来,提醒这不是源表原有列;
* focus 命中的行高亮,作为从柱子下钻过来的落点。
*/
function DataTable({ table, max = 99 }: { table: DetailTable; max?: number }) {
const { tokens } = useTheme();
const rows = table.rows.slice(0, max);
return (
<div style={{ overflowX: 'auto' }}>
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
<thead><tr>
{table.columns.map(c => (
<Th key={c} right={/^[\d.,%()-]+$/.test(cellText(table.rows[0]?.[c]))}>
{c}
{c.includes('现算') && <span style={{ color: tokens.accent, marginLeft: 3, fontSize: 9.5 }}>◆</span>}
</Th>
))}
</tr></thead>
<tbody>
{rows.map((r, i) => {
const focused = !!table.focus && cellText(r[table.focus.column]) === table.focus.value;
return (
<tr key={i} style={{
background: focused ? tokens.accentBg : i % 2 ? tokens.tableRowAlt : 'transparent',
boxShadow: focused ? `inset 3px 0 0 ${tokens.accent}` : undefined,
}}>
{table.columns.map(c => {
const raw = r[c];
const numeric = typeof raw === 'number';
return (
<Td key={c} mono={numeric} right={numeric} color={focused ? tokens.text : undefined}>
{cellText(raw)}
</Td>
);
})}
</tr>
);
})}
</tbody>
</table>
{table.rows.length > rows.length && (
<Note>共 {table.rows.length} 行,此处显示前 {rows.length} 行。</Note>
)}
</div>
);
}
/** 严重度 → 展示色(字典与检查表共用) */
const severityColor = (s: string, tk: ThemeTokens) =>
s === '致命' ? tk.danger : s === '严重' ? tk.warning : tk.info;
/** 缺陷四类配色:与 DS-09 列序一致,堆叠条与图例复用 */
const DEFECT_COLORS = (tk: ThemeTokens) => [tk.accent, tk.danger, tk.warning, tk.info];
/* ══════════════════ 1. 全景驾驶舱 ══════════════════ */
/** 告警类型 → 品质指标脊里的对应读数,点关注清单就落到那张明细卡 */
const KIND_TO_METRIC: Record<AlertKind, string> = {
abnormal: 'ALERT-POOL', drift: 'DRIFT-CURD', bottleneck: 'LOAD-MAX', gap: 'STD-GAP',
};
export function CockpitView({ onOpen, period }: VizProps) {
const { tokens } = useTheme();
const radar = radarModelAt(period);
const tiles = cockpitTilesAt(period);
const watch = watchList();
const levelColor = (l: string) => (l === 'red' ? tokens.danger : l === 'orange' ? tokens.warning : tokens.info);
return (
<div style={{ display: 'grid', gridTemplateColumns: '330px 1fr', gap: 12, alignItems: 'start' }}>
<Card
title="结构特征良率雷达"
right={<PeriodTag period={period} />}
tone={tokens.accent}
>
<RadarBlock radar={radar} onOpen={onOpen} />
<Note>
六轴=DS-09 六类结构特征的综合良率(100 − 四类缺陷率之和,现算);虚线=基准轴 {radar.baselineLabel}。
多边形越瘪的那一角就是当下最该防的结构。
</Note>
</Card>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, minWidth: 0 }}>
<Card title={`品质核心读数 · ${tiles.length}`} right={<PeriodTag period={period} />}>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(150px, 1fr))', gap: 8 }}>
{tiles.map((tile, i) => {
const c = statusColor(tile.status, tokens);
return (
<button
key={tile.code}
onClick={() => onOpen(tile.code)}
className="card-in ghost-btn"
style={{
animationDelay: `${i * 18}ms`, textAlign: 'left', cursor: 'pointer', padding: '7px 9px',
borderRadius: 9, background: tokens.panelBgAlt,
border: `1px solid ${tile.status === 'na' ? tokens.border : `${c}55`}`,
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
<span style={{
width: 6, height: 6, borderRadius: 6, flex: '0 0 6px',
background: tile.status === 'na' ? tokens.borderAccent : c,
}} />
<span style={{ fontSize: 10.5, color: tokens.textMuted, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{tile.label}</span>
</div>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 3, marginTop: 2 }}>
<span style={{ fontSize: 20, fontWeight: 800, color: tokens.text, fontVariantNumeric: 'tabular-nums', lineHeight: 1.3 }}>{tile.value}</span>
<span style={{ fontSize: 10, color: tokens.textMuted }}>{tile.unit}</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 9.5, color: tokens.accent, fontFamily: 'ui-monospace, monospace' }}>{tile.ds}</span>
</div>
<div style={{ fontSize: 10, color: tokens.textMuted, marginTop: 2, lineHeight: 1.4, whiteSpace: 'normal' }}>{tile.sub}</div>
</button>
);
})}
</div>
<Note>
八块读数随底部回放同轴:当期取源表快照,历史期由 2026-10 快照按统一质量曲线回推,切换时点可见缺陷率、良率、负荷与告警量的时空迁移。
每块读数各自回到自己的数据集;点任意一块 → 「指标明细」页签看判定线、口径与源表明细。
</Note>
</Card>
<Card title={`当前关注 · Top ${watch.length}`} tone={tokens.warning} right={<SnapshotTag label="源表当期告警队列" />}>
{watch.map((a, i) => {
const c = levelColor(a.level);
return (
<div
key={a.id}
onClick={() => onOpen(KIND_TO_METRIC[a.kind])}
className="ghost-btn"
style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '4px 6px', borderRadius: 6, cursor: 'pointer' }}
>
<AlertTriangle size={12} style={{ color: c, flex: '0 0 12px' }} />
<span style={{ fontSize: 10, padding: '0 5px', borderRadius: 5, background: `${c}1f`, color: c, fontWeight: 700, flex: '0 0 auto' }}>{alertKindLabel(a.kind)}</span>
<span style={{ fontSize: 11.5, color: tokens.text, width: 130, flex: '0 0 130px', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{a.title}</span>
<span style={{ fontSize: 11, color: tokens.textMuted, flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{a.subject} · {a.action}
</span>
<span style={{ fontSize: 11.5, color: c, fontVariantNumeric: 'tabular-nums', fontWeight: 700, whiteSpace: 'nowrap' }}>
{a.metric.label} {a.metric.value}
</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted, whiteSpace: 'nowrap' }}>{a.owner || a.role}</span>
{i === 0 && <span style={{ fontSize: 9.5, color: tokens.onAccent, background: c, borderRadius: 6, padding: '0 5px' }}>TOP</span>}
</div>
);
})}
<Note>队列按「先分档再分类型」排:滞留天数、偏移率、负荷率三个量纲不跨类型硬比,避免排出假次序。</Note>
</Card>
</div>
</div>
);
}
/** 雷达:良率刻度从 60% 起才看得出差异,直接 0 起会让六边形糊成一团 */
function RadarBlock({ radar, onOpen }: { radar: ReturnType<typeof radarModelAt>; onOpen: (code: string) => void }) {
const { tokens } = useTheme();
const min = 60;
const scaled = radar.values.map(v => Math.max(0, ((v - min) / (100 - min)) * 100));
const compare = radar.compare.map(v => Math.max(0, ((v - min) / (100 - min)) * 100));
return (
<div>
<RadarChart axes={radar.axes} values={scaled} compare={compare} height={311} />
<div style={{ display: 'flex', gap: 12, justifyContent: 'center', marginTop: 2 }}>
<span style={{ display: 'flex', alignItems: 'center', gap: 4, fontSize: 10.5, color: tokens.textSub }}>
<span style={{ width: 12, height: 2.5, background: tokens.accent, borderRadius: 2 }} />六类特征综合良率
</span>
<span style={{ display: 'flex', alignItems: 'center', gap: 4, fontSize: 10.5, color: tokens.textSub }}>
<span style={{ width: 12, height: 2.5, background: tokens.info, borderRadius: 2, opacity: 0.7 }} />基准平板拼焊
</span>
</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 5, marginTop: 8, justifyContent: 'center' }}>
{radar.axes.map((axis, i) => (
<button
key={axis}
onClick={() => onOpen(radar.codes[i])}
className="ghost-btn"
style={{
display: 'flex', alignItems: 'center', gap: 4, padding: '2px 7px', borderRadius: 7, cursor: 'pointer',
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`, fontSize: 10.5, color: tokens.textSub,
}}
>
{axis}
<b style={{ color: tokens.text, fontVariantNumeric: 'tabular-nums' }}>{radar.values[i].toFixed(1)}%</b>
</button>
))}
</div>
<Note>刻度自 {min}% 起放大差异;点任一轴签看该特征的四类缺陷拆分与样本数。</Note>
</div>
);
}
/* ══════════════════ 2. 趋势分析 ══════════════════ */
export function TrendView({ onOpen, period }: VizProps) {
const { tokens } = useTheme();
const trend = trendModelAt(period);
const main = trend.main;
const singles = trend.all.filter(s => s.values.length === 1);
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
{main && (
<Card title={`关键参数漂移 · ${main.device} ${main.param}`} right={<PeriodTag period={period} />}>
<TrendChart
height={210}
labels={main.dates}
series={[{ name: `${main.param}实测均值(${main.unit})`, color: tokens.accent, values: main.values }]}
band={main.tolLow !== null && main.tolHigh !== null
? [{ lo: main.tolLow, hi: main.tolHigh, label: `允差 ${main.tolText}` }] : undefined}
refs={main.std !== null ? [{ v: main.std, label: `标准值 ${main.std}${main.unit}` }] : undefined}
marker={main.values.length - 1}
yDigits={0}
/>
<div style={{ display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap', marginTop: 6 }}>
<StatusChip status={/^超差/.test(main.latestStatus) ? 'red' : /^预警/.test(main.latestStatus) ? 'yellow' : 'green'} />
<span style={{ fontSize: 11.5, color: tokens.textSub }}>状态「{main.latestStatus}」· 处理动作「{main.latestAction}」</span>
<button onClick={() => onOpen('DRIFT-CURD')} className="ghost-btn" style={{ display: 'flex', alignItems: 'center', gap: 3, fontSize: 11.5, color: tokens.accent, cursor: 'pointer', background: 'transparent' }}>
看超差读数 <ChevronRight size={12} />
</button>
</div>
<Note>
{period === CURRENT_PERIOD ? '' : `回放期 ${periodLabel(period)}:日期窗随游标平移到该月,偏移量与同步缺陷率按统一曲线回推。`}
五日实测 {main.values[0]} → {main.values[main.values.length - 1]}{main.unit},允差带({main.tolLow}–{main.tolHigh}),状态按回放后的偏移率重新判定。
偏移率 =(实测均值 − 标准值)÷ 标准值,现算 {main.driftLatest === null ? '—' : `${main.driftLatest.toFixed(2)}%`}。
</Note>
</Card>
)}
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, alignItems: 'start' }}>
{main && (
<Card title="同步缺陷率同轴对比" tone={tokens.danger} right={<PeriodTag period={period} />}>
<TrendChart
height={196}
labels={main.dates}
series={[{ name: '同步缺陷率(%)', color: tokens.danger, values: main.defects }]}
marker={main.defects.length - 1}
/>
<div style={{ fontSize: 11.5, color: tokens.textSub, marginTop: 4 }}>
功率 −{Math.abs(main.values[0] - main.values[main.values.length - 1]).toFixed(1)}W 的同时缺陷率 {main.defects[0]}% → {main.defects[main.defects.length - 1]}%;
两条序列的皮尔逊相关系数 <b style={{ color: tokens.danger }}>{trend.corr ?? '—'}</b>
</div>
<Note>相关系数为负即「功率越低、缺陷越多」,这条曲线是把参数漂移翻译成质量后果的那一环。</Note>
</Card>
)}
<Card title={`监控状态分布 · ${trend.monitored} 条序列`} tone={tokens.warning}>
<HBarChart
height={170}
items={trend.counts.filter(c => c.n > 0).map(c => ({
label: c.label,
value: c.n,
color: c.label === '超差' ? tokens.danger : c.label === '预警' ? tokens.warning : c.label === '正常' ? tokens.success : tokens.info,
display: `${c.n} 条`,
}))}
/>
<div style={{ display: 'flex', flexDirection: 'column', gap: 5, marginTop: 6 }}>
{singles.map(s => (
<div key={`${s.device}-${s.param}`} style={{ display: 'flex', alignItems: 'center', gap: 7, fontSize: 11, color: tokens.textSub }}>
<span style={{ width: 7, height: 7, borderRadius: 7, flex: '0 0 7px', background: /^超差/.test(s.latestStatus) ? tokens.danger : /^预警|注意|临近/.test(s.latestStatus) ? tokens.warning : tokens.success }} />
<span style={{ flex: 1, minWidth: 0, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{s.device} {s.param}</span>
<span style={{ fontVariantNumeric: 'tabular-nums', color: tokens.text }}>{s.values[0]}{s.unit}</span>
<span style={{ color: tokens.textMuted }}>/标准 {s.stdText}{/^-?\d/.test(s.stdText) ? s.unit : ''}</span>
<span style={{ color: tokens.textMuted }}>{s.latestStatus}</span>
</div>
))}
</div>
<Note>{trend.sequenceCount} 条参数配到多日监控,其余 {singles.length} 条为单日快照;单日快照不构成趋势,列在下方明细表里。</Note>
</Card>
</div>
<Card title="DS-16 参数漂移监控明细" right={<span style={{ fontSize: 10.5, color: tokens.textMuted }}>偏移率现算 · 明细为源表 2026-10 当期</span>}>
<DataTable table={{ tableKey: 'DS-16', title: 'DS-16', columns: ['日期', '设备', '参数', '标准值', '实测均值', '单位', '偏移率%(现算)', '允许偏差', '同步缺陷率%', '状态', '处理动作'], rows: driftRows() }} />
</Card>
</div>
);
}
/* ══════════════════ 3. 结构动因 ══════════════════ */
export function StructureView({ onOpen, period }: VizProps) {
const { tokens } = useTheme();
const feats = featureModelsAt(period);
const pareto = defectPareto();
const causes = rootCauseGroups();
const dup = duplicateHits();
const doe = doeModelAt(period);
const factors = [...doe.factors].sort((a, b) => b.spread - a.spread);
/** 焊速是极差最弱那根:推荐组合与按极差挑出的最优水平不一致,要在文案里点明 */
const speed = doe.factors.find(f => f.column === '焊速(mm/s)') ?? factors[factors.length - 1];
const speedBest = speed.levels.reduce((bi, l, li) => (l.meanYield > speed.levels[bi].meanYield ? li : bi), 0);
const sev = severityCount();
const byProcess = defectByProcess();
const colors = DEFECT_COLORS(tokens);
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
<Card
title="结构特征 × 四类缺陷率"
full
right={<PeriodTag period={period} />}
>
<StackedBarChart
height={186}
items={feats.map(f => ({
key: f.code,
label: f.label,
total: f.defect,
display: `${f.defect.toFixed(1)}%`,
sub: `n=${f.samples.toLocaleString('en-US')}`,
segs: f.parts.map((p, i) => ({ label: DEFECT_COLUMNS[i], value: p, color: colors[i] })),
}))}
onClick={code => onOpen(code)}
/>
<Note>
{period === CURRENT_PERIOD ? '' : `${periodLabel(period)} 回放:四类缺陷率按统一质量曲线回推,条长仍由四段累加。`}
全厂样本加权综合不良率 <b style={{ color: tokens.text }}>{overallDefectRateAt(period, feats).toFixed(1)}%</b>;
基准平板拼焊 {feats.find(f => /基准/.test(f.conclusion))?.defect.toFixed(1) ?? '—'}% 是这六类里最稳的一档。
点任意一条 → 该结构的明细与结论。
</Note>
</Card>
{/* Pareto 独占左列;右侧两张小卡上下堆叠,并把图表各拉高一点补齐到 Pareto 的高度 */}
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, alignItems: 'start' }}>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, minWidth: 0 }}>
<Card title="缺陷占比 Pareto(DS-03)" right={<SnapshotTag label="近3月构成 · 源表当期" />}>
<HBarChart
items={pareto.map(d => ({
label: d.name,
value: d.share,
color: severityColor(d.severity, tokens),
display: `${d.share.toFixed(1)}%`,
sub: `累计${d.cum.toFixed(0)}%`,
}))}
/>
<div style={{ display: 'flex', gap: 10, flexWrap: 'wrap', marginTop: 6 }}>
{sev.map(s => (
<button key={s.label} onClick={() => onOpen(`DS03:${pareto.find(p => p.severity === s.label)?.defectCode ?? ''}`)} className="ghost-btn"
style={{ display: 'flex', alignItems: 'center', gap: 5, fontSize: 10.5, color: tokens.textSub, cursor: 'pointer', background: 'transparent' }}>
<span style={{ width: 8, height: 8, borderRadius: 2, background: severityColor(s.label, tokens) }} />
{s.label}档 {s.n} 个码 · 占 {s.share.toFixed(1)}%
</button>
))}
</div>
<Note>占比取原表「近3月占比」列(比率 ×100),合计为字典内 11 个缺陷码之和,不是全数;累计列按降序现算。点档位药签看该档最高频缺陷码的明细。</Note>
</Card>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, minWidth: 0 }}>
<Card title="不良按工序归并" tone={tokens.info}>
<HBarChart
height={176}
items={byProcess.map(p => ({
label: p.label, value: p.share, color: tokens.accent,
display: `${p.share.toFixed(1)}%`, sub: `${p.codes} 个码`,
}))}
/>
<Note>同一本字典按「所属工序」汇总,看得出不合格集中在哪一段工艺:焊接段码数最多。</Note>
</Card>
<Card title="8D 根因类别(DS-11)" tone={tokens.warning} right={<span style={{ fontSize: 10.5, color: tokens.textMuted }}>重复拦截命中 {dup.length}/6</span>}>
<HBarChart
height={117}
items={causes.map((g, i) => ({
label: g.label, value: g.n,
color: i === 0 ? tokens.danger : tokens.accent,
display: `${g.n} 件`, sub: g.items.join(' '),
}))}
/>
<Note>
拦截口径:相似度 &gt; 0.85 判为重复问题(原表列值)。命中 {dup.length} 件里最高 {dup[0].相似度}({dup[0]['8D编号']}),
说明根因没有沉淀成标准,同一类问题在不同客户重复开单。
</Note>
</Card>
</div>
</div>
<Card title="激光焊 DOE 主效应(DS-12 L9)" full right={<PeriodTag period={period} />}>
<div style={{ display: 'grid', gridTemplateColumns: '0.9fr 1.6fr', gap: 12, alignItems: 'start' }}>
<div>
<HBarChart
items={factors.map((f, i) => ({
label: `${f.label}(${f.unit})`,
value: f.spread,
color: i === 0 ? tokens.danger : tokens.accent,
display: `${f.spread.toFixed(2)}pt`,
sub: `${f.levels.length} 水平`,
}))}
/>
<Note>极差=该因子各水平均值良率的最高 − 最低,就是它对良率的动因强度;红色是最强那根。</Note>
</div>
<div style={{ overflowX: 'auto' }}>
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
<thead><tr><Th>因子</Th>{[0, 1, 2].map(i => <Th key={i} right>水平{i + 1}</Th>)}<Th right>极差(pt)</Th><Th>推荐</Th></tr></thead>
<tbody>
{factors.map((f, i) => {
const best = f.levels.reduce((bi, l, li) => (l.meanYield > f.levels[bi].meanYield ? li : bi), 0);
return (
<tr key={f.column} style={{ background: i % 2 ? tokens.tableRowAlt : 'transparent' }}>
<Td><span style={{ color: tokens.text }}>{f.label}</span></Td>
{f.levels.map(l => <Td key={l.level} right mono>{l.meanYield.toFixed(1)}</Td>)}
{f.levels.length < 3 && [0, 1, 2].slice(f.levels.length).map(k => <Td key={k} right mono>—</Td>)}
<Td right mono color={i === 0 ? tokens.danger : tokens.textSub}>{f.spread.toFixed(2)}</Td>
<Td mono>{f.levels[best].level}{f.unit}</Td>
</tr>
);
})}
</tbody>
</table>
<Note>
三水平均值良率同表对照;最优组合落在试验 {doe.best.试验号}(综合良率 {yieldPctAt(+((calc.yieldRate(doe.best) || 0) * 100).toFixed(1), period).toFixed(1)}%,
功率 {doe.best['激光功率(W)']}W/保护气 {doe.best['保护气(L/min)']}L/焊速 {doe.best['焊速(mm/s)']}mm·s⁻¹),
最差试验 {doe.worst.试验号}({yieldPctAt(+((calc.yieldRate(doe.worst) || 0) * 100).toFixed(1), period).toFixed(1)}%,功率降到 {doe.worst['激光功率(W)']}W 时未焊透率抬到 {(doe.worst.未焊透率 * 100).toFixed(0)}%)。
原表「标记」列把试验 {doe.marked[0]?.试验号 ?? doe.best.试验号} 定为推荐组合。
有一处不一致要说清楚:按极差挑出的最优焊速是 {speed.levels[speedBest].level}mm/s,而推荐那组用的是 {doe.best['焊速(mm/s)']}mm/s——
焊速极差只有 {speed.spread.toFixed(2)}pt,是四个因子里最弱的一根,落在试验 {doe.best.试验号} 的参数窗口内即可,不必为它另开一轮。
</Note>
<div style={{ marginTop: 7 }}>
<button onClick={() => onOpen('DOE-BEST')} className="ghost-btn"
style={{ display: 'flex', alignItems: 'center', gap: 3, fontSize: 11.5, color: tokens.accent, cursor: 'pointer', background: 'transparent' }}>
看 L9 九组全表与参数窗口 <ChevronRight size={12} />
</button>
</div>
</div>
</div>
</Card>
</div>
);
}
/* ══════════════════ 4. 工序 · 工位对比 ══════════════════ */
export function RegionView({ onOpen, period }: VizProps) {
const { tokens } = useTheme();
const lines = lineModelsAt(period);
const stations = stationModelsAt(period);
const master = masterModel();
const methods = methodCompareRows();
const bottleneckStations = stations.filter(s => s.bottleneck !== '否');
/** DS-02 与 DS-14 对「最大瓶颈」各说各话:一个按标准工时最长,一个按负荷率最高 */
const slowest = stations.reduce((mi, s) => (s.hours > mi.hours ? s : mi), stations[0]);
const busiest = lines.reduce((mi, l) => (l.load > mi.load ? l : mi), lines[0]);
/** DS-10 是一张「对比项 × 三种方式」的横表,按指标名取出三根柱子(比率已在视图层 ×100) */
const methodSeries = (item: string) => {
const row = methods.find(m => m.对比项 === item);
const raw = [numCell(row?.手工氩弧焊), numCell(row?.机器人弧焊), numCell(row?.['激光焊(设备)'])];
if (/一次良率/.test(item)) return raw.map(v => yieldPctAt(v, period));
if (/未焊透率/.test(item)) return raw.map(v => +defectPctAt(v, period).toFixed(1));
return raw;
};
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
<Card title="工序负荷率对比(DS-14)" right={<PeriodTag period={period} />}>
<HBarChart
height={210}
items={lines.map(l => ({
label: l.label,
value: l.load,
color: statusColor(l.status, tokens),
display: `${l.load.toFixed(1)}%`,
sub: `WIP ${l.wip.toLocaleString('en-US')}`,
}))}
/>
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, marginTop: 8 }}>
{lines.map(l => (
<button key={l.code} onClick={() => onOpen(l.code)} className="ghost-btn"
style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '3px 6px', borderRadius: 6, cursor: 'pointer', background: tokens.panelBgAlt, border: `1px solid ${tokens.border}` }}>
<span style={{ width: 7, height: 7, borderRadius: 7, flex: '0 0 7px', background: statusColor(l.status, tokens) }} />
<span style={{ fontSize: 11.5, color: tokens.text, width: 78, flex: '0 0 78px' }}>{l.label}</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted, width: 118, flex: '0 0 118px' }}>{l.station}</span>
<span style={{ fontSize: 10.5, color: tokens.textSub, flex: 1, minWidth: 0, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
需求 {l.demand}/实际 {l.capacity} 件·班⁻¹ · {l.warn}
</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted, maxWidth: 210, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{l.advice}</span>
</button>
))}
</div>
<Note>
负荷率 = 需求节拍 ÷ 实际产能(现算)。需求节拍按订单口径折到班次:
月需求 {QAP_CALIBER.monthlyDemand.toLocaleString('en-US')} 件 ÷({QAP_CALIBER.workDays} 工作日 × {QAP_CALIBER.shifts} 班),
当前有 {lines.filter(l => l.load > 100).length} 道工序 &gt;100%;档位沿用原表「预警」列(最大瓶颈/严重瓶颈红,超负荷黄)。
{period === CURRENT_PERIOD ? '' : ` 当前为 ${periodLabel(period)} 回放:负荷按年末放行的季节曲线回推。`}
</Note>
</Card>
{/* 两栏各自纵向堆叠,而不是按行对齐:
按行放时 DS-02 比 DS-10 矮 300px,左列会空出一大块;
改成一列「DS-02 + DS-01」对一列「DS-10」,卡片间距仍然一致,但不再留洞。 */}
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, alignItems: 'start' }}>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, minWidth: 0 }}>
<Card title="工位产能达成率(DS-02)" tone={tokens.info} right={<PeriodTag period={period} />}>
<VBarChart
height={210}
labels={stations.map(s => s.process)}
groups={[stations.map(s => s.rate)]}
colors={[tokens.accent]}
names={['产能达成率(班次产能 ÷ 理论产能,现算)']}
/>
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginTop: 8 }}>
{stations.map(s => (
<button key={s.code} onClick={() => onOpen(s.code)} className="ghost-btn"
style={{ display: 'flex', alignItems: 'center', gap: 5, padding: '3px 8px', borderRadius: 7, cursor: 'pointer', background: tokens.panelBgAlt, border: `1px solid ${s.status === 'na' ? tokens.border : `${statusColor(s.status, tokens)}55`}`, fontSize: 10.5, color: tokens.textSub }}>
<span style={{ width: 6, height: 6, borderRadius: 6, background: statusColor(s.status, tokens) }} />
{s.station}
<b style={{ color: tokens.text, fontVariantNumeric: 'tabular-nums' }}>{s.rate.toFixed(1)}%</b>
<span style={{ color: tokens.textMuted }}>{s.bottleneck}</span>
</button>
))}
</div>
<Note>
理论产能 = ROUND(480 ÷ 标准工时)(现算)。{bottleneckStations.length} 个瓶颈工位全落在焊接段({bottleneckStations.map(s => s.process).join('/')}),与 DS-14 的负荷率红档同段互证。
两张表的「最大瓶颈」不同名,这里不强行统一:DS-02 按标准工时把 {slowest.station} {slowest.process}({slowest.hours} min/件)标为最大瓶颈,
DS-14 按负荷率把 {busiest.label}({busiest.load.toFixed(1)}%)排为最大瓶颈——前者看单件耗时,后者看需求÷实际产能,两列各按源表原话显示。
</Note>
</Card>
<Card title="机型结构主数据(DS-01)" tone={tokens.info}>
<HBarChart
height={150}
items={master.byModel.map(m => ({
label: `${m.label}(${m.items} 料号)`,
value: m.annual,
color: tokens.accent,
display: m.annual.toLocaleString('en-US'),
sub: `${m.welded} 涉焊`,
}))}
/>
{/* 左列比右列矮一截,把留白换成四个源表读数:既能补齐高度,也把「共几个料号/机型」从文字里提出来 */}
<div style={{ display: 'flex', gap: 6, marginTop: 8 }}>
{([
['机型', `${master.models} 个`],
['料号', `${master.items} 个`],
['年用量', `${master.annual.toLocaleString('en-US')} 件`],
['涉焊料号', `${master.welded} 个`],
] as const).map(([k, v]) => (
<div key={k} style={{
flex: '1 1 0', minWidth: 0, padding: '6px 8px', borderRadius: 8,
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
}}>
<div style={{ fontSize: 10, color: tokens.textMuted }}>{k}</div>
<div style={{ fontSize: 12, fontWeight: 700, color: tokens.text, marginTop: 2, fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{v}</div>
</div>
))}
</div>
<Note>
条长=年用量,右侧标该机型里涉焊接的料号数——特征码(材质 × 结构特征 × 工艺方法)就挂在这张表上。
</Note>
</Card>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12, minWidth: 0 }}>
<Card title="三种焊接方式对照(DS-10)" tone={tokens.danger} right={<PeriodTag period={period} />}>
<VBarChart
height={200}
labels={['手工氩弧焊', '机器人弧焊', '激光焊(设备)']}
groups={[methodSeries('一次良率'), methodSeries('未焊透率(DF-WLD-02)')]}
colors={[tokens.accent, tokens.danger]}
names={['一次良率 %', '未焊透率 %(致命缺陷)']}
/>
<DataTable table={{ tableKey: 'DS-10', title: 'DS-10', columns: ['对比项', '手工氩弧焊', '机器人弧焊', '激光焊(设备)', '单位', '差异结论'], rows: methods.slice(0, 6) }} />
<Note>
同料号 SRV2U-FANW-01、同批次板材对照;原表结论:设备化把一次良率抬 14~20pt(68.5 → 88.9%),
返修/补焊工时从 3.2 压到 0.6 min/件,换型时间反而从 5 涨到 15 min——柔性是小批量手工的强项,这张表也照着原表列全了代价。
</Note>
</Card>
</div>
</div>
</div>
);
}
/* ══════════════════ 5. 风险矩阵 ══════════════════ */
export function RiskView({ onOpen, period }: VizProps) {
const { tokens } = useTheme();
const rp = riskPoints();
const maxCount = Math.max(...rp.map(r => r.count), 1);
const items = rp.map(r => ({
label: r.label.length > 9 ? `${r.label.slice(0, 9)}…` : r.label,
x: r.count / maxCount,
y: SEVERITY_WEIGHT[r.severity] ?? 0.3,
status: r.severity,
color: severityColor(r.severity, tokens),
}));
const abn = abnormalModelsAt(period);
/** 平均值只按未闭环那几单算:把已闭环的 11 天混进去会凭空抬高一倍 */
const openAbn = abn.filter(a => !a.closed);
const overdueAbn = openAbn.filter(a => a.overdue);
const avgOpenDwell = openAbn.length ? openAbn.reduce((s, a) => s + a.dwell, 0) / openAbn.length : 0;
const cov = coverageModelAt(period);
return (
<div style={{ display: 'grid', gridTemplateColumns: '1.15fr 1fr', gap: 12, alignItems: 'start' }}>
<Card title="风险点检矩阵(DS-05)" right={<SnapshotTag label="历史发生 · 源表当期" />}>
<RiskMatrix items={items} height={318} xLabel={`历史发生次数 →(最高 ${maxCount})`} yLabel="↑ 严重度(致命 0.9/严重 0.6/一般 0.3)" />
<Note>
横轴直接取原表「历史发生次数」,纵轴用严重度做展示映射(致命 0.9/严重 0.6/一般 0.3)——
这是坐标摆放,不是源表判定线。右上=高频且致命,是最该先补标准的那格。
同严重度的几点会挤在同一横线上,图里只把它们上下错开、标签让位,次数与严重度的读数以下方明细为准。
</Note>
</Card>
<Card title={`异常滞留天数(DS-15)· ${openAbn.length} 单未闭环`} tone={tokens.danger} right={<PeriodTag period={period} />}>
<HBarChart
height={334}
items={[...abn].sort((a, b) => Number(a.closed) - Number(b.closed) || b.dwell - a.dwell).map(a => ({
label: `${a.order} ${a.defect}`,
value: a.dwell,
color: statusColor(a.status, tokens),
display: `${a.dwell} 天`,
sub: a.closed ? '已闭环' : a.escalation,
}))}
/>
<Note>
滞留天数 = 回放基准日 {period === CURRENT_PERIOD ? QAP_CALIBER.warningPoolBaseDate : periodLabel(period) + '-16'} − 发生日(现算);原表口径超 3 天必须升级,
当前超期未闭环 {overdueAbn.length} 单({overdueAbn.map(a => `${a.order} ${a.dwell} 天`).join('、') || '无'}),
未闭环 {openAbn.length} 单平均滞留 {avgOpenDwell.toFixed(1)} 天(已闭环那单不计入)。
</Note>
</Card>
<Card title="新机型良率可预测度(DS-13)" full tone={tokens.info}>
<DataTable table={{
tableKey: 'DS-13', title: 'DS-13',
columns: ['新机型/料号', '相似机型', '特征相似度', '相似机型实际良率%', '预测良率区间', '高概率缺陷(Top3)', '建议动作'],
rows: predictionRows(),
focus: { column: '相似机型', value: '无相似件' },
}} />
<Note>相似度按材质 × 板厚 × 结构特征 × 焊接方式加权;标「无相似件」的行就是模型盲区——高亮那行没有可比历史,预测区间为空,只能靠首件验证补。</Note>
</Card>
<Card title={`检验标准缺口(DS-07)· 已覆盖 ${cov.coveredCount}/${cov.total}`} full tone={tokens.warning} right={period === CURRENT_PERIOD ? undefined : <PeriodTag period={period} />}>
<div style={{ display: 'grid', gridTemplateColumns: '240px 1fr', gap: 12, alignItems: 'start' }}>
<div>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 6 }}>
<span style={{ fontSize: 30, fontWeight: 800, color: tokens.text, fontVariantNumeric: 'tabular-nums' }}>{cov.rate}</span>
<span style={{ fontSize: 12, color: tokens.textMuted }}>% 覆盖率</span>
</div>
<div style={{ height: 8, borderRadius: 8, background: tokens.border, overflow: 'hidden', marginTop: 6 }}>
<div style={{ width: `${cov.rate}%`, height: '100%', background: tokens.accent, borderRadius: 8 }} />
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 5, marginTop: 9 }}>
{cov.pending.map(p => (
<button key={p.检验项目} onClick={() => onOpen('STD-GAP')} className="ghost-btn"
style={{ textAlign: 'left', cursor: 'pointer', padding: '5px 8px', borderRadius: 8, background: `${tokens.warning}14`, border: `1px solid ${tokens.warning}44` }}>
<div style={{ fontSize: 11.5, color: tokens.text, fontWeight: 700 }}>待 QE 确认 · {p.检验项目}</div>
<div style={{ fontSize: 10.5, color: tokens.textSub, marginTop: 2 }}>{p['AI 提示']}</div>
</button>
))}
</div>
</div>
<DataTable table={{
tableKey: 'DS-07', title: 'DS-07',
columns: ['特征/项目', '检验项目', '依据', '抽样', '量具', '频次', 'AI 提示', '状态'],
rows: cov.rows(),
focus: { column: '状态', value: '待 QE 确认' },
}} />
</div>
<Note>
状态=「待 QE 确认」即标准缺口(原表口径),确认后转「已覆盖」;AI 提示直接引用相似件历史 8D,把 QE 段最依赖个人经验的那一步补上。
{period === CURRENT_PERIOD ? '' : ` ${periodLabel(period)} 回放:缺口数以源表待确认项为基数按质量曲线回推,下列明细仍为 2026-10 当期。`}
</Note>
</Card>
<Card title="DS-05 风险点检清单" full>
<DataTable table={{
tableKey: 'DS-05', title: 'DS-05',
columns: ['序号', '风险项', '工序', '历史发生次数', '严重度', '控制措施', '检验方法/频次', '责任人', '来源引用'],
rows: riskChecklistRows(),
}} />
</Card>
</div>
);
}
/* ══════════════════ 6. 指标明细 ══════════════════ */
export function DetailView({ subject, onOpen, period }: VizProps) {
const { tokens } = useTheme();
const m: QualityMetric = metricAt(subject, period) ?? metricAt(DEFAULT_METRIC, period)!;
const groups = [...new Set(METRICS.map(x => x.group))];
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
{/* 指标脊导航:四组读数横排,点一个换主体 */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 7 }}>
{groups.map(g => (
<div key={g} style={{ display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 }}>
<span style={{ fontSize: 11, color: tokens.textMuted, width: 62, flex: '0 0 62px', whiteSpace: 'nowrap' }}>{g}</span>
<div style={{ display: 'flex', gap: 5, flexWrap: 'wrap', minWidth: 0 }}>
{METRICS.filter(x => x.group === g).map(x => {
const xm = metricAt(x.code, period) ?? x;
const on = x.code === m.code;
const c = statusColor(xm.status, tokens);
return (
<button
key={x.code}
onClick={() => onOpen(x.code)}
className="ghost-btn"
style={{
display: 'flex', alignItems: 'center', gap: 4, padding: '3px 9px', borderRadius: 8, cursor: 'pointer',
fontSize: 11, whiteSpace: 'nowrap',
background: on ? tokens.accent : tokens.panelBgAlt,
color: on ? tokens.onAccent : tokens.textSub,
border: `1px solid ${on ? tokens.accent : xm.status === 'na' ? tokens.border : `${c}55`}`,
fontWeight: on ? 700 : 500,
}}
>
{xm.status !== 'na' && <span style={{ width: 6, height: 6, borderRadius: 6, background: on ? tokens.onAccent : c }} />}
{x.name}
{!on && <span style={{ fontVariantNumeric: 'tabular-nums', color: tokens.textMuted }}>{xm.value}{xm.unit}</span>}
</button>
);
})}
</div>
</div>
))}
</div>
{/* Hero + 判定 */}
<div style={{ display: 'grid', gridTemplateColumns: 'minmax(220px, 0.9fr) 1.6fr', gap: 12 }}>
<div style={{
padding: '12px 14px', borderRadius: 11, border: `1px solid ${tokens.borderAccent}`,
background: `linear-gradient(135deg, ${tokens.accentBg}, ${tokens.cardBg})`, position: 'relative', overflow: 'hidden',
}}>
<div style={{ fontSize: 12, color: tokens.textSub }}>{m.name}</div>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 5, marginTop: 4 }}>
<span style={{ fontSize: 38, fontWeight: 800, color: tokens.text, lineHeight: 1, fontVariantNumeric: 'tabular-nums', textShadow: `0 0 22px ${statusColor(m.status, tokens)}33` }}>
{m.value || '—'}
</span>
<span style={{ fontSize: 13, color: tokens.textMuted }}>{m.unit}</span>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 8, flexWrap: 'wrap' }}>
<StatusChip status={m.status} />
<span style={{ fontSize: 11, color: tokens.textMuted, fontFamily: 'ui-monospace, monospace' }}>{m.code}</span>
<span style={{ fontSize: 11, color: tokens.accent }}>{m.ds} {m.dsName}</span>
{period !== CURRENT_PERIOD && <PeriodTag period={period} />}
</div>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, minWidth: 0 }}>
<div style={{ padding: '9px 12px', borderRadius: 10, background: tokens.cardBg, border: `1px solid ${tokens.border}` }}>
<div style={{ fontSize: 11, color: tokens.textMuted, marginBottom: 3 }}>读数</div>
<div style={{ fontSize: 12.5, lineHeight: 1.7, color: tokens.textSub }}>{m.reading}</div>
</div>
<div style={{ padding: '9px 12px', borderRadius: 10, background: tokens.cardBg, border: `1px solid ${tokens.border}` }}>
<div style={{ fontSize: 11, color: tokens.textMuted, marginBottom: 3 }}>判定依据</div>
<div style={{ fontSize: 12.5, lineHeight: 1.7, color: m.status === 'na' ? tokens.textMuted : statusColor(m.status, tokens) }}>{m.rule}</div>
</div>
</div>
</div>
{/* 元信息 */}
<div style={{
display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0,1fr))', gap: 1,
background: tokens.border, border: `1px solid ${tokens.border}`, borderRadius: 10, overflow: 'hidden',
}}>
{[
['归属分组', m.group],
['责任角色', m.role],
['计算式', m.formula],
['数据集口径', m.caliber],
].map(([k, v]) => (
<div key={k} style={{ background: tokens.panelBgAlt, padding: '7px 10px', minWidth: 0 }}>
<div style={{ fontSize: 10.5, color: tokens.textMuted, marginBottom: 2 }}>{k}</div>
<div style={{ fontSize: 12, color: tokens.text, fontWeight: 600, lineHeight: 1.55, whiteSpace: 'normal' }}>{v}</div>
</div>
))}
</div>
<Card title={`${m.detail.title} · ${m.detail.rows.length} 行`} right={<span style={{ fontSize: 10.5, color: tokens.textMuted }}>带 ◆ 的列是现算,不在原表里</span>}>
<DataTable table={m.detail} max={12} />
</Card>
<Card title="这一组的其他读数">
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
{METRICS.filter(x => x.group === m.group && x.code !== m.code).map(x => {
const xm = metricAt(x.code, period) ?? x;
return (
<button key={x.code} onClick={() => onOpen(x.code)} className="ghost-btn"
style={{ display: 'flex', alignItems: 'center', gap: 5, padding: '4px 9px', borderRadius: 8, cursor: 'pointer', background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`, fontSize: 11.5, color: tokens.textSub }}>
<span style={{ width: 6, height: 6, borderRadius: 6, background: statusColor(xm.status, tokens) }} />
{x.name}
<b style={{ color: tokens.text, fontVariantNumeric: 'tabular-nums' }}>{xm.value}{xm.unit}</b>
<span style={{ color: tokens.textMuted }}>{x.ds}</span>
</button>
);
})}
</div>
<Note>全部读数只出自这本 Excel 的 16 个数据集;比率类字段按原表存小数、页面 ×100 展示,计算列一律现算。
{period === CURRENT_PERIOD ? '' : ` ${REPLAY_DETAIL_NOTE}`}
</Note>
</Card>
</div>
);
}
/* 局部小工具 */
function numCell(v: unknown): number {
const n = Number(v);
return Number.isFinite(n) ? n : 0;
}