新增模块

This commit is contained in:
2026-10-18 15:27:02 +08:00
parent 5b7d1e8f64
commit f2e6d2b3f1
228 changed files with 46089 additions and 11 deletions
@@ -0,0 +1,953 @@
import { useEffect, useMemo, useState } from 'react';
import {
BookOpen, Box, ChevronDown, ChevronRight, FlaskConical, GitBranch, Search, Wrench, X,
} from 'lucide-react';
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
import { ONTOLOGY_AS_OF } from '../../data/ontologyQap';
import { ROLE_COLOR, roleDocs, type RoleKey } from '../../data/knowledge';
import type { KbRef } from '../../data/kbLinks';
import {
getFeatureTree, methodsForRef, type FeatureMethod, type FeatureModel,
type FeatureProcess,
} from '../../data/featureTree';
import type { MethodSummaryRow } from '../../data/methodSummaries';
import { methodImageSrc } from '../../data/methodImages';
/**
* 特征建模舞台:机型 → 工艺 → 生产方法 三级树。
*
* 第三级是可执行的生产方法(数控冲孔 / 手工倒角 / 激光焊 / 压铆…)。
* 选中生产方法后,右侧按「每条知识来源一行」列出问题 / 原因 / 对策 / 角色。
* 真实知识只覆盖 SRV-2U-620;其余机型与空方法用方法模板示例补齐,并标「示例」。
*
* 与知识库的双向动线:
* 知识库点特征码 → 经 featFocus 跳到这里,自动展开并选中对应生产方法
* 这里点「原文」→ 经 onOpenKnowledge 跳回知识库对应切片
*/
interface Props {
onExit: () => void;
/** 从知识库跳回时:指定要聚焦的数据对象/实例 */
focus?: { objKey: string; instanceId?: string } | null;
/** 点击知识来源时跳回知识库 */
onOpenKnowledge?: (role: RoleKey, chunkId: string) => void;
}
type Path = { modelId: string; processId?: string; methodId?: string };
const ROLE_LABEL: Record<RoleKey, string> = {
PE: '工艺', IE: '工业', QE: '质量', ME: '制造',
};
const ROLE_FULL: Record<RoleKey, string> = {
PE: '工艺工程师', IE: '工业工程师', QE: '质量工程师', ME: '制造工程师',
};
const KB_MODEL = 'SRV-2U-620';
const cardBase = (tk: ThemeTokens, on: boolean): React.CSSProperties => ({
width: '100%', textAlign: 'left', cursor: 'pointer',
padding: '6px 8px', borderRadius: 8, marginBottom: 4,
background: on ? tk.accentBg : 'transparent',
border: `1px solid ${on ? tk.accent : 'transparent'}`,
transition: 'background .15s ease, border-color .15s ease',
});
export default function FeatureTreeView({ onExit, focus, onOpenKnowledge }: Props) {
const { tokens } = useTheme();
const tree = useMemo(getFeatureTree, []);
const initialSelection = useMemo<Path>(() => {
const model = tree.models.find(m => m.id === KB_MODEL) ?? tree.models[0];
if (!model) return { modelId: '' };
const proc = model.processes.find(p => p.id === 'NCT') ?? model.processes[0];
const method = proc?.methods.find(m => m.label === '手工倒角') ?? proc?.methods[0];
return method
? { modelId: model.id, processId: proc.id, methodId: method.id }
: proc ? { modelId: model.id, processId: proc.id } : { modelId: model.id };
}, [tree]);
const validSelection = (path: Path | null): boolean => {
if (!path) return false;
const model = tree.models.find(m => m.id === path.modelId);
if (!model) return false;
if (!path.processId) return true;
const proc = model.processes.find(p => p.id === path.processId);
if (!proc) return false;
if (!path.methodId) return true;
return proc.methods.some(m => m.id === path.methodId);
};
/* 从知识库跳回时优先用上次的选中,否则用默认方法 */
const [selected, setSelected] = useState<Path>(() => {
const last = readLastSelection();
return validSelection(last) ? last! : initialSelection;
});
const [expanded, setExpanded] = useState<Set<string>>(() => {
const first = tree.models.find(m => m.id === KB_MODEL) ?? tree.models[0];
const set = new Set<string>();
if (first) {
set.add(first.id);
for (const p of first.processes) set.add(`${first.id}/${p.id}`);
}
return set;
});
const [query, setQuery] = useState('');
/* 外部跳入:知识库点特征码 → 定位到对应生产方法 */
useEffect(() => {
if (!focus) return;
const methods = methodsForRef(focus.objKey, focus.instanceId);
if (methods.length === 0) return;
const target = methods.find(m => m.modelId === KB_MODEL) ?? methods[0];
setSelected({ modelId: target.modelId, processId: target.processId, methodId: target.id });
setExpanded(prev => {
const next = new Set(prev);
next.add(target.modelId);
next.add(`${target.modelId}/${target.processId}`);
return next;
});
}, [focus]);
/* 记住舞台内最后一次选中,退出再进入时保持不变 */
useEffect(() => {
if (selected.modelId) writeLastSelection(selected);
}, [selected]);
const q = query.trim().toLowerCase();
const match = (text: string) => text.toLowerCase().includes(q);
const methodVisible = (m: FeatureMethod) =>
!q || match(m.label) || m.summary.some(r =>
match(r.problem) || match(r.cause) || match(r.action) || match(r.role));
const selectedNode = useMemo(() => {
const model = tree.models.find(m => m.id === selected.modelId);
if (!model) return null;
if (!selected.processId) return { kind: 'model' as const, node: model };
const proc = model.processes.find(p => p.id === selected.processId);
if (!proc) return { kind: 'model' as const, node: model };
if (!selected.methodId) return { kind: 'process' as const, node: proc };
const method = proc.methods.find(m => m.id === selected.methodId);
return method
? { kind: 'method' as const, node: method }
: { kind: 'process' as const, node: proc };
}, [selected, tree]);
const totalLeaves = useMemo(
() => tree.models.reduce((a, m) => a + m.processes.reduce((b, p) => b + p.methods.length, 0), 0),
[tree],
);
const totalKb = useMemo(
() => tree.models.reduce((a, m) => a + m.kbRefs.length, 0),
[tree],
);
const toggleExpand = (id: string) => {
setExpanded(prev => {
const next = new Set(prev);
if (next.has(id)) next.delete(id); else next.add(id);
return next;
});
};
const isSelected = (path: Path) =>
selected.modelId === path.modelId &&
selected.processId === path.processId &&
selected.methodId === path.methodId;
const box: React.CSSProperties = {
minWidth: 0, display: 'flex', flexDirection: 'column',
borderRadius: 12, overflow: 'hidden', background: tokens.cardBg, border: `1px solid ${tokens.border}`,
};
return (
<div style={{ flex: 1, minHeight: 0, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 10 }}>
{/* ── 标题栏 ── */}
<div style={{ display: 'flex', alignItems: 'center', gap: 10, flex: '0 0 auto', flexWrap: 'wrap', padding: '2px 2px 0' }}>
<FlaskConical size={19} style={{ color: tokens.accent, flexShrink: 0 }} />
<span style={{ fontSize: 17, fontWeight: 800, color: tokens.text, letterSpacing: '0.03em' }}>特征建模</span>
<span style={{ fontSize: 13, color: tokens.textMuted, flexShrink: 0 }}>
快照日 {ONTOLOGY_AS_OF} · 机型 → 工艺 → 生产方法
</span>
<span style={{ flex: '1 1 24px' }} />
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
{[
{ l: '机型', v: tree.models.length },
{ l: '工艺', v: tree.models.reduce((a, m) => a + m.processes.length, 0) },
{ l: '生产方法', v: totalLeaves },
{ l: '知识挂载', v: totalKb, hot: true },
].map(s => (
<span key={s.l} style={{
fontSize: 12.5, fontWeight: 700, padding: '2px 9px', borderRadius: 999, whiteSpace: 'nowrap',
color: s.hot ? tokens.warning : tokens.textSub,
background: s.hot ? tokens.warningBg : tokens.accentBg,
border: `1px solid ${s.hot ? `${tokens.warning}55` : tokens.border}`,
fontVariantNumeric: 'tabular-nums',
}}>{s.l} {s.v}</span>
))}
</div>
<div style={{
display: 'flex', alignItems: 'center', gap: 6, flex: '1 1 190px', minWidth: 150, maxWidth: 260,
padding: '3px 9px', borderRadius: 999, background: tokens.panelBgAlt, border: `1px solid ${tokens.borderAccent}`,
}}>
<Search size={12} style={{ color: tokens.textMuted, flexShrink: 0 }} />
<input
value={query} onChange={e => setQuery(e.target.value)}
placeholder="搜索机型 / 工艺 / 方法 / 问题"
style={{ flex: 1, minWidth: 0, background: 'transparent', border: 'none', outline: 'none', color: tokens.text, fontSize: 13.5 }}
/>
{query && (
<button onClick={() => setQuery('')} title="清空搜索" style={{ background: 'none', border: 'none', cursor: 'pointer', color: tokens.textMuted, display: 'flex' }}>
<X size={12} />
</button>
)}
</div>
<button
onClick={onExit} title="退出特征建模 (ESC)"
style={{
flexShrink: 0, display: 'flex', alignItems: 'center', gap: 5, cursor: 'pointer',
padding: '4px 11px', borderRadius: 8, fontSize: 13, fontWeight: 700,
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
}}
>
<X size={13} /> 退出 ESC
</button>
</div>
{/* ── 主区:左树 + 右详情 ── */}
<div style={{ flex: 1, minHeight: 0, display: 'flex', gap: 10 }}>
{/* 左侧树 */}
<div style={{ ...box, flex: '0 0 330px' }}>
<div style={{
display: 'flex', alignItems: 'center', gap: 7, padding: '8px 11px',
borderBottom: `1px solid ${tokens.border}`, flex: '0 0 auto',
}}>
<GitBranch size={13} style={{ color: tokens.accent }} />
<span style={{ fontSize: 14, fontWeight: 800, color: tokens.text }}>特征树</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 12, color: tokens.textMuted }}>叶子=生产方法</span>
</div>
<div style={{ flex: 1, minHeight: 0, overflowY: 'auto', padding: '8px 9px' }}>
{tree.models.map(model => {
const modelOpen = q ? true : expanded.has(model.id);
const modelVisible = !q || match(model.label) || model.processes.some(p =>
match(p.label) || p.methods.some(methodVisible),
);
if (!modelVisible) return null;
const modelSel = isSelected({ modelId: model.id });
return (
<div key={model.id}>
<button
onClick={() => setSelected({ modelId: model.id })}
style={{ ...cardBase(tokens, modelSel), display: 'flex', alignItems: 'center', gap: 6 }}
>
<span onClick={e => { e.stopPropagation(); toggleExpand(model.id); }} style={{ display: 'flex', color: tokens.textMuted }}>
{modelOpen ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
</span>
<Box size={14} style={{ color: tokens.accent, flexShrink: 0 }} />
<span style={{ fontSize: 14, fontWeight: 700, color: tokens.text, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{model.label}
</span>
<KbBadge n={model.kbRefs.length} tokens={tokens} />
</button>
{modelOpen && model.processes.map(proc => {
const procOpen = q ? true : expanded.has(`${model.id}/${proc.id}`);
const procVisible = !q || match(proc.label) || proc.methods.some(methodVisible);
if (!procVisible) return null;
const procSel = isSelected({ modelId: model.id, processId: proc.id });
return (
<div key={proc.id} style={{ paddingLeft: 16 }}>
<button
onClick={() => setSelected({ modelId: model.id, processId: proc.id })}
style={{ ...cardBase(tokens, procSel), display: 'flex', alignItems: 'center', gap: 5 }}
>
<span onClick={e => { e.stopPropagation(); toggleExpand(`${model.id}/${proc.id}`); }} style={{ display: 'flex', color: tokens.textMuted }}>
{procOpen ? <ChevronDown size={13} /> : <ChevronRight size={13} />}
</span>
<GitBranch size={13} style={{ color: tokens.info, flexShrink: 0 }} />
<span style={{ fontSize: 13.5, fontWeight: 600, color: tokens.textSub, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{proc.label}
</span>
<span style={{ fontSize: 11, color: tokens.textMuted, flexShrink: 0, fontVariantNumeric: 'tabular-nums' }}>
{proc.methods.length}
</span>
<KbBadge n={proc.kbRefs.length} tokens={tokens} />
</button>
{procOpen && proc.methods.map(method => {
if (!methodVisible(method)) return null;
const methodSel = isSelected({ modelId: model.id, processId: proc.id, methodId: method.id });
const hasReal = method.realCount > 0;
const thumb = methodImageSrc(method.label);
return (
<button
key={method.id}
onClick={() => setSelected({ modelId: model.id, processId: proc.id, methodId: method.id })}
title={`${method.summary.length} 行总结 · 真实知识 ${method.realCount} 条 · 示例 ${method.exampleCount} 条`}
style={{ ...cardBase(tokens, methodSel), display: 'flex', alignItems: 'center', gap: 7, paddingLeft: 30 }}
>
{/* 生产方法实拍示意图:4:3 缩略图,统一贴在叶子左侧 */}
{thumb ? (
<img
src={thumb}
alt=""
loading="lazy"
draggable={false}
style={{
width: 40, height: 30, objectFit: 'cover', flexShrink: 0,
borderRadius: 5, border: `1px solid ${methodSel ? tokens.accent : tokens.border}`,
boxShadow: '0 1px 2px rgba(0,0,0,0.14)',
}}
/>
) : (
<Wrench size={12} style={{ color: hasReal ? tokens.success : tokens.textMuted, flexShrink: 0 }} />
)}
<span style={{ fontSize: 13, color: hasReal ? tokens.text : tokens.textSub, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{method.label}
</span>
<span style={{
fontSize: 11, fontWeight: 800, padding: '1px 5px', borderRadius: 999,
flexShrink: 0, fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap',
color: hasReal ? tokens.warning : tokens.textMuted,
background: hasReal ? tokens.warningBg : tokens.panelBgAlt,
border: `1px solid ${hasReal ? `${tokens.warning}44` : tokens.border}`,
}}>
{hasReal ? method.summary.length : '示例'}
</span>
</button>
);
})}
</div>
);
})}
</div>
);
})}
</div>
</div>
{/* 右侧详情 */}
<div style={{ ...box, flex: '1 1 0' }}>
<DetailPanel
node={selectedNode}
onOpenKnowledge={onOpenKnowledge}
onSelect={setSelected}
onSelectMethod={method => setSelected({
modelId: method.modelId, processId: method.processId, methodId: method.id,
})}
/>
</div>
</div>
</div>
);
}
/* ── 选中记忆(仅本舞台,刷新后保留) ─────────────────────────────────── */
const LAST_KEY = 'qap.featureTree.lastSelection';
function readLastSelection(): Path | null {
try {
const raw = sessionStorage.getItem(LAST_KEY);
if (!raw) return null;
const p = JSON.parse(raw) as Path;
return p && typeof p.modelId === 'string' ? p : null;
} catch {
return null;
}
}
function writeLastSelection(p: Path) {
try {
sessionStorage.setItem(LAST_KEY, JSON.stringify(p));
} catch {
/* 忽略存储不可用 */
}
}
function KbBadge({ n, tokens }: { n: number; tokens: ThemeTokens }) {
if (n === 0) return null;
return (
<span style={{
fontSize: 11, fontWeight: 800, color: tokens.onAccent, background: tokens.warning,
padding: '1px 6px', borderRadius: 999, fontVariantNumeric: 'tabular-nums', flexShrink: 0,
}}>
{n}
</span>
);
}
function DetailPanel({
node,
onOpenKnowledge,
onSelect,
onSelectMethod,
}: {
node: { kind: 'model'; node: FeatureModel } | { kind: 'process'; node: FeatureProcess } | { kind: 'method'; node: FeatureMethod } | null;
onOpenKnowledge?: (role: RoleKey, chunkId: string) => void;
onSelect: (p: Path) => void;
onSelectMethod: (m: FeatureMethod) => void;
}) {
const { tokens } = useTheme();
const label: React.CSSProperties = { fontSize: 12, fontWeight: 700, color: tokens.textMuted, letterSpacing: '0.06em' };
const kv: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: 4, marginBottom: 10 };
if (!node) {
return (
<div style={{ flex: 1, display: 'grid', placeItems: 'center', color: tokens.textMuted, fontSize: 14 }}>
在左侧特征树选择一个节点
</div>
);
}
const { kind, node: n } = node;
const tag = kind === 'model' ? '机型' : kind === 'process' ? '工艺' : '生产方法';
const tagColor = kind === 'model' ? tokens.accent : kind === 'process' ? tokens.info : tokens.success;
const title = n.label;
const subtitle = kind === 'method'
? `${(n as FeatureMethod).modelId} / ${(n as FeatureMethod).processId}`
: kind === 'process' ? (n as FeatureProcess).modelId : '';
const kbList = kind === 'model' ? (n as FeatureModel).kbRefs
: kind === 'process' ? (n as FeatureProcess).kbRefs
: (n as FeatureMethod).kbRefs;
return (
<div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
<div style={{
padding: '9px 12px 8px', borderBottom: `1px solid ${tokens.border}`, flex: '0 0 auto',
display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap',
}}>
<span style={{
fontSize: 12, fontWeight: 800, color: tokens.onAccent, padding: '1px 7px', borderRadius: 999,
background: tagColor, flexShrink: 0,
}}>{tag}</span>
<span style={{ fontSize: 16, fontWeight: 800, color: tokens.text, letterSpacing: '0.02em' }}>{title}</span>
{subtitle && (
<span style={{ fontSize: 12, color: tokens.textMuted, fontFamily: 'ui-monospace, SFMono-Regular, monospace' }}>
{subtitle}
</span>
)}
<span style={{ flex: 1 }} />
{kind === 'method' && (
<MethodStats method={n as FeatureMethod} tokens={tokens} />
)}
</div>
<div style={{ flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden', padding: '10px 12px 12px' }}>
{kind === 'method'
? <MethodDetail
method={n as FeatureMethod}
tokens={tokens}
label={label}
onOpenKnowledge={onOpenKnowledge}
onSelectMethod={onSelectMethod}
/>
: (
<>
<AttrGrid attrs={n.attrs} tokens={tokens} label={label} />
{kind === 'model' && (
<div style={kv}>
<span style={label}>工艺 {(n as FeatureModel).processes.length} 个</span>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 5 }}>
{(n as FeatureModel).processes.map(p => (
<button
key={p.id}
onClick={() => onSelect({ modelId: (n as FeatureModel).id, processId: p.id })}
title={`${p.methods.length} 个生产方法 · 知识 ${p.kbRefs.length} 条`}
style={chipBtn(tokens)}
>
<GitBranch size={11} style={{ color: tokens.info }} />
{p.label}
<span style={{ color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>{p.methods.length}</span>
{p.kbRefs.length > 0 && (
<span style={{ color: tokens.warning, fontWeight: 800 }}>{p.kbRefs.length}</span>
)}
</button>
))}
</div>
</div>
)}
{kind === 'process' && (
<div style={kv}>
<span style={label}>生产方法 {(n as FeatureProcess).methods.length} 个</span>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 5 }}>
{(n as FeatureProcess).methods.map(m => (
<button
key={m.id}
onClick={() => onSelectMethod(m)}
title={`真实知识 ${m.realCount} 条 · 示例 ${m.exampleCount} 条`}
style={chipBtn(tokens)}
>
<Wrench size={11} style={{ color: m.realCount > 0 ? tokens.success : tokens.textMuted }} />
{m.label}
<span style={{ color: m.realCount > 0 ? tokens.warning : tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>
{m.summary.length}
</span>
</button>
))}
</div>
</div>
)}
<KbList list={kbList} onOpenKnowledge={onOpenKnowledge} tokens={tokens} label={label} />
</>
)}
</div>
</div>
);
}
function MethodStats({ method, tokens }: { method: FeatureMethod; tokens: ThemeTokens }) {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 5, flexWrap: 'wrap' }}>
<span style={{
fontSize: 11.5, fontWeight: 800, padding: '1px 7px', borderRadius: 999,
color: method.realCount > 0 ? tokens.warning : tokens.textMuted,
background: method.realCount > 0 ? tokens.warningBg : tokens.panelBgAlt,
border: `1px solid ${method.realCount > 0 ? `${tokens.warning}44` : tokens.border}`,
fontVariantNumeric: 'tabular-nums',
}}>真实知识 {method.realCount}</span>
<span style={{
fontSize: 11.5, fontWeight: 700, padding: '1px 7px', borderRadius: 999,
color: tokens.textSub, background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
fontVariantNumeric: 'tabular-nums',
}}>示例 {method.exampleCount}</span>
<span style={{
fontSize: 11.5, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums',
}}>共 {method.summary.length} 行</span>
</div>
);
}
/* ── 生产方法详情:问题 / 原因 / 对策 / 角色 总结表 ───────────────────── */
function MethodDetail({
method, tokens, label, onOpenKnowledge, onSelectMethod,
}: {
method: FeatureMethod;
tokens: ThemeTokens;
label: React.CSSProperties;
onOpenKnowledge?: (role: RoleKey, chunkId: string) => void;
onSelectMethod: (m: FeatureMethod) => void;
}) {
const hasExample = method.exampleCount > 0;
const hasReal = method.realCount > 0;
const siblings = (() => {
const model = getFeatureTree().models.find(m => m.id === method.modelId);
const proc = model?.processes.find(p => p.id === method.processId);
return proc?.methods.filter(m => m.id !== method.id) ?? [];
})();
return (
<>
{hasExample && (
<div style={{
display: 'flex', alignItems: 'flex-start', gap: 6, padding: '6px 9px', borderRadius: 8,
background: tokens.panelBgAlt, border: `1px dashed ${tokens.borderAccent}`, marginBottom: 8,
}}>
<span style={{
fontSize: 11, fontWeight: 800, color: tokens.textSub, background: tokens.kpiCardBg,
border: `1px solid ${tokens.border}`, padding: '1px 5px', borderRadius: 5, flexShrink: 0, marginTop: 1,
}}>示例</span>
<span style={{ fontSize: 12, lineHeight: 1.6, color: tokens.textSub }}>
{hasReal
? `有 ${method.exampleCount} 行是示例补齐(不是知识库原文),其余来自知识库切片。`
: `该生产方法暂无知识库切片,以下 ${method.exampleCount} 行按方法模板生成,仅用于演示结构,不作为知识事实。`}
</span>
</div>
)}
<div style={{ marginBottom: 10 }}>
<div style={{
border: `1px solid ${tokens.border}`, borderRadius: 9, overflow: 'hidden',
background: tokens.panelBgAlt,
}}>
<table style={{ width: '100%', borderCollapse: 'collapse', tableLayout: 'fixed' }}>
<colgroup>
<col style={{ width: 88 }} />
<col style={{ width: '24%' }} />
<col style={{ width: '24%' }} />
<col style={{ width: '34%' }} />
<col style={{ width: 94 }} />
</colgroup>
<thead>
<tr style={{ background: tokens.tableHeaderBg }}>
{['角色', '问题', '原因', '对策', '来源'].map((h, i) => (
<th key={h} style={{
padding: '6px 8px', textAlign: i === 4 ? 'center' : 'left',
fontSize: 11.5, fontWeight: 800, color: tokens.textMuted, letterSpacing: '0.06em',
borderBottom: `1px solid ${tokens.border}`,
}}>{h}</th>
))}
</tr>
</thead>
<tbody>
{method.summary.map((row, i) => (
<SummaryTableRow
key={row.id}
row={row}
tokens={tokens}
zebra={i % 2 === 1}
onOpenKnowledge={onOpenKnowledge}
/>
))}
</tbody>
</table>
</div>
</div>
<RoleCoverage method={method} tokens={tokens} label={label} />
<SourceExcerpts method={method} tokens={tokens} label={label} onOpenKnowledge={onOpenKnowledge} />
{method.refs.length > 0 && (
<div style={kvBlock}>
<span style={label}>关联数据 {method.refs.length} 项</span>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 5 }}>
{method.refs.map((r, i) => (
<span
key={`${r.objKey}-${r.instanceId ?? ''}-${i}`}
title={r.why}
style={{
display: 'inline-flex', alignItems: 'center', gap: 5, padding: '2px 7px', borderRadius: 6,
fontSize: 12, color: tokens.textSub, background: tokens.kpiCardBg,
border: `1px solid ${tokens.border}`, fontFamily: 'ui-monospace, SFMono-Regular, monospace',
}}
>
{r.objKey}
{r.instanceId ? ` · ${r.instanceId}` : ''}
</span>
))}
</div>
</div>
)}
<div style={{ display: 'flex', flexDirection: 'column', gap: 5 }}>
<ContextDetails title={`机型上下文 · ${method.modelId}`} attrs={method.modelAttrs} tokens={tokens} />
<ContextDetails title={`工艺上下文 · ${method.processId}`} attrs={method.processAttrs} tokens={tokens} />
</div>
{siblings.length > 0 && (
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, marginTop: 9 }}>
<span style={label}>同工艺其他方法 {siblings.length} 个</span>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 5 }}>
{siblings.map(m => (
<button
key={m.id}
onClick={() => onSelectMethod(m)}
title={`真实知识 ${m.realCount} 条 · 示例 ${m.exampleCount} 条`}
style={chipBtn(tokens)}
>
<Wrench size={11} style={{ color: m.realCount > 0 ? tokens.success : tokens.textMuted }} />
{m.label}
<span style={{ color: m.realCount > 0 ? tokens.warning : tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>
{m.realCount > 0 ? m.realCount : '示例'}
</span>
</button>
))}
</div>
</div>
)}
</>
);
}
const kvBlock: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: 4, marginBottom: 10 };
const chunkText = (role: RoleKey, chunkId: string) =>
roleDocs.find(d => d.role === role)?.chunks.find(c => c.id === chunkId)?.text ?? '';
/* 角色覆盖:一眼看出该方法有哪些角色在管、哪些还空着 */
function RoleCoverage({ method, tokens, label }: { method: FeatureMethod; tokens: ThemeTokens; label: React.CSSProperties }) {
const roles: RoleKey[] = ['PE', 'IE', 'QE', 'ME'];
return (
<div style={kvBlock}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 6 }}>
<span style={label}>角色覆盖</span>
<span style={{ fontSize: 11.5, color: tokens.textMuted }}>
{roles.filter(r => method.summary.some(x => x.role === r)).length} / 4 角色已挂载
</span>
</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: 6 }}>
{roles.map(role => {
const rows = method.summary.filter(r => r.role === role);
const real = rows.filter(r => r.source.kind === 'kb').length;
const example = rows.length - real;
const empty = rows.length === 0;
return (
<div key={role} style={{
padding: '5px 8px', borderRadius: 8,
background: empty ? 'transparent' : tokens.panelBgAlt,
border: `1px ${empty ? 'dashed' : 'solid'} ${empty ? tokens.border : tokens.borderSub}`,
opacity: empty ? 0.75 : 1,
}}>
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
<span style={{
fontSize: 11, fontWeight: 800, color: tokens.onAccent, background: ROLE_COLOR[role],
padding: '0 4px', borderRadius: 4, flexShrink: 0,
}}>{role}</span>
<span style={{ fontSize: 11.5, color: tokens.textSub, flex: 1 }}>{ROLE_FULL[role]}</span>
<span style={{
fontSize: 11.5, fontWeight: 800, color: empty ? tokens.textMuted : tokens.text,
fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap',
}}>{empty ? '未覆盖' : `${rows.length} 行`}</span>
</div>
<div style={{
marginTop: 3, fontSize: 11, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums',
display: 'flex', gap: 6, whiteSpace: 'nowrap',
}}>
{empty ? <span>无知识行</span> : <><span>真实 {real}</span><span>示例 {example}</span></>}
</div>
</div>
);
})}
</div>
</div>
);
}
/* 知识原文节选:表格是提炼行,这里保留可核对的原文 */
function SourceExcerpts({
method, tokens, label, onOpenKnowledge,
}: {
method: FeatureMethod;
tokens: ThemeTokens;
label: React.CSSProperties;
onOpenKnowledge?: (role: RoleKey, chunkId: string) => void;
}) {
const rows = method.summary.filter(r => r.source.kind === 'kb');
if (rows.length === 0) {
const checklist: [RoleKey, string][] = [
['PE', '工艺参数卡 / DFM 检查表'],
['IE', 'SOP 与标准节拍 / 工装方案'],
['QE', '检验标准 / 抽检频次'],
['ME', '设备参数卡 / 点检表'],
];
return (
<div style={{
padding: '9px 11px', borderRadius: 9, marginBottom: 10,
background: tokens.accentBg, border: `1px dashed ${tokens.borderAccent}`,
}}>
<div style={{ fontSize: 12.5, fontWeight: 800, color: tokens.text, marginBottom: 3 }}>
该生产方法还没有知识库切片
</div>
<div style={{ fontSize: 12, lineHeight: 1.65, color: tokens.textSub }}>
上表 {method.exampleCount} 行全部是示例。补齐路径:① 在知识库上传该方法的 SOP / 检验标准;
② 给切片标注「所属特征树」;③ 回到这里即可换成带来源的真实总结。
</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: 5, marginTop: 7 }}>
{checklist.map(([role, items]) => (
<div key={role} style={{
display: 'flex', alignItems: 'flex-start', gap: 5, padding: '4px 6px', borderRadius: 7,
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
}}>
<span style={{
fontSize: 11, fontWeight: 800, color: tokens.onAccent, background: ROLE_COLOR[role],
padding: '0 4px', borderRadius: 4, flexShrink: 0, marginTop: 1,
}}>{role}</span>
<span style={{ fontSize: 11.5, lineHeight: 1.45, color: tokens.textSub }}>{items}</span>
</div>
))}
</div>
</div>
);
}
return (
<div style={kvBlock}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: 6 }}>
<span style={label}>知识原文节选 {rows.length} 条</span>
<span style={{ fontSize: 11.5, color: tokens.textMuted }}>点卡片回到知识库切片</span>
</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 6 }}>
{rows.map(row => {
if (row.source.kind !== 'kb') return null;
const text = chunkText(row.role, row.source.chunkId);
return (
<button
key={row.id}
onClick={() => onOpenKnowledge?.(row.role, row.source.kind === 'kb' ? row.source.chunkId : '')}
title={text}
style={{
textAlign: 'left', cursor: onOpenKnowledge ? 'pointer' : 'default',
padding: '6px 8px', borderRadius: 8,
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
display: 'flex', flexDirection: 'column', gap: 3, minWidth: 0,
}}
>
<span style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
<span style={{
fontSize: 11, fontWeight: 800, color: tokens.onAccent, background: ROLE_COLOR[row.role],
padding: '0 4px', borderRadius: 4, flexShrink: 0,
}}>{row.role}</span>
<span style={{
fontSize: 11, color: tokens.textMuted, fontFamily: 'ui-monospace, SFMono-Regular, monospace',
}}>{row.source.kind === 'kb' ? row.source.chunkId : ''}</span>
<span style={{ flex: 1 }} />
<BookOpen size={10} style={{ color: tokens.accent, flexShrink: 0 }} />
</span>
<span style={{
fontSize: 12, lineHeight: 1.55, color: tokens.textSub,
display: '-webkit-box', WebkitLineClamp: 3, WebkitBoxOrient: 'vertical', overflow: 'hidden',
}}>{text || row.problem}</span>
</button>
);
})}
</div>
</div>
);
}
function SummaryTableRow({
row, tokens, zebra, onOpenKnowledge,
}: {
row: MethodSummaryRow;
tokens: ThemeTokens;
zebra: boolean;
onOpenKnowledge?: (role: RoleKey, chunkId: string) => void;
}) {
const isKb = row.source.kind === 'kb';
const cell: React.CSSProperties = {
padding: '8px 9px', verticalAlign: 'top', fontSize: 12.5, lineHeight: 1.6,
color: tokens.text, borderBottom: `1px solid ${tokens.borderSub}`,
wordBreak: 'break-word',
};
return (
<tr style={{ background: isKb ? (zebra ? tokens.tableRowAlt : 'transparent') : tokens.kpiCardBg }}>
<td style={{ ...cell, borderBottom: `1px solid ${tokens.borderSub}` }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
<span style={{
fontSize: 11, fontWeight: 800, color: tokens.onAccent, background: ROLE_COLOR[row.role],
padding: '1px 5px', borderRadius: 4, flexShrink: 0,
}}>{row.role}</span>
<span style={{ fontSize: 11, color: tokens.textMuted, whiteSpace: 'nowrap' }}>{ROLE_LABEL[row.role]}</span>
</div>
</td>
<td style={{ ...cell, fontWeight: 600 }}>{row.problem}</td>
<td style={{ ...cell, color: tokens.textSub }}>{row.cause}</td>
<td style={{ ...cell, color: tokens.textSub }}>{row.action}</td>
<td style={{ ...cell, textAlign: 'center' }}>
{isKb ? (
<button
onClick={() => onOpenKnowledge?.(row.role, row.source.kind === 'kb' ? row.source.chunkId : '')}
title={`${row.role} 知识切片 ${row.source.kind === 'kb' ? row.source.chunkId : ''}`}
style={{
display: 'inline-flex', alignItems: 'center', gap: 3, cursor: onOpenKnowledge ? 'pointer' : 'default',
padding: '1px 6px', borderRadius: 5, fontSize: 11, fontWeight: 700,
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
whiteSpace: 'nowrap',
}}
>
<BookOpen size={10} />
原文 {row.source.kind === 'kb' ? row.source.chunkId : ''}
</button>
) : (
<span style={{
display: 'inline-flex', alignItems: 'center', padding: '1px 6px', borderRadius: 5,
fontSize: 11, fontWeight: 800, color: tokens.textSub,
background: tokens.panelBgAlt, border: `1px dashed ${tokens.borderAccent}`, whiteSpace: 'nowrap',
}}>示例</span>
)}
</td>
</tr>
);
}
function ContextDetails({ title, attrs, tokens }: { title: string; attrs: { label: string; value: string }[]; tokens: ThemeTokens }) {
if (attrs.length === 0) return null;
return (
<details open style={{
borderRadius: 8, background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
}}>
<summary style={{
cursor: 'pointer', padding: '5px 9px', fontSize: 12, fontWeight: 700,
color: tokens.textSub, letterSpacing: '0.04em', listStyle: 'none',
}}>
{title} · {attrs.length} 项
</summary>
<div style={{
display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(240px, 1fr))', gap: 4,
padding: '0 9px 8px',
}}>
{attrs.map(a => (
<div key={a.label} style={{
display: 'flex', alignItems: 'baseline', gap: 6, padding: '2px 0',
borderTop: `1px solid ${tokens.borderSub}`,
}}>
<span style={{ fontSize: 11, color: tokens.textMuted, flexShrink: 0, minWidth: 54 }}>{a.label}</span>
<span style={{ fontSize: 12, color: tokens.text, lineHeight: 1.5, wordBreak: 'break-word' }}>{a.value}</span>
</div>
))}
</div>
</details>
);
}
function AttrGrid({ attrs, tokens, label }: { attrs: { label: string; value: string }[]; tokens: ThemeTokens; label: React.CSSProperties }) {
if (attrs.length === 0) return null;
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, marginBottom: 10 }}>
<span style={label}>属性 {attrs.length} 项</span>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(190px, 1fr))', gap: 5 }}>
{attrs.map(a => (
<div key={a.label} style={{
padding: '5px 8px', borderRadius: 7, background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
}}>
<div style={{ fontSize: 11, fontWeight: 800, color: tokens.textMuted, marginBottom: 1 }}>{a.label}</div>
<div style={{ fontSize: 12.5, color: tokens.text, lineHeight: 1.45, wordBreak: 'break-word' }}>{a.value}</div>
</div>
))}
</div>
</div>
);
}
function KbList({
list, onOpenKnowledge, tokens, label,
}: {
list: KbRef[];
onOpenKnowledge?: (role: RoleKey, chunkId: string) => void;
tokens: ThemeTokens;
label: React.CSSProperties;
}) {
if (list.length === 0 || !onOpenKnowledge) return null;
return (
<div style={{ ...kvBlock, paddingTop: 8, borderTop: `1px solid ${tokens.border}` }}>
<span style={label}>知识挂载 {list.length} 条</span>
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
{list.map((r, i) => (
<button
key={`${r.role}-${r.chunkId}-${i}`}
onClick={() => onOpenKnowledge(r.role, r.chunkId)}
style={{
textAlign: 'left', cursor: 'pointer', padding: '5px 8px', borderRadius: 7,
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
display: 'flex', alignItems: 'center', gap: 6,
}}
>
<BookOpen size={11} style={{ color: tokens.accent, flexShrink: 0 }} />
<span style={{
fontSize: 11, fontWeight: 800, color: tokens.onAccent, background: ROLE_COLOR[r.role],
padding: '1px 5px', borderRadius: 4, flexShrink: 0,
}}>{r.role}</span>
<span style={{
fontSize: 12.5, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis',
whiteSpace: 'nowrap', flex: 1,
}}>{r.label}</span>
<span style={{
fontSize: 11, color: tokens.textMuted, flexShrink: 0,
fontFamily: 'ui-monospace, SFMono-Regular, monospace',
}}>{r.chunkId}</span>
</button>
))}
</div>
</div>
);
}
const chipBtn = (tokens: ThemeTokens): React.CSSProperties => ({
display: 'inline-flex', alignItems: 'center', gap: 4, cursor: 'pointer',
padding: '2px 7px', borderRadius: 6, fontSize: 12, color: tokens.textSub,
background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`,
});