优化删除一些无效文件

This commit is contained in:
2026-11-19 11:02:39 +08:00
parent d2013c2a07
commit 2b1abd3907
90 changed files with 62 additions and 19560 deletions
@@ -1,621 +0,0 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { ArrowRight, Ban, Bot, ChevronDown, ChevronsDown, ChevronUp, ChevronsUp, Layers, Radio, Send, Sparkles, User, Users } from 'lucide-react';
import { useTheme } from '../context/ThemeContext';
import type { ThemeTokens } from '../context/ThemeContext';
import { useText } from '../i18n/useText';
import type { I18n } from '../i18n/locales';
import { SUGGESTED } from '../lib/qualityAsk';
import type { AskJump } from '../lib/qualityAsk';
import { qualityExperts } from '../lib/teams';
import type { ConsultTurn, ExpertTeam, MetricSnap } from '../lib/teams';
import { consultPlan } from '../hooks/useAgentChat';
import type { AgentChat, ConsultBlockKey, PendingConsult } from '../hooks/useAgentChat';
import AskAnswerCard, { JumpButton } from './agent/AskAnswerCard';
import TeamPicker from './agent/TeamPicker';
interface AgentDockProps {
/** 会话状态机由父级持有:本体舞台换掉内容区时对话历史不丢 */
chat: AgentChat;
/** 专家团:非空时对话区切换为多智能体轮流会诊 */
team: ExpertTeam | null;
onConveneTeam: (team: ExpertTeam) => void;
onDismissTeam: () => void;
/** 回答卡里的跳转:指标 / 页签 / 本体 / 数据集 / 知识库 / 特征建模 / 追问 */
onJump: (j: AskJump) => void;
/** 高度由父级持有,全屏切换时不丢失展开状态 */
height: number;
onToggle: () => void;
/** 拉高态:对话区进一步往上拉高(第三高度档) */
tall: boolean;
onToggleTall: () => void;
}
const clock = () => {
const d = new Date();
const p = (n: number) => String(n).padStart(2, '0');
return `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
};
const levelColor = (lv: MetricSnap['level'], tk: ThemeTokens) =>
lv === 'good' ? tk.success : lv === 'warn' ? tk.warning : tk.danger;
/** 成员卡内的一行:小标签 + 文本;流式中在句尾挂一枚闪烁光标 */
function SecRow({ label, text, tk, color, typing }: { label: string; text?: string; tk: ThemeTokens; color?: string; typing?: boolean }) {
if (!text) return null;
return (
<div style={{ display: 'flex', gap: 7, alignItems: 'flex-start' }}>
<span style={{
flex: '0 0 auto', fontSize: 10.5, fontWeight: 700, marginTop: 1, padding: '1px 6px', borderRadius: 6,
color: color ?? tk.textMuted,
background: color ? `${color}1a` : tk.panelBgAlt,
border: `1px solid ${color ? `${color}33` : tk.border}`,
}}>{label}</span>
<span style={{ fontSize: 12.5, lineHeight: 1.6, color: tk.textSub, minWidth: 0 }}>
{text}{typing && <span className="stream-caret" />}
</span>
</div>
);
}
/** 卡片刚立起来、正文还没铺开时的占位:避免出现一个空白发言卡 */
function ReaderHint({ tk, t }: { tk: ThemeTokens; t: I18n }) {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 7, color: tk.textMuted, fontSize: 12 }}>
<span style={{ display: 'flex', gap: 3 }}>
{[0, 1, 2].map(i => <i key={i} className="typing-dot" style={{ animationDelay: `${i * 0.16}s` }} />)}
</span>
{t.agent.thinking}…
</div>
);
}
/** 会诊流式:某个块此刻该显示到什么程度;没有 stream 时整块直接显示 */
function blockView(
turn: ConsultTurn, stream: PendingConsult | undefined, key: ConsultBlockKey,
): { visible: boolean; text?: string; items: number; typing: boolean } {
if (!stream) return { visible: true, items: Number.POSITIVE_INFINITY, typing: false };
const plan = consultPlan(turn);
const i = plan.findIndex(b => b.key === key);
if (i < 0) return { visible: true, items: Number.POSITIVE_INFINITY, typing: false };
const b = plan[i];
if (i < stream.done) {
return { visible: true, text: b.mode === 'type' ? b.text : undefined, items: b.count ?? 0, typing: false };
}
if (i === stream.done) {
if (b.mode === 'type') {
return {
visible: stream.typed > 0, typing: stream.typed > 0,
text: (b.text ?? '').slice(0, stream.typed), items: 0,
};
}
if (b.mode === 'item') return { visible: stream.items > 0, items: stream.items, typing: false };
return { visible: false, items: 0, typing: false };
}
return { visible: false, items: 0, typing: false };
}
/** 专家成员发言卡:指标数据条 + 现状/观点/建议 + 移交衔接;stream 存在时按块流式铺开 */
function MemberCard({ turn, tk, t, time, onJump, stream }: { turn: ConsultTurn; tk: ThemeTokens; t: I18n; time: string; onJump: (j: AskJump) => void; stream?: PendingConsult }) {
const m = turn.metric;
const lc = m ? levelColor(m.level, tk) : tk.accent;
const metric = blockView(turn, stream, 'metric');
const reading = blockView(turn, stream, 'reading');
const status = blockView(turn, stream, 'status');
const stance = blockView(turn, stream, 'stance');
const proposal = blockView(turn, stream, 'proposal');
const handoff = blockView(turn, stream, 'handoff');
return (
<div data-role="consult-card" className="content-reveal" style={{ display: 'flex', justifyContent: 'flex-start', marginBottom: 8 }}>
<div style={{ maxWidth: '92%', minWidth: 0 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 4 }}>
<span style={{ width: 18, height: 18, borderRadius: 6, display: 'grid', placeItems: 'center', flexShrink: 0, background: tk.cardBg, border: `1px solid ${tk.border}` }}>
<User size={11} color={tk.accent} />
</span>
<span style={{ fontSize: 12.5, fontWeight: 700, color: tk.text, flexShrink: 0 }}>{turn.name}</span>
{turn.tag && <span style={{ fontSize: 10.5, color: tk.textMuted, padding: '0 6px', borderRadius: 7, border: `1px solid ${tk.border}`, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', maxWidth: 160 }}>{turn.tag}</span>}
{turn.intent && (
<span style={{ fontSize: 10.5, color: tk.accent, padding: '0 6px', borderRadius: 7, border: `1px solid ${tk.borderAccent}`, background: tk.accentBg, whiteSpace: 'nowrap' }}>
{t.agent.secIntent}:{turn.intent}
</span>
)}
<span style={{ marginLeft: 'auto', color: tk.textMuted, fontSize: 10.5, fontVariantNumeric: 'tabular-nums' }}>{time}</span>
</div>
<div style={{ background: tk.cardBg, border: `1px solid ${tk.border}`, borderLeft: `3px solid ${lc}`, borderRadius: '4px 10px 10px 10px', padding: '9px 11px', display: 'flex', flexDirection: 'column', gap: 7 }}>
{stream && stream.done === 0 && stream.typed === 0 && stream.items === 0 && <ReaderHint tk={tk} t={t} />}
{m && metric.visible && (
<div className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', flexDirection: 'column', gap: 7 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '5px 9px', borderRadius: 8, background: tk.panelBgAlt, border: `1px solid ${tk.borderSub}` }}>
<span style={{ flex: 1, minWidth: 0, fontSize: 12, color: tk.textSub, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{m.label}</span>
<span style={{ fontSize: 13, fontWeight: 700, color: tk.text, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace' }}>{m.value}</span>
<span style={{ fontSize: 11, fontWeight: 700, color: lc, background: `${lc}1a`, border: `1px solid ${lc}33`, borderRadius: 6, padding: '0 6px', whiteSpace: 'nowrap' }}>{m.state}</span>
<span style={{ fontSize: 11.5, color: lc, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace', maxWidth: 180, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{m.deviation}</span>
</div>
{/* 判定线原文:源表没设线就照实写,不补达成率 */}
<div style={{ fontSize: 10.5, color: tk.textMuted, lineHeight: 1.5, marginTop: -2 }}>
{t.agent.lineLabel}:{m.line}
</div>
</div>
)}
{!!turn.reading?.length && reading.visible && (
<div className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
{turn.reading.map((r, i) => (
<span key={i} style={{ display: 'flex', alignItems: 'baseline', gap: 4, padding: '2px 8px', borderRadius: 7, background: tk.panelBgAlt, border: `1px solid ${tk.borderSub}` }}>
<span style={{ fontSize: 10.5, color: tk.textMuted }}>{r.label}</span>
<b style={{ fontSize: 12, color: tk.text, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace' }}>{r.value}</b>
</span>
))}
</div>
)}
{status.visible && (
<div className={stream ? 'content-reveal' : undefined}>
<SecRow label={t.agent.secStatus} text={status.text ?? turn.status} typing={status.typing} tk={tk} />
</div>
)}
{stance.visible && (
<div className={stream ? 'content-reveal' : undefined}>
<SecRow label={t.agent.secStance} text={stance.text ?? turn.stance} typing={stance.typing} tk={tk} color={lc} />
</div>
)}
{proposal.visible && (
<div className={stream ? 'content-reveal' : undefined}>
<SecRow label={t.agent.secProposal} text={proposal.text ?? turn.proposal} typing={proposal.typing} tk={tk} color={tk.accent} />
</div>
)}
{handoff.visible && (
<div className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
{turn.handoff && (
<div style={{ display: 'flex', alignItems: 'center', gap: 5, fontSize: 11, color: tk.textMuted }}>
<ArrowRight size={11} color={tk.accent} style={{ flexShrink: 0 }} />
{t.agent.handoff} →
<span style={{ color: tk.accent, fontWeight: 700 }}>{turn.handoff}</span>
</div>
)}
<span style={{ flex: 1 }} />
{turn.jump && <JumpButton jump={turn.jump} label={t.agent.jumpSee} tk={tk} onJump={onJump} />}
</div>
)}
</div>
</div>
</div>
);
}
/** 牵头结论卡:结论 headline + 成员要点 + 研判数据条 + 联合行动清单;stream 存在时逐块铺开 */
function LeadCard({ turn, tk, t, time, onJump, stream }: { turn: ConsultTurn; tk: ThemeTokens; t: I18n; time: string; onJump: (j: AskJump) => void; stream?: PendingConsult }) {
const j = turn.judge;
const lc = j ? levelColor(j.level, tk) : tk.accent;
const marks = ['①', '②', '③'];
const concl = blockView(turn, stream, 'conclusion');
const summary = blockView(turn, stream, 'summary');
const judge = blockView(turn, stream, 'judge');
const actions = blockView(turn, stream, 'actions');
return (
<div data-role="consult-card" className="content-reveal" style={{ display: 'flex', justifyContent: 'flex-start', marginBottom: 8 }}>
<div style={{ maxWidth: '94%', minWidth: 0 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 4 }}>
<span style={{ width: 18, height: 18, borderRadius: 6, display: 'grid', placeItems: 'center', flexShrink: 0, background: `linear-gradient(135deg, ${tk.accent}, ${tk.info})` }}>
<Sparkles size={11} color={tk.onAccent} />
</span>
<span style={{ fontSize: 12.5, fontWeight: 700, color: tk.accent, flexShrink: 0 }}>{turn.name}</span>
{turn.tag && <span style={{ fontSize: 10.5, color: tk.accent, padding: '0 6px', borderRadius: 7, border: `1px solid ${tk.borderAccent}`, background: tk.accentBg, whiteSpace: 'nowrap' }}>{turn.tag}</span>}
<span style={{ marginLeft: 'auto', color: tk.textMuted, fontSize: 10.5, fontVariantNumeric: 'tabular-nums' }}>{time}</span>
</div>
<div style={{ background: tk.accentBg, border: `1px solid ${tk.borderAccent}`, borderRadius: '4px 12px 12px 12px', padding: '10px 12px', display: 'flex', flexDirection: 'column', gap: 9, boxShadow: `0 0 0 1px ${tk.accent}1f` }}>
{stream && stream.done === 0 && stream.typed === 0 && stream.items === 0 && <ReaderHint tk={tk} t={t} />}
{turn.conclusion && concl.visible && (
<div className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', gap: 7, alignItems: 'flex-start' }}>
<span style={{ flex: '0 0 auto', fontSize: 10.5, fontWeight: 700, color: tk.accent, background: `${tk.accent}1a`, border: `1px solid ${tk.borderAccent}`, borderRadius: 6, padding: '1px 6px', marginTop: 1 }}>{t.agent.concl}</span>
<span style={{ fontSize: 13, fontWeight: 700, lineHeight: 1.6, color: tk.text, minWidth: 0 }}>
{concl.text ?? turn.conclusion}{concl.typing && <span className="stream-caret" />}
</span>
</div>
)}
{!!turn.summary?.length && summary.visible && (
<div className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
<span style={{ fontSize: 10.5, fontWeight: 700, color: tk.textMuted, letterSpacing: '0.04em' }}>{t.agent.keypoints}</span>
{turn.summary.slice(0, summary.items).map((srow, i) => (
<div key={i} className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', gap: 7, alignItems: 'flex-start' }}>
<span style={{ width: 5, height: 5, borderRadius: 5, background: tk.accent, flex: '0 0 5px', marginTop: 6 }} />
<span style={{ fontSize: 12, color: tk.text, fontWeight: 600, flexShrink: 0 }}>{srow.name}</span>
<span style={{ fontSize: 12, color: tk.textSub, minWidth: 0 }}>{srow.point}</span>
</div>
))}
</div>
)}
{j && judge.visible && (
<div className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
<span style={{ fontSize: 10.5, fontWeight: 700, color: tk.textMuted, letterSpacing: '0.04em' }}>{t.agent.judgeLabel}</span>
<div style={{ display: 'flex', alignItems: 'center', gap: 9, padding: '6px 10px', borderRadius: 8, background: tk.panelBgAlt, border: `1px solid ${tk.borderSub}` }}>
<span style={{ fontSize: 17, fontWeight: 800, color: lc, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace', lineHeight: 1, flexShrink: 0 }}>{j.value}</span>
<span style={{ flex: 1, minWidth: 0, fontSize: 11.5, color: tk.textSub, lineHeight: 1.5 }}>{j.label} · {j.note}</span>
<span style={{ fontSize: 11, fontWeight: 700, color: lc, background: `${lc}1a`, border: `1px solid ${lc}33`, borderRadius: 6, padding: '1px 7px', whiteSpace: 'nowrap', flexShrink: 0 }}>{j.state}</span>
</div>
</div>
)}
{!!turn.actions?.length && actions.visible && (
<div className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', flexDirection: 'column', gap: 5 }}>
<span style={{ fontSize: 10.5, fontWeight: 700, color: tk.textMuted, letterSpacing: '0.04em' }}>{t.agent.actionsLabel}</span>
{turn.actions.slice(0, actions.items).map((a, i) => (
<div key={i} className={stream ? 'content-reveal' : undefined} style={{ display: 'flex', gap: 7, alignItems: 'flex-start' }}>
<span style={{ flex: '0 0 auto', fontSize: 12, color: tk.accent, fontWeight: 700, lineHeight: 1.5 }}>{marks[i] ?? '·'}</span>
<span style={{ fontSize: 12, lineHeight: 1.6, color: tk.textSub, minWidth: 0, flex: 1 }}>
<span style={{ color: tk.text, fontWeight: 600 }}>{a.owner}</span>
<span style={{ color: tk.textMuted }}>({a.role})</span> {a.action}
</span>
{a.jump && <JumpButton jump={a.jump} label={t.agent.jumpSee} tk={tk} onJump={onJump} />}
</div>
))}
</div>
)}
</div>
</div>
</div>
);
}
export default function AgentDock({ chat, team, onConveneTeam, onDismissTeam, onJump, height, onToggle, tall, onToggleTall }: AgentDockProps) {
const { tokens } = useTheme();
const { t } = useText();
/* 会话状态机在父级:本组件只管渲染与滚动,进出本体舞台都不会丢掉对话历史 */
const { msgs, pending, pendingTurn, thinking, thinkingName, busy, draft, setDraft, ask, skip, reset } = chat;
const listRef = useRef<HTMLDivElement>(null);
/** 专家团召集面板:点头部「组建专家团」展开 */
const [picker, setPicker] = useState(false);
/** 质量专家名册来自 lib/teams(与会诊同一批人),不再显示经营口径的数字员工 */
const experts = useMemo(() => qualityExperts(), []);
/* 滚动策略:回答卡通常远高于对话区,一律贴底用户只能看到末尾。
- 思考/打字阶段:对齐卡片顶部,让思考轨和逐字结论看得见;
- 分段亮出后:贴底跟随新段;
- 落卡与高度变化:仍然对齐最新答案卡顶部(避免只看到"数据来源"一行)。 */
useEffect(() => {
const el = listRef.current;
if (!el) return;
const cards = el.querySelectorAll<HTMLElement>('[data-role="answer-card"]');
const lastCard = cards[cards.length - 1];
const alignTop = () => {
if (!lastCard) return;
el.scrollTop += lastCard.getBoundingClientRect().top - el.getBoundingClientRect().top - 4;
};
if (pending) {
if (pending.phase === 'think' && pending.typed === 0) {
// 思考阶段盯住最新一步:6 步在 244px 高的对话区里放不下,贴顶只能看到第 1 步
const steps = el.querySelectorAll<HTMLElement>('[data-role="think-step"]');
const step = steps[steps.length - 1];
if (step) el.scrollTop += step.getBoundingClientRect().top - el.getBoundingClientRect().top - 34;
else alignTop();
return;
}
if (pending.phase === 'think' || pending.typed < pending.answer.conclusion.length) alignTop();
else el.scrollTop = el.scrollHeight;
return;
}
if (pendingTurn) {
/* 会诊发言:卡头先贴顶让人看清是谁发言,正文铺开后再贴底跟随新块 */
const consult = el.querySelectorAll<HTMLElement>('[data-role="consult-card"]');
const c = consult[consult.length - 1];
if (c) {
if (pendingTurn.turn.kind !== 'system' && pendingTurn.done <= 1) {
el.scrollTop += c.getBoundingClientRect().top - el.getBoundingClientRect().top - 4;
} else {
el.scrollTop = el.scrollHeight;
}
return;
}
}
const last = msgs[msgs.length - 1];
if (last?.answer && lastCard) { alignTop(); return; }
if (last?.kind === 'member' || last?.kind === 'lead') {
// 会诊发言卡也远高于对话区:对齐卡头,先看到专家名、数据条与现状
const consult = el.querySelectorAll<HTMLElement>('[data-role="consult-card"]');
const c = consult[consult.length - 1];
if (c) { el.scrollTop += c.getBoundingClientRect().top - el.getBoundingClientRect().top - 4; return; }
}
el.scrollTop = el.scrollHeight;
}, [msgs, pending, pendingTurn, thinking, height]);
const expanded = height > 120;
const convene = (next: ExpertTeam) => { setPicker(false); onConveneTeam(next); };
return (
<div style={{
flexShrink: 0, position: 'relative', zIndex: 2,
background: tokens.panelBgAlt, borderRadius: '0 0 16px 16px',
display: 'flex', flexDirection: 'column', overflow: 'hidden', height,
transition: 'height 0.28s cubic-bezier(0.22,1,0.36,1)',
}}>
{/* 与上方工作区的分隔饰条:中央亮渐变主线 + 下溢光晕 + 菱形饰点,比 1px 实线更清晰且有仪式感 */}
<div style={{ flexShrink: 0, position: 'relative', height: 9 }}>
<div style={{
position: 'absolute', left: 0, right: 0, top: 3, height: 2,
background: `linear-gradient(90deg, transparent, ${tokens.accent}55 15%, ${tokens.accent}b3 50%, ${tokens.accent}55 85%, transparent)`,
}} />
<div style={{
position: 'absolute', left: 0, right: 0, top: 5, height: 4,
background: `linear-gradient(to bottom, ${tokens.accentGlow}, transparent)`,
}} />
<div style={{
position: 'absolute', left: '50%', top: 4, width: 7, height: 7,
transform: 'translate(-50%, -50%) rotate(45deg)',
background: tokens.accent, boxShadow: `0 0 8px ${tokens.accentGlow}`,
}} />
<div style={{ position: 'absolute', left: '12%', top: 4, width: 3, height: 3, transform: 'translate(-50%, -50%) rotate(45deg)', background: `${tokens.accent}88` }} />
<div style={{ position: 'absolute', left: '88%', top: 4, width: 3, height: 3, transform: 'translate(-50%, -50%) rotate(45deg)', background: `${tokens.accent}88` }} />
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 14px', flexShrink: 0 }}>
<span style={{
width: 22, height: 22, borderRadius: 7, display: 'grid', placeItems: 'center', flexShrink: 0,
background: `linear-gradient(135deg, ${tokens.accent}, ${tokens.info})`,
}}>
<Bot size={13} color={tokens.onAccent} strokeWidth={2.2} />
</span>
<span style={{ color: tokens.text, fontSize: 14.5, fontWeight: 700, letterSpacing: '0.03em' }}>{t.agent.title}</span>
<span style={{ flex: 1 }} />
{/* 在岗质量专家:六位,悬停看角色;不再是经营口径的数字员工 */}
<span style={{ display: 'flex', gap: 4, alignItems: 'center' }}>
{experts.map(e => (
<span key={e.code} title={`${e.name} · ${e.role}`} style={{
width: 7, height: 7, borderRadius: '50%', background: tokens.accent,
boxShadow: `0 0 6px ${tokens.accentGlow}`, opacity: 0.85,
}} />
))}
</span>
<button
onClick={() => {
// 召集面板比常规高度高:打开时把对话区拉到「拉高」档,五个预设团一屏能看全
if (!expanded) onToggle();
if (!tall) onToggleTall();
setPicker(v => !v);
}}
data-role="open-team-picker"
title={t.team.entry}
className="ghost-btn"
style={{
display: 'flex', alignItems: 'center', gap: 4, cursor: 'pointer', flexShrink: 0,
color: picker ? tokens.onAccent : tokens.accent, fontSize: 12, fontWeight: 700,
background: picker ? tokens.accent : tokens.accentBg,
border: `1px solid ${picker ? tokens.accent : tokens.borderAccent}`,
borderRadius: 12, padding: '2px 9px',
}}
>
<Users size={12} />{t.team.entry}
</button>
<button
onClick={reset}
title={t.agent.clear}
className="ghost-btn"
style={{ display: 'flex', alignItems: 'center', gap: 4, color: tokens.textMuted, fontSize: 12, border: 'none', background: 'transparent', cursor: 'pointer', padding: '2px 6px' }}
>
<Ban size={12} />{t.agent.clear}
</button>
<button
onClick={onToggleTall}
title={tall ? t.agent.tallOff : t.agent.tall}
className="ghost-btn"
style={{
display: 'grid', placeItems: 'center', width: 24, height: 24, borderRadius: 8, cursor: 'pointer', flexShrink: 0,
color: tall ? tokens.onAccent : tokens.accent,
background: tall ? tokens.accent : tokens.accentBg,
border: `1px solid ${tokens.borderAccent}`,
}}
>
{tall ? <ChevronsDown size={13} /> : <ChevronsUp size={13} />}
</button>
<button
onClick={onToggle}
title={expanded ? t.agent.collapse : t.agent.expand}
className="ghost-btn"
style={{
display: 'flex', alignItems: 'center', gap: 3, color: tokens.accent, fontSize: 12, fontWeight: 600,
border: `1px solid ${tokens.borderAccent}`, background: tokens.accentBg, borderRadius: 12, padding: '2px 9px', cursor: 'pointer', flexShrink: 0,
}}
>
{expanded ? <ChevronDown size={12} /> : <ChevronUp size={12} />}
{expanded ? t.agent.collapse : t.agent.expand}
</button>
</div>
{picker && (
<TeamPicker tk={tokens} t={t} onConvene={convene} onClose={() => setPicker(false)} />
)}
{team && (
<div style={{
display: 'flex', alignItems: 'center', gap: 8, margin: '0 14px 6px', padding: '5px 10px',
borderRadius: 9, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`, flexShrink: 0,
}}>
<Users size={13} color={tokens.accent} style={{ flexShrink: 0 }} />
<span style={{ fontSize: 12.5, fontWeight: 700, color: tokens.accent, flexShrink: 0 }}>{team.nameZh}</span>
<span style={{ fontSize: 11.5, color: tokens.textMuted, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
· {team.memberCodes.length} 位专家 · {team.topicZh}
</span>
<span style={{ flex: 1 }} />
<button
onClick={onDismissTeam}
title={t.team.dismiss}
className="ghost-btn"
style={{ display: 'flex', alignItems: 'center', gap: 3, fontSize: 11.5, color: tokens.textMuted, border: 'none', background: 'transparent', cursor: 'pointer', padding: '2px 5px', flexShrink: 0 }}
>
<Ban size={11} />{t.team.dismiss}
</button>
</div>
)}
{expanded && (
<>
<div ref={listRef} className="space-scroll" style={{ flex: 1, overflowY: 'auto', padding: '2px 14px 0', minHeight: 0, display: 'flex', flexDirection: 'column' }}>
{/* 消息贴底:对话从输入框往上长,不留中段空洞(内容满时该占位自动压为 0,不影响滚动) */}
<div style={{ flex: '1 0 0px', minHeight: 0 }} />
{msgs.map(m => {
/* 专家团就位播报:居中虚线卡,区别于专家发言 */
if (m.kind === 'system') {
return (
<div key={m.id} className="content-reveal" style={{ display: 'flex', justifyContent: 'center', marginBottom: 8 }}>
<div style={{
maxWidth: '94%', padding: '7px 12px', borderRadius: 10, whiteSpace: 'pre-wrap', textAlign: 'center',
background: tokens.accentBg, border: `1px dashed ${tokens.borderAccent}`,
color: tokens.textSub, fontSize: 12.5, lineHeight: 1.6,
}}>
<span style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 5, color: tokens.accent, fontWeight: 700, marginBottom: 3 }}>
<Radio size={11} />{m.name} · {m.tag}
</span>
{m.text}
</div>
</div>
);
}
if ((m.kind === 'member' || m.kind === 'lead') && m.turn) {
return m.kind === 'member'
? <MemberCard key={m.id} turn={m.turn} tk={tokens} t={t} time={m.time} onJump={onJump} />
: <LeadCard key={m.id} turn={m.turn} tk={tokens} t={t} time={m.time} onJump={onJump} />;
}
/* 单轮问答:思考过程条 + 规范回答卡(结论/关键数字/明细/依据/行动/来源) */
if (m.role === 'ai' && m.answer) {
return (
<AskAnswerCard
key={m.id} answer={m.answer} elapsed={m.elapsed ?? 0} tk={tokens} t={t} time={m.time} staff={m.staff}
onJump={onJump}
/>
);
}
const consult = m.kind === 'member' || m.kind === 'lead';
const isLead = m.kind === 'lead';
return (
<div key={m.id} className={consult ? 'content-reveal' : undefined} style={{ display: 'flex', justifyContent: m.role === 'user' ? 'flex-end' : 'flex-start', marginBottom: 8 }}>
<div style={{ maxWidth: consult ? '90%' : '76%', minWidth: 0 }}>
{consult && (
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 3 }}>
<span style={{
width: 18, height: 18, borderRadius: 6, display: 'grid', placeItems: 'center', flexShrink: 0,
background: isLead ? `linear-gradient(135deg, ${tokens.accent}, ${tokens.info})` : tokens.cardBg,
border: `1px solid ${isLead ? 'transparent' : tokens.border}`,
}}>
<User size={11} color={isLead ? tokens.onAccent : tokens.accent} />
</span>
<span style={{ fontSize: 12.5, fontWeight: 700, color: isLead ? tokens.accent : tokens.text, flexShrink: 0 }}>{m.name}</span>
{m.tag && (
<span style={{ fontSize: 10.5, color: tokens.textMuted, padding: '0 6px', borderRadius: 7, border: `1px solid ${tokens.border}`, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', maxWidth: 160 }}>{m.tag}</span>
)}
{isLead && <Sparkles size={11} color={tokens.accent} style={{ flexShrink: 0 }} />}
</div>
)}
<div style={{
padding: '8px 12px', fontSize: 13.5, lineHeight: 1.65, whiteSpace: 'pre-wrap',
borderRadius: m.role === 'user' ? '10px 10px 3px 10px' : '10px 10px 10px 3px',
background: m.role === 'user' ? `${tokens.accent}22` : isLead ? tokens.accentBg : tokens.cardBg,
border: `1px solid ${m.role === 'user' ? `${tokens.accent}44` : isLead ? tokens.borderAccent : tokens.border}`,
color: m.role === 'user' ? tokens.text : tokens.textSub,
boxShadow: isLead ? `0 0 0 1px ${tokens.accent}1f` : 'none',
}}>{m.text}</div>
<div style={{ display: 'flex', gap: 6, marginTop: 3, justifyContent: m.role === 'user' ? 'flex-end' : 'flex-start' }}>
{m.staff && (
<span style={{ color: m.role === 'user' ? tokens.textMuted : tokens.accent, fontSize: 11, display: 'flex', alignItems: 'center', gap: 3 }}>
{m.role === 'ai' && <Sparkles size={10} />}{m.staff}
</span>
)}
<span style={{ color: tokens.textMuted, fontSize: 11, fontVariantNumeric: 'tabular-nums' }}>{m.time}</span>
</div>
</div>
</div>
);
})}
{/* 会诊流式:就位播报逐字打出 → 成员卡/牵头卡逐块铺开 */}
{pendingTurn && pendingTurn.turn.kind === 'system' && (() => {
const full = pendingTurn.turn.text ?? '';
const shown = full.slice(0, pendingTurn.typed);
return (
<div data-role="consult-card" className="content-reveal" style={{ display: 'flex', justifyContent: 'center', marginBottom: 8 }}>
<div style={{
maxWidth: '94%', padding: '7px 12px', borderRadius: 10, whiteSpace: 'pre-wrap', textAlign: 'center',
background: tokens.accentBg, border: `1px dashed ${tokens.borderAccent}`,
color: tokens.textSub, fontSize: 12.5, lineHeight: 1.6,
}}>
<span style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 5, color: tokens.accent, fontWeight: 700, marginBottom: 3 }}>
<Radio size={11} />{pendingTurn.turn.name} · {pendingTurn.turn.tag}
</span>
{shown}{pendingTurn.typed < full.length && <span className="stream-caret" />}
</div>
</div>
);
})()}
{pendingTurn && pendingTurn.turn.kind === 'member' && (
<MemberCard
turn={pendingTurn.turn} tk={tokens} t={t} time={clock()} onJump={onJump} stream={pendingTurn}
/>
)}
{pendingTurn && pendingTurn.turn.kind === 'lead' && (
<LeadCard
turn={pendingTurn.turn} tk={tokens} t={t} time={clock()} onJump={onJump} stream={pendingTurn}
/>
)}
{/* 流式推演:思考轨逐条揭示 → 结论打字 → 正文分段亮出;可一键跳过 */}
{pending && (
<AskAnswerCard
answer={pending.answer}
elapsed={(performance.now() - pending.started) / 1000}
tk={tokens} t={t} time={clock()} staff={pending.staff}
onJump={onJump}
streaming={{
revealedSteps: pending.revealed, phase: pending.phase,
sections: pending.sections, typed: pending.typed, items: pending.items,
}}
onSkip={skip}
/>
)}
{thinking && (
<div style={{ display: 'flex', alignItems: 'center', gap: 7, padding: '6px 10px', background: tokens.cardBg, border: `1px solid ${tokens.border}`, borderRadius: 10, width: 'fit-content' }}>
<span style={{ display: 'flex', gap: 3 }}>
{[0, 1, 2].map(i => <i key={i} className="typing-dot" style={{ animationDelay: `${i * 0.16}s` }} />)}
</span>
<span style={{ color: tokens.textMuted, fontSize: 12 }}>{thinkingName ? `${thinkingName}${t.agent.thinking}` : t.agent.thinking}…</span>
</div>
)}
</div>
<div style={{ display: 'flex', gap: 6, padding: '0 14px 6px', flexWrap: 'wrap', flexShrink: 0 }}>
{SUGGESTED.map(q => (
<button key={q} onClick={() => ask(q)} disabled={busy} className="ghost-btn" style={{
color: busy ? tokens.textMuted : tokens.textSub, fontSize: 12, border: `1px solid ${tokens.border}`, background: tokens.cardBg,
borderRadius: 20, padding: '4px 11px', cursor: busy ? 'default' : 'pointer', whiteSpace: 'nowrap',
opacity: busy ? 0.55 : 1,
}}>{q}</button>
))}
</div>
</>
)}
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '0 14px 10px', flexShrink: 0 }}>
<Layers size={14} color={tokens.textMuted} style={{ flexShrink: 0 }} />
<input
value={draft}
onChange={e => setDraft(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') ask(draft); }}
onFocus={() => { if (!expanded) onToggle(); }}
placeholder={t.agent.placeholder}
style={{
flex: 1, minWidth: 0, background: tokens.cardBg, border: `1px solid ${tokens.border}`,
borderRadius: 10, padding: '8px 12px', color: tokens.text, fontSize: 13.5, outline: 'none',
}}
/>
<button
onClick={() => ask(draft)}
disabled={!draft.trim() || busy}
style={{
display: 'flex', alignItems: 'center', gap: 5, padding: '7px 14px', borderRadius: 10,
/* 禁用态原本用 tokens.border(浅色下≈16% 淡蓝)当底色配白字,实测只有 1.37:1,
「发送」两字在浅底上几乎看不见。改成淡底 + 次级文字色,既保留「不可点」的观感,
又把标签对比度抬到 AA 以上。 */
background: !draft.trim() || busy ? tokens.accentBg : tokens.accent,
border: `1px solid ${!draft.trim() || busy ? tokens.border : 'transparent'}`,
color: !draft.trim() || busy ? tokens.textMuted : tokens.onAccent,
fontSize: 13, fontWeight: 700,
cursor: !draft.trim() || busy ? 'default' : 'pointer', transition: 'background 0.18s ease', flexShrink: 0,
}}
>
<Send size={13} />{t.agent.send}
</button>
</div>
</div>
);
}
@@ -1,42 +0,0 @@
import { useMemo, useState } from 'react';
import { Workflow } from 'lucide-react';
import PanelShell, { CountBadge } from './layout/PanelShell';
import { AutoScrollProvider, AutoScrollToggle } from './layout/AutoScroll';
import QualityFlowPanel from './quality/QualityFlowPanel';
import { ROLES } from '../lib/qualityFlow';
interface Props {
expanded: boolean;
onToggle: () => void;
/** 全局时间游标:质量流程与中央看板按同一时点读数 */
period: number;
}
/**
* 左侧工作栏。原先是「销售订单 / 客户资料」两个列表页签那块壳,
* 现在只装质量流程一块内容:弧板与自动滚动开关保留,
* 后续品质域要加页签(异常台账、检验标准库…)时接着往这里挂。
*/
export default function DemandPanel({ expanded, onToggle, period }: Props) {
/* 卡片多到一屏装不下时自动缓慢下滚;标题栏按钮可关闭 */
const [autoScroll, setAutoScroll] = useState(true);
/* 徽标=四段角色的 KPI 总数,与面板内容同源 */
const count = useMemo(() => ROLES.reduce((a, r) => a + r.kpis.length, 0), []);
return (
<PanelShell
side="left" expanded={expanded} onToggle={onToggle}
widthCollapsed={268} widthExpanded={468}
icon={<Workflow size={16} />}
title="质量流程"
badge={<CountBadge n={count} />}
extra={<AutoScrollToggle on={autoScroll} onToggle={() => setAutoScroll(v => !v)} expanded={expanded} />}
animClass="space-animate-left"
>
<AutoScrollProvider value={autoScroll}>
<QualityFlowPanel period={period} expanded={expanded} />
</AutoScrollProvider>
</PanelShell>
);
}
@@ -1,337 +0,0 @@
import { useEffect, useMemo, useState, type MouseEvent } from 'react';
import { ChevronRight, ListTree, Maximize2, Network, Search, Workflow, X } from 'lucide-react';
import PanelShell, { PanelBody, CountBadge } from './layout/PanelShell';
import { useTheme } from '../context/ThemeContext';
import { useText } from '../i18n/useText';
import type { MetricNode } from '../data/sqlite';
import { alertColor, chainOf, execColor, EXEC_RED_LINE, fmt } from '../lib/metric';
import { achieveAt, levelAt, valueAt } from '../lib/time';
import { STAGES } from '../lib/process';
import ProcessFlowPanel from './process/ProcessFlowPanel';
const TreeIcon = ListTree;
interface Props {
expanded: boolean;
onToggle: () => void;
tree: MetricNode[];
flat: MetricNode[];
byCode: Map<string, MetricNode>;
selected: string;
onSelect: (code: string) => void;
/** 左栏两种口径:指标树=结果指标,流程效能=过程指标 */
mode: 'tree' | 'process';
onModeChange: (m: 'tree' | 'process') => void;
/** 指标网络全景:把图谱推到中央工作区 */
onMaximize?: () => void;
/** 全局时间游标:列表里的取值与达成率随时点重算 */
period: number;
}
interface Flat { node: MetricNode; depth: number; hasKids: boolean }
/** 三档视觉权重对应的字号:指标卡(L2)最突出,驱动因子(L3)从属,维度行只作分组标题 */
function typo(level: number) {
if (level === 0) return { name: 16, nameW: 800, val: 20, valW: 800, unit: 11.5, meta: 11.5, gap: 12.5, dot: 8 };
if (level === 1) return { name: 14.5, nameW: 800, val: 15, valW: 800, unit: 10.5, meta: 11.5, gap: 12, dot: 8 };
if (level === 2) return { name: 14.5, nameW: 600, val: 17, valW: 800, unit: 11, meta: 11.5, gap: 12.5, dot: 7 };
return { name: 13, nameW: 500, val: 14.5, valW: 700, unit: 10, meta: 11, gap: 11.5, dot: 6 };
}
export default function MetricTreePanel({
expanded, onToggle, tree, flat, byCode, selected, onSelect, mode, onModeChange, onMaximize, period,
}: Props) {
const { tokens, theme } = useTheme();
const { t } = useText();
const isLight = theme === 'light';
const [query, setQuery] = useState('');
const [collapsed, setCollapsed] = useState<Set<string>>(() => new Set(['D-G', 'D-M', 'D-P', 'D-D', 'D-K']));
// 外部(数字员工 / 中央看板)改变选中项时,自动展开归属链
useEffect(() => {
const chain = chainOf(selected, byCode);
setCollapsed(prev => {
const next = new Set(prev);
chain.forEach(c => next.delete(c));
return next;
});
}, [selected, byCode]);
const name = (n: MetricNode) => (n.name_zh);
const rows = useMemo<Flat[]>(() => {
const q = query.trim().toLowerCase();
const match = (n: MetricNode) =>
name(n).toLowerCase().includes(q)
|| n.code.toLowerCase().includes(q)
|| n.owner.toLowerCase().includes(q);
// 搜索态:命中的节点连同其父链一起保留,keepDepth 记录该节点应处的缩进层级
const keepDepth = new Map<string, number>();
if (q) {
flat.forEach(n => {
if (!match(n)) return;
chainOf(n.code, byCode).forEach((c, i) => {
if (!keepDepth.has(c) || keepDepth.get(c)! > i) keepDepth.set(c, i);
});
});
}
const out: Flat[] = [];
const walk = (nodes: MetricNode[], depth: number) => {
nodes.forEach(n => {
const kids = n.children ?? [];
if (!q) {
out.push({ node: n, depth, hasKids: kids.length > 0 });
if (kids.length && !collapsed.has(n.code)) walk(kids, depth + 1);
} else if (keepDepth.has(n.code)) {
out.push({ node: n, depth: keepDepth.get(n.code)!, hasKids: false });
walk(kids, depth + 1);
}
});
};
walk(tree, 0);
return out.slice(0, 160);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tree, flat, byCode, collapsed, query]);
const toggleNode = (code: string) => {
setCollapsed(prev => {
const next = new Set(prev);
if (next.has(code)) next.delete(code); else next.add(code);
return next;
});
};
const segBtn = (active: boolean) => ({
display: 'flex' as const, alignItems: 'center' as const, justifyContent: 'center' as const,
gap: 5, flex: 1, minWidth: 0, padding: '5px 8px', borderRadius: 7,
fontSize: 13, fontWeight: 600, cursor: 'pointer', whiteSpace: 'nowrap' as const,
background: active ? tokens.accent : 'transparent',
color: active ? tokens.onAccent : tokens.textMuted,
border: `1px solid ${active ? tokens.accent : tokens.border}`,
});
const isTree = mode === 'tree';
return (
<PanelShell
side="left" expanded={expanded} onToggle={onToggle}
widthCollapsed={268} widthExpanded={468}
icon={isTree ? <TreeIcon size={16} /> : <Workflow size={16} />}
title={isTree ? t.panel.metricTree : t.flow.title}
badge={<CountBadge n={isTree ? flat.length : STAGES.length} />}
animClass="space-animate-left"
/* 指标网络不再占一个页签,改为标题行上的一颗按钮:点了就把图谱送到中央工作区。
两种页签下都保留这颗钮,不让人从流程效能绕路才能回图谱。 */
extra={onMaximize ? (
<button
onClick={onMaximize}
className="ghost-btn"
title={t.net.toStage}
style={{
display: 'flex', alignItems: 'center', gap: 4, flexShrink: 0, cursor: 'pointer',
padding: '3px 8px', borderRadius: 7, fontSize: 12.5, fontWeight: 700,
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
}}
>
<Network size={13} />{/* 收起态只留图标:标题不被挤成一个字 */}
{expanded && t.panel.metricNetwork}
{expanded && <Maximize2 size={11} style={{ opacity: 0.75 }} />}
</button>
) : undefined}
tabs={
<>
<button style={segBtn(isTree)} onClick={() => onModeChange('tree')}>{t.panel.metricTree}</button>
<button style={segBtn(!isTree)} onClick={() => onModeChange('process')}>{t.flow.title}</button>
</>
}
>
{isTree ? (
<>
<div style={{ position: 'relative', marginBottom: 10, flex: '0 0 auto' }}>
<Search size={14} style={{ position: 'absolute', left: 10, top: 10, color: tokens.textMuted }} />
<input
value={query}
onChange={e => setQuery(e.target.value)}
placeholder={t.tree.search}
style={{
width: '100%', padding: '8px 30px 8px 31px', fontSize: 13.5, borderRadius: 9,
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`, color: tokens.text,
outline: 'none',
}}
/>
{query && (
<button onClick={() => setQuery('')} style={{ position: 'absolute', right: 9, top: 11, color: tokens.textMuted, cursor: 'pointer' }}>
<X size={14} />
</button>
)}
</div>
{/* 色条语义图例:三档与 execColor / EXEC_RED_LINE 同源,改阈值不会漏改 */}
{expanded && (
<div style={{
display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '4px 11px',
marginBottom: 10, flex: '0 0 auto', fontSize: 11.5, color: tokens.textMuted,
}}>
<span style={{ fontWeight: 700, color: tokens.textSub }}>{t.panel.legendExec}</span>
{[
{ c: tokens.success, k: t.panel.legendOk },
{ c: tokens.warning, k: t.panel.legendWarn },
{ c: tokens.danger, k: t.panel.legendBad.replace('{n}', String(EXEC_RED_LINE)) },
].map(x => (
<span key={x.k} style={{ display: 'inline-flex', alignItems: 'center', gap: 4, whiteSpace: 'nowrap' }}>
<i style={{ display: 'inline-block', width: 14, height: 5, borderRadius: 99, background: x.c }} />{x.k}
</span>
))}
</div>
)}
<PanelBody>
{rows.length === 0 && (
<div style={{ padding: '20px 0', textAlign: 'center', fontSize: 13, color: tokens.textMuted }}>{t.tree.noResult}</div>
)}
{rows.map(({ node: n, depth, hasKids }) => {
const active = selected === n.code;
const c = alertColor(levelAt(n, period), tokens);
const unit = n.unit;
const ty = typo(n.level);
const kind: 'head' | 'card' | 'drive' = n.level <= 1 ? 'head' : n.level === 2 ? 'card' : 'drive';
const rate = achieveAt(n, period); // 游标时点的预算执行率,超额时会大于 100
const rateW = Math.max(0, Math.min(rate, 100)); // 条宽封顶:满格即达标
const ec = execColor(rate, tokens); // 色条与右侧数字同色,成对引导视线
const surface = isLight ? '#ffffff' : tokens.cardBg;
const base = active ? tokens.accentBg
: kind === 'drive' ? tokens.panelBgAlt
: (kind === 'card' || n.level === 0) ? surface
: 'transparent';
const lift = isLight ? '0 1px 3px rgba(30,60,130,0.09), 0 1px 2px rgba(30,60,130,0.05)' : 'none';
const enter = (e: MouseEvent<HTMLDivElement>) => { if (!active) e.currentTarget.style.background = tokens.tableRowHover; };
const leave = (e: MouseEvent<HTMLDivElement>) => { if (!active) e.currentTarget.style.background = base; };
const dot = <span style={{ width: ty.dot, height: ty.dot, borderRadius: 99, background: c, flex: '0 0 auto', boxShadow: `0 0 7px ${c}66` }} />;
const label = (
<div style={{ minWidth: 0, flex: 1 }}>
<div style={{
fontSize: ty.name, fontWeight: ty.nameW, letterSpacing: '0.01em',
color: active ? tokens.accent : kind === 'drive' ? tokens.textSub : tokens.text,
whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
}}>{name(n)}</div>
{expanded && n.level >= 2 && (
<div style={{
fontSize: ty.meta, color: tokens.textMuted, marginTop: 2,
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
}}>{n.code} · {n.owner}</div>
)}
</div>
);
const nums = (
<div style={{ textAlign: 'right', flex: '0 0 auto', minWidth: 66, whiteSpace: 'nowrap' }}>
<div style={{
fontSize: ty.val, fontWeight: ty.valW, color: tokens.text, lineHeight: 1.12,
fontVariantNumeric: 'tabular-nums', letterSpacing: '0.01em',
}}>
{fmt(valueAt(n, period))}
<span style={{ fontSize: ty.unit, fontWeight: 500, color: tokens.textMuted, marginLeft: 3 }}>{unit}</span>
</div>
<div style={{
fontSize: ty.gap, fontWeight: kind === 'drive' ? 600 : 700, color: ec,
fontVariantNumeric: 'tabular-nums', marginTop: 1, letterSpacing: '0.01em',
}}>
{t.detail.reach} {fmt(rate)}%
</div>
</div>
);
/* L2 指标 → 独立指标卡:卡内留白撑开名称与数值,底边一条达成度进度条 */
if (kind === 'card') {
return (
<div
key={n.code} onClick={() => onSelect(n.code)} className="notice-in"
onMouseEnter={enter} onMouseLeave={leave}
style={{
cursor: 'pointer', marginBottom: 5, marginLeft: depth * 11,
padding: '8px 10px 7px', borderRadius: 10, background: base,
border: `1px solid ${active ? tokens.borderAccent : tokens.border}`,
boxShadow: active ? `0 0 0 1px ${tokens.accent}2e, 0 3px 14px rgba(0,0,0,0.2)` : lift,
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
{hasKids && (
<span
onClick={e => { e.stopPropagation(); toggleNode(n.code); }}
style={{ width: 16, flex: '0 0 16px', display: 'flex', alignItems: 'center', color: tokens.textMuted, cursor: 'pointer' }}
>
<ChevronRight size={14} style={{ transform: `rotate(${collapsed.has(n.code) ? 0 : 90}deg)`, transition: 'transform 0.18s' }} />
</span>
)}
{dot}
{label}
{nums}
</div>
<div style={{ marginTop: 8, height: 6, borderRadius: 99, background: tokens.border, overflow: 'hidden' }}>
<div style={{ width: `${rateW}%`, height: '100%', borderRadius: 99, background: ec, boxShadow: `0 0 8px ${ec}59` }} />
</div>
</div>
);
}
/* L3 驱动因子 → 从属子条目:左侧一道状态色连接线,挂在上方指标卡之下 */
if (kind === 'drive') {
return (
<div
key={n.code} onClick={() => onSelect(n.code)} className="notice-in"
onMouseEnter={enter} onMouseLeave={leave}
style={{
display: 'flex', alignItems: 'center', gap: 7, cursor: 'pointer',
marginLeft: depth * 11 + 10, marginBottom: 4, padding: '5px 8px',
borderRadius: 8, background: base,
border: `1px solid ${active ? tokens.borderAccent : tokens.border}`,
}}
>
{dot}
{label}
{nums}
</div>
);
}
/* L0 / L1 → 分组标题行,不参与卡片化,避免 54 行同质方框 */
return (
<div
key={n.code} onClick={() => onSelect(n.code)} className="notice-in"
onMouseEnter={enter} onMouseLeave={leave}
style={{
display: 'flex', alignItems: 'center', gap: 7, cursor: 'pointer',
marginLeft: depth * 11, marginBottom: n.level === 0 ? 9 : 4,
padding: n.level === 0 ? '8px 10px' : '5px 7px', borderRadius: 9,
background: base,
border: `1px solid ${active ? tokens.borderAccent : n.level === 0 ? tokens.border : 'transparent'}`,
}}
>
<span
onClick={e => { e.stopPropagation(); if (hasKids) toggleNode(n.code); }}
style={{
width: 16, flex: '0 0 16px', display: 'flex', alignItems: 'center', justifyContent: 'center',
color: tokens.textMuted, cursor: hasKids ? 'pointer' : 'default',
}}
>
{hasKids && <ChevronRight size={14} style={{ transform: `rotate(${collapsed.has(n.code) ? 0 : 90}deg)`, transition: 'transform 0.18s' }} />}
</span>
{dot}
{label}
{nums}
</div>
);
})}
</PanelBody>
</>
) : (
<ProcessFlowPanel byCode={byCode} selected={selected} onSelect={onSelect} period={period} />
)}
</PanelShell>
);
}
@@ -1,132 +0,0 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { Boxes, Search, Truck, Users, X } from 'lucide-react';
import PanelShell, { CountBadge } from './layout/PanelShell';
import { AutoScrollProvider, AutoScrollToggle } from './layout/AutoScroll';
import { useTheme } from '../context/ThemeContext';
import PurchaseOrderList, { buildPurchaseGroups, filterPurchaseGroups } from './supply/PurchaseOrderList';
import ProductionOrderList, { buildWorkOrders, filterWorkOrders } from './supply/ProductionOrderList';
import SupplierList, { buildSuppliers, filterSuppliers } from './supply/SupplierList';
type TabKey = 'po' | 'wo' | 'sup';
interface Props {
expanded: boolean;
onToggle: () => void;
/** 左栏选中的销售订单号:三个页签各自反查关联单据 */
selectedSO: string | null;
onSelectSO: (so: string | null) => void;
}
const TABS: { key: TabKey; label: string; short: string; icon: typeof Truck; placeholder: string }[] = [
{ key: 'po', label: '采购单', short: '采购', icon: Truck, placeholder: '搜索采购单号 / 供应商 / 材料' },
{ key: 'wo', label: '生产工单', short: '工单', icon: Boxes, placeholder: '搜索工单号 / 来源订单 / 产品编码 / 车间' },
{ key: 'sup', label: '供应商资料', short: '供方', icon: Users, placeholder: '搜索供应商编码 / 简称 / 类别 / 部门' },
];
/**
* 右侧供应与生产执行栏:采购单、生产工单、供应商资料三个页签共用一块弧板,
* 搜索关键词、展开态与左栏订单联动在三者之间保持同一份状态。
*/
export default function SupplyPanel({ expanded, onToggle, selectedSO, onSelectSO }: Props) {
const { tokens } = useTheme();
const [tab, setTab] = useState<TabKey>('po');
/* 外部把订单选中时切回采购单页签:与左栏同一联动理由 */
const prevSO = useRef(selectedSO);
useEffect(() => {
if (selectedSO && selectedSO !== prevSO.current) setTab('po');
prevSO.current = selectedSO;
}, [selectedSO]);
const [query, setQuery] = useState('');
/* 卡片多到一屏装不下时自动缓慢下滚;标题栏按钮可关闭,三个页签共用这一个开关 */
const [autoScroll, setAutoScroll] = useState(true);
/* 徽标数与页签内容走同一组纯函数,标题数字不会和列表条数打架 */
const count = useMemo(() => {
const q = query.trim();
if (tab === 'po') return filterPurchaseGroups(buildPurchaseGroups(selectedSO), q).length;
if (tab === 'wo') return filterWorkOrders(buildWorkOrders(selectedSO), q).length;
return filterSuppliers(buildSuppliers(selectedSO), q).length;
}, [tab, query, selectedSO]);
const segBtn = (active: boolean) => ({
display: 'flex' as const, alignItems: 'center' as const, justifyContent: 'center' as const,
gap: 5, flex: 1, minWidth: 0, padding: '5px 8px', borderRadius: 7,
fontSize: 13, fontWeight: 600, cursor: 'pointer', whiteSpace: 'nowrap' as const,
background: active ? tokens.accent : 'transparent',
color: active ? tokens.onAccent : tokens.textMuted,
border: `1px solid ${active ? tokens.accent : tokens.border}`,
});
const current = TABS.find(x => x.key === tab)!;
const Icon = current.icon;
return (
<PanelShell
side="right" expanded={expanded} onToggle={onToggle}
widthCollapsed={268} widthExpanded={468}
icon={<Icon size={16} />}
title={current.label}
badge={<CountBadge n={count} />}
extra={<AutoScrollToggle on={autoScroll} onToggle={() => setAutoScroll(v => !v)} expanded={expanded} />}
animClass="space-animate-right"
tabs={
<>
{TABS.map(x => (
/* 收起态宽度只够两个字:页签用短标签,避免挤成一列竖排 */
<button key={x.key} style={segBtn(tab === x.key)} onClick={() => setTab(x.key)}>
{expanded ? x.label : x.short}
</button>
))}
</>
}
>
{/* 搜索:三个页签共用,占位提示随页签切换 */}
<div style={{ position: 'relative', marginBottom: 10, flex: '0 0 auto' }}>
<Search size={14} style={{ position: 'absolute', left: 10, top: 10, color: tokens.textMuted }} />
<input
value={query}
onChange={e => setQuery(e.target.value)}
placeholder={current.placeholder}
style={{
width: '100%', padding: '8px 30px 8px 31px', fontSize: 13.5, borderRadius: 9,
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`, color: tokens.text,
outline: 'none',
}}
/>
{query && (
<button onClick={() => setQuery('')} style={{ position: 'absolute', right: 9, top: 11, color: tokens.textMuted, cursor: 'pointer', background: 'none', border: 'none' }}>
<X size={14} />
</button>
)}
</div>
<AutoScrollProvider value={autoScroll}>
{tab === 'po' && (
<PurchaseOrderList
query={query}
filterSO={selectedSO}
onClearFilter={() => onSelectSO(null)}
/>
)}
{tab === 'wo' && (
<ProductionOrderList
query={query}
filterSO={selectedSO}
onClearFilter={() => onSelectSO(null)}
selectedSO={selectedSO}
onSelectSO={onSelectSO}
/>
)}
{tab === 'sup' && (
<SupplierList
query={query}
filterSO={selectedSO}
onClearFilter={() => onSelectSO(null)}
/* 点供应商=带着它的编码跳到采购单页签,只看这家下的单 */
onPickSupplier={code => { setQuery(code); setTab('po'); }}
/>
)}
</AutoScrollProvider>
</PanelShell>
);
}
@@ -1,412 +0,0 @@
import { useMemo, useState } from 'react';
import type { ReactNode } from 'react';
import {
BookOpen, Boxes, BrainCircuit, ChevronsRight, ChevronRight, CircleAlert, Database,
FlaskConical, Gauge, LayoutGrid, Lightbulb, ListChecks, MessageCircle, Sparkles, Table2,
} from 'lucide-react';
import type { ThemeTokens } from '../../context/ThemeContext';
import type { I18n } from '../../i18n/locales';
import type { AskAnswer, AskJump, AskStep, AskTone } from '../../lib/qualityAsk';
/**
* 质量问答回答卡:思考过程(逐条揭示,揭示完折叠成一行复查)+ 六段式正文
* 结论 / 关键数字 / 质量明细 / 依据与口径 / 建议动作(可跳转)/ 数据来源。
* 只负责渲染,所有数字与文案由 lib/qualityAsk.ts 从 17 张源表与本体规则现算。
*
* 流式:pending 时父级给 `reveal={ sections, typed }`,卡片按段亮出正文、
* 结论按打字机逐字出现;落卡后不传 reveal,整张卡全量渲染。
*/
const toneColor = (tone: AskTone | undefined, tk: ThemeTokens) =>
tone === 'danger' ? tk.danger
: tone === 'warning' ? tk.warning
: tone === 'success' ? tk.success
: tone === 'info' ? tk.info
: tk.accent;
/** 小节标题:细线 + 图标 + 文案,让六段结构一眼可辨 */
function SecHead({ icon, text, tk, hint }: { icon: ReactNode; text: string; tk: ThemeTokens; hint?: string }) {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 5, marginBottom: 1 }}>
{icon}
<span style={{ fontSize: 10.5, fontWeight: 700, letterSpacing: '0.06em', color: tk.textMuted }}>{text}</span>
{hint && <span style={{ fontSize: 10.5, color: tk.textMuted, opacity: 0.8 }}>· {hint}</span>}
<span style={{ flex: 1, height: 1, background: tk.borderSub }} />
</div>
);
}
/** 打字点:思考进行中用,揭示一条停一条 */
function Dots({ tk }: { tk: ThemeTokens }) {
return (
<span style={{ display: 'flex', gap: 3, alignItems: 'center' }}>
{[0, 1, 2].map(i => (
<i key={i} className="typing-dot" style={{ animationDelay: `${i * 0.16}s`, background: tk.accent }} />
))}
</span>
);
}
/**
* 思考过程轨:running 时逐条出现(由父级推进 revealed),出答案后折叠成
* 「思考过程 · 6 步 · 耗时 2.8s」一行,点开可复查每一步做了什么、依据哪张表。
*/
export function StepTrace({
steps, revealed, running, elapsed, tk, t,
}: {
steps: AskStep[]; revealed: number; running: boolean; elapsed?: number; tk: ThemeTokens; t: I18n;
}) {
const [open, setOpen] = useState(running);
const shown = steps.slice(0, Math.max(0, revealed));
const label = t.agent.thinkSteps.replace('{n}', String(steps.length));
const time = elapsed !== undefined ? t.agent.thinkElapsed.replace('{s}', elapsed.toFixed(1)) : t.agent.thinkHint;
return (
<div style={{
border: `1px ${running ? 'solid' : 'dashed'} ${tk.borderAccent}`, borderRadius: 10,
background: running ? tk.accentBg : tk.cardBg, overflow: 'hidden',
}}>
<button
onClick={() => setOpen(v => !v)}
aria-expanded={open}
data-role="think-toggle"
style={{
display: 'flex', alignItems: 'center', gap: 6, width: '100%', cursor: 'pointer',
padding: '5px 9px', border: 'none', background: 'transparent', textAlign: 'left',
}}
>
<BrainCircuit size={12} color={tk.accent} style={{ flexShrink: 0 }} />
<span style={{ fontSize: 11.5, fontWeight: 700, color: tk.accent, flexShrink: 0 }}>{t.agent.thinkTitle}</span>
<span style={{ fontSize: 11, color: tk.textMuted, fontVariantNumeric: 'tabular-nums' }}>{label} · {time}</span>
<span style={{ flex: 1 }} />
{running && <Dots tk={tk} />}
<ChevronRight size={12} color={tk.textMuted} style={{ flexShrink: 0, transform: open ? 'rotate(90deg)' : undefined, transition: 'transform 0.18s ease' }} />
</button>
{open && (
<div style={{ padding: '2px 9px 8px', display: 'flex', flexDirection: 'column', gap: 5 }}>
{shown.map((s, i) => (
<div key={i} data-role="think-step" className="content-reveal" style={{ display: 'flex', gap: 7, alignItems: 'flex-start' }}>
<span style={{
flex: '0 0 15px', width: 15, height: 15, borderRadius: 5, display: 'grid', placeItems: 'center', marginTop: 1,
fontSize: 10, fontWeight: 700, fontVariantNumeric: 'tabular-nums',
color: tk.onAccent, background: tk.accent,
}}>{i + 1}</span>
<span style={{ minWidth: 0, fontSize: 11.5, lineHeight: 1.55 }}>
<span style={{ color: tk.text, fontWeight: 700 }}>{s.act}</span>
<span style={{ color: tk.textMuted }}> · {s.detail}</span>
</span>
</div>
))}
{running && revealed < steps.length && (
<div style={{ display: 'flex', alignItems: 'center', gap: 7, fontSize: 11.5, color: tk.textMuted }}>
<Dots tk={tk} />
{steps[revealed]?.act ?? t.agent.thinkHint}
</div>
)}
</div>
)}
</div>
);
}
/** 跳转目的地的图标与 data-role(供核验脚本点击) */
const JUMP_META: Record<AskJump['kind'], { icon: ReactNode; role: string }> = {
metric: { icon: <Gauge size={11} />, role: 'jump-metric' },
tab: { icon: <LayoutGrid size={11} />, role: 'jump-tab' },
ontology: { icon: <Boxes size={11} />, role: 'jump-ontology' },
dataset: { icon: <Database size={11} />, role: 'jump-dataset' },
knowledge: { icon: <BookOpen size={11} />, role: 'jump-knowledge' },
feature: { icon: <FlaskConical size={11} />, role: 'jump-feature' },
ask: { icon: <MessageCircle size={11} />, role: 'jump-ask' },
};
export function JumpButton({ jump, label, tk, onJump, block }: {
jump: AskJump; label: string; tk: ThemeTokens; onJump: (j: AskJump) => void; block?: boolean;
}) {
const meta = JUMP_META[jump.kind];
return (
<button
onClick={() => onJump(jump)}
data-role={meta.role}
data-jump={block ? JSON.stringify(jump) : undefined}
className="ghost-btn"
title={t_jumpTitle(jump)}
style={{
display: 'flex', alignItems: 'center', gap: 4, fontSize: 11.5, fontWeight: 600, cursor: 'pointer',
color: tk.accent, background: tk.accentBg, border: `1px solid ${tk.borderAccent}`,
borderRadius: 8, padding: '3px 10px', whiteSpace: 'nowrap',
}}
>
{meta.icon}{label}
</button>
);
}
/** title 提示:告诉用户点下去会走到哪一眼数据 */
function t_jumpTitle(j: AskJump): string {
switch (j.kind) {
case 'metric': return `在「指标明细」打开口径 ${j.code}`;
case 'tab': return '切换中央工作区页签';
case 'ontology': return '打开业务本体';
case 'dataset': return `回数据集总览对账 ${j.id}`;
case 'knowledge': return `打开知识库 ${j.role} · ${j.chunkId}`;
case 'feature': return `打开工艺建模 ${j.objKey}${j.instanceId ? ` · ${j.instanceId}` : ''}`;
case 'ask': return '把这个问题再抛回对话区';
}
}
interface CardProps {
answer: AskAnswer;
elapsed: number;
tk: ThemeTokens;
t: I18n;
time: string;
/** 应答归属(卡头小字:由哪位质量专家作答) */
staff?: string;
onJump: (j: AskJump) => void;
/**
* 流式推演中:思考轨按 revealedSteps 揭示;phase 转 body 后正文按 sections 分段亮出、
* 结论按 typed 逐字打出。不传就是已落卡的完整回答。
*/
streaming?: { revealedSteps: number; phase: 'think' | 'body'; sections: number; typed: number; items: number };
/** 「跳过推演」:直接落成完整卡 */
onSkip?: () => void;
}
export default function AskAnswerCard({ answer, elapsed, tk, t, time, staff, onJump, streaming, onSkip }: CardProps) {
const sev = toneColor(answer.severity, tk);
const tone = (x?: AskTone) => toneColor(x, tk);
const inBody = !!streaming && streaming.phase === 'body';
/* 正文按段构建:与 hooks/useAgentChat 的 sectionPlan 同一套"有没有内容"判断,
顺序也必须一致(结论 → 关键数字 → 明细 → 依据 → 动作 → 来源),否则流式会跳段。
每段是一个 render(limit):流式时只铺到 limit 条,数字/表格行/依据/动作逐条出现。 */
const parts = useMemo(() => {
const out: { key: string; count: number; node: (limit: number) => ReactNode }[] = [];
out.push({
key: 'conclusion', count: 1,
node: () => (
<div style={{ display: 'flex', gap: 7, alignItems: 'flex-start' }}>
<CircleAlert size={13} color={sev} style={{ flexShrink: 0, marginTop: 2 }} />
<span style={{ fontSize: 13, fontWeight: 700, lineHeight: 1.65, color: tk.text, minWidth: 0 }}>
{answer.conclusion}
</span>
</div>
),
});
if (answer.metrics.length) {
out.push({
key: 'numbers', count: answer.metrics.length,
node: (limit) => (
<div>
<SecHead icon={<ListChecks size={11} color={tk.textMuted} />} text={t.agent.secNumbers} tk={tk} />
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginTop: 4 }}>
{answer.metrics.slice(0, limit).map((m, i) => {
const c = tone(m.tone);
return (
<span key={i} className="content-reveal" style={{
display: 'flex', alignItems: 'baseline', gap: 5, padding: '3px 9px', borderRadius: 8,
background: tk.panelBgAlt, border: `1px solid ${tk.borderSub}`,
}}>
<span style={{ fontSize: 11, color: tk.textMuted, whiteSpace: 'nowrap' }}>{m.label}</span>
<span style={{ fontSize: 13, fontWeight: 800, color: c, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace' }}>{m.value}</span>
</span>
);
})}
</div>
</div>
),
});
}
if (answer.table) {
const tbl = answer.table;
out.push({
key: 'table', count: tbl.rows.length,
node: (limit) => (
<div>
<SecHead icon={<Table2 size={11} color={tk.textMuted} />} text={t.agent.secTable} tk={tk} hint={`${Math.min(limit, tbl.rows.length)} 行`} />
<div style={{ marginTop: 4, overflowX: 'auto', border: `1px solid ${tk.borderSub}`, borderRadius: 9 }}>
<table style={{ borderCollapse: 'collapse', width: '100%', fontSize: 11.5, whiteSpace: 'nowrap' }}>
<thead>
<tr style={{ background: tk.panelBgAlt }}>
{tbl.cols.map((c, i) => (
<th key={i} style={{
textAlign: 'left', fontWeight: 700, color: tk.textMuted, padding: '5px 8px',
borderBottom: `1px solid ${tk.border}`, fontSize: 10.5, letterSpacing: '0.04em',
}}>{c}</th>
))}
</tr>
</thead>
<tbody>
{tbl.rows.slice(0, limit).map((r, ri) => {
const c = tone(r.tone);
return (
<tr key={ri} className="content-reveal" style={{ background: r.tone ? `${c}0d` : undefined, borderBottom: ri < tbl.rows.length - 1 ? `1px solid ${tk.borderSub}` : undefined }}>
{r.cells.map((cell, ci) => (
<td key={ci} style={{
padding: '4px 8px',
color: ci === 0 ? (r.tone ? c : tk.text) : tk.textSub,
fontWeight: ci === 0 ? 700 : 400,
fontVariantNumeric: 'tabular-nums',
fontFamily: ci === 0 ? undefined : 'ui-monospace, monospace',
}}>{cell}</td>
))}
</tr>
);
})}
</tbody>
</table>
</div>
</div>
),
});
}
if (answer.points.length) {
out.push({
key: 'basis', count: answer.points.length,
node: (limit) => (
<div>
<SecHead icon={<BrainCircuit size={11} color={tk.textMuted} />} text={t.agent.secBasis} tk={tk} />
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, marginTop: 4 }}>
{answer.points.slice(0, limit).map((p, i) => {
const c = tone(p.tone);
return (
<div key={i} className="content-reveal" style={{ display: 'flex', gap: 7, alignItems: 'flex-start' }}>
<span style={{
flex: '0 0 auto', fontSize: 10.5, fontWeight: 700, marginTop: 1, padding: '1px 6px', borderRadius: 6,
color: p.tone ? c : tk.textMuted,
background: p.tone ? `${c}14` : tk.panelBgAlt,
border: `1px solid ${p.tone ? `${c}33` : tk.border}`,
whiteSpace: 'nowrap', maxWidth: 130, overflow: 'hidden', textOverflow: 'ellipsis',
}}>{p.label}</span>
<span style={{ fontSize: 12, lineHeight: 1.6, color: tk.textSub, minWidth: 0 }}>{p.text}</span>
</div>
);
})}
</div>
</div>
),
});
}
if (answer.actions.length) {
out.push({
key: 'actions', count: answer.actions.length,
node: (limit) => (
<div>
<SecHead
icon={<Lightbulb size={11} color={tk.textMuted} />} text={t.agent.secActions} tk={tk}
hint={t.agent.jumpHint}
/>
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginTop: 4 }}>
{answer.actions.slice(0, limit).map((a, i) => (
<span key={i} className="content-reveal" style={{ display: 'inline-flex' }}>
<JumpButton jump={a.jump} label={a.label} tk={tk} onJump={onJump} block />
</span>
))}
</div>
</div>
),
});
}
out.push({
key: 'source', count: 1,
node: () => (
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 5, paddingTop: 3, borderTop: `1px dashed ${tk.borderSub}` }}>
<Database size={10} color={tk.textMuted} style={{ flexShrink: 0, marginTop: 2 }} />
<span style={{ fontSize: 10.5, color: tk.textMuted, minWidth: 0, lineHeight: 1.55 }}>
<span style={{ fontWeight: 700 }}>{t.agent.secSource}:</span>{answer.source}
</span>
</div>
),
});
return out;
}, [answer, onJump, sev, t, tk]);
const shownParts = inBody ? parts.slice(0, Math.max(1, streaming!.sections)) : parts;
const typedText = inBody ? answer.conclusion.slice(0, streaming!.typed) : answer.conclusion;
const typing = inBody && streaming!.typed < answer.conclusion.length;
return (
<div data-role="answer-card" className="content-reveal" style={{ display: 'flex', justifyContent: 'flex-start', marginBottom: 8 }}>
<div style={{ maxWidth: '96%', minWidth: 0, display: 'flex', flexDirection: 'column', gap: 6 }}>
{/* 卡头:智能体名 + 识别到的意图 + 应答归属 + 时间 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<span style={{
width: 18, height: 18, borderRadius: 6, display: 'grid', placeItems: 'center', flexShrink: 0,
background: `linear-gradient(135deg, ${tk.accent}, ${tk.info})`,
}}>
<Sparkles size={11} color={tk.onAccent} />
</span>
<span style={{ fontSize: 12.5, fontWeight: 700, color: tk.accent, flexShrink: 0 }}>{t.agent.aiName}</span>
<span style={{
fontSize: 10.5, color: tk.textMuted, padding: '0 6px', borderRadius: 7,
border: `1px solid ${tk.border}`, background: tk.cardBg, whiteSpace: 'nowrap',
}}>{t.agent.secIntent}:{answer.intent}</span>
{staff && (
<span style={{ fontSize: 10.5, color: tk.textMuted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 }}>{staff}</span>
)}
<span style={{ marginLeft: 'auto', color: tk.textMuted, fontSize: 10.5, fontVariantNumeric: 'tabular-nums', flexShrink: 0 }}>{time}</span>
</div>
{/* 思考轨:推演中逐条展开,落卡后折叠成一行供复查 */}
<StepTrace
steps={answer.steps}
revealed={streaming ? streaming.revealedSteps : answer.steps.length}
running={!!streaming}
elapsed={streaming ? undefined : elapsed}
tk={tk} t={t}
/>
<div style={{
background: tk.cardBg, border: `1px solid ${tk.border}`, borderLeft: `3px solid ${sev}`,
borderRadius: '4px 12px 12px 12px', padding: '9px 12px',
display: 'flex', flexDirection: 'column', gap: 9, minWidth: 0,
}}>
{/* 思考阶段:正文还没开始写,只给一行"正在取数"的占位,不摆假数字 */}
{streaming && !inBody && (
<div style={{ display: 'flex', alignItems: 'center', gap: 7, fontSize: 12, color: tk.textMuted }}>
<Dots tk={tk} />
{answer.steps[Math.min(streaming.revealedSteps, answer.steps.length - 1)]?.act ?? t.agent.thinkHint}
· {t.agent.thinkHint}
</div>
)}
{inBody && (
<>
<div style={{ display: 'flex', gap: 7, alignItems: 'flex-start' }}>
<CircleAlert size={13} color={sev} style={{ flexShrink: 0, marginTop: 2 }} />
<span style={{ fontSize: 13, fontWeight: 700, lineHeight: 1.65, color: tk.text, minWidth: 0 }}>
{typedText}
{typing && <span style={{ color: tk.accent }}>▍</span>}
</span>
</div>
{shownParts.slice(1).map((p, idx) => {
/* 只有最后一段还在「写」:按 items 逐条铺;之前的段已经铺满 */
const top = idx + 1 === shownParts.length - 1;
const limit = top ? Math.max(0, Math.min(p.count, streaming!.items)) : p.count;
return <div key={p.key} className="content-reveal">{p.node(limit)}</div>;
})}
</>
)}
{!streaming && parts.map(p => <div key={p.key}>{p.node(p.count)}</div>)}
{/* 推演进行中:给一个「跳过推演」,不想等的用户一键落到完整卡 */}
{streaming && onSkip && (
<button
onClick={onSkip}
data-role="skip-reasoning"
className="ghost-btn"
style={{
alignSelf: 'flex-start', display: 'flex', alignItems: 'center', gap: 4, cursor: 'pointer',
fontSize: 11.5, fontWeight: 700, color: tk.textMuted,
background: tk.panelBgAlt, border: `1px solid ${tk.border}`, borderRadius: 8, padding: '3px 10px',
}}
>
<ChevronsRight size={11} />{t.agent.skip}
</button>
)}
</div>
</div>
</div>
);
}
@@ -1,152 +0,0 @@
import { useMemo, useState } from 'react';
import { Check, Sparkles, Users } from 'lucide-react';
import type { ThemeTokens } from '../../context/ThemeContext';
import type { I18n } from '../../i18n/locales';
import { customTeam, presetTeams, qualityExperts } from '../../lib/teams';
import type { ExpertTeam, TeamTone } from '../../lib/teams';
/**
* 专家团召集面板:从对话区头部弹出,选一个预设质量专家团或自己勾几位质量专家发起会诊。
* 只做"选人 + 开会"这一件事,会诊内容与播放时序都在 lib/teams.ts 与 AgentDock 里。
*/
interface Props {
tk: ThemeTokens;
t: I18n;
onConvene: (team: ExpertTeam) => void;
onClose: () => void;
}
const toneColor = (tone: TeamTone, tk: ThemeTokens) =>
tone === 'danger' ? tk.danger : tone === 'warning' ? tk.warning
: tone === 'success' ? tk.success : tone === 'info' ? tk.info : tk.accent;
export default function TeamPicker({ tk, t, onConvene, onClose }: Props) {
const presets = useMemo(() => presetTeams(), []);
const experts = useMemo(() => qualityExperts(), []);
const [sel, setSel] = useState<string[]>([]);
const toggle = (code: string) => setSel(prev => (prev.includes(code) ? prev.filter(c => c !== code) : [...prev, code]));
const custom = sel.length >= 2 ? customTeam(sel) : null;
const nameOf = (code: string) => experts.find(e => e.code === code)?.name ?? code;
return (
<div
data-role="team-picker"
className="space-scroll"
style={{
position: 'absolute', right: 14, top: 42, zIndex: 8, width: 396, maxWidth: 'calc(100% - 28px)',
maxHeight: 'calc(100% - 48px)', overflowY: 'auto', overscrollBehavior: 'contain',
background: tk.panelBg, border: `1px solid ${tk.borderAccent}`, borderRadius: 12,
boxShadow: `0 12px 32px rgba(0,0,0,.28)`, padding: 10, display: 'flex', flexDirection: 'column', gap: 8,
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<Users size={13} color={tk.accent} />
<span style={{ fontSize: 12.5, fontWeight: 800, color: tk.text }}>{t.team.panel}</span>
<span style={{ flex: 1 }} />
<button
onClick={onClose}
className="ghost-btn"
style={{ fontSize: 11.5, color: tk.textMuted, border: 'none', background: 'transparent', cursor: 'pointer' }}
>{t.common.close}</button>
</div>
<div style={{ fontSize: 11.5, color: tk.textMuted, lineHeight: 1.55 }}>{t.team.presetHint}</div>
{/* 预设团:一键就位 */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
{presets.map(p => {
const c = toneColor(p.tone, tk);
return (
<button
key={p.id}
data-role={`team-${p.id}`}
onClick={() => onConvene(p)}
className="ghost-btn"
style={{
textAlign: 'left', cursor: 'pointer', padding: '7px 9px', borderRadius: 10,
background: tk.cardBg, border: `1px solid ${tk.border}`,
display: 'flex', flexDirection: 'column', gap: 3,
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<span style={{ width: 6, height: 6, borderRadius: '50%', background: c, flexShrink: 0 }} />
<span style={{ fontSize: 12.5, fontWeight: 800, color: tk.text }}>{p.nameZh}</span>
<span style={{ fontSize: 11, color: c, background: `${c}14`, border: `1px solid ${c}33`, borderRadius: 6, padding: '0 6px', whiteSpace: 'nowrap' }}>
{p.memberCodes.length} 位
</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 11, color: tk.accent, fontWeight: 700, display: 'flex', alignItems: 'center', gap: 3 }}>
<Sparkles size={10} />{t.team.convene}
</span>
</div>
<span style={{ fontSize: 11.5, color: tk.textSub }}>{p.topicZh}</span>
<span style={{ fontSize: 11, color: tk.textMuted, lineHeight: 1.5 }}>{p.brief}</span>
<span style={{ fontSize: 10.5, color: tk.textMuted }}>
{t.team.lead}:{nameOf(p.leadCode)} · {t.team.member}:{p.memberCodes.filter(c2 => c2 !== p.leadCode).map(nameOf).join('、')}
</span>
</button>
);
})}
</div>
{/* 自建团:勾选专家,首位为牵头 */}
<div style={{ borderTop: `1px dashed ${tk.borderSub}`, paddingTop: 8 }}>
<div style={{ fontSize: 11.5, fontWeight: 800, color: tk.text, marginBottom: 3 }}>{t.team.customTitle}</div>
<div style={{ fontSize: 11, color: tk.textMuted, marginBottom: 6 }}>{t.team.customHint}</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 5 }}>
{experts.map(e => {
const on = sel.includes(e.code);
const lead = sel[0] === e.code && sel.length >= 2;
return (
<button
key={e.code}
onClick={() => toggle(e.code)}
className="ghost-btn"
title={`${e.role} · ${e.skill}`}
style={{
display: 'flex', alignItems: 'center', gap: 4, cursor: 'pointer',
fontSize: 11.5, fontWeight: on ? 700 : 500,
color: on ? tk.onAccent : tk.textSub,
background: lead ? tk.info : on ? tk.accent : tk.panelBgAlt,
border: `1px solid ${on ? 'transparent' : tk.border}`,
borderRadius: 8, padding: '3px 9px',
}}
>
{on && <Check size={11} />}
{e.name}
{lead && <span style={{ fontSize: 10, opacity: 0.9 }}>牵头</span>}
</button>
);
})}
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 8 }}>
<span style={{ fontSize: 11.5, color: sel.length >= 2 ? tk.textSub : tk.textMuted }}>
{sel.length >= 2 ? `${t.team.selected}:${sel.map(nameOf).join('、')}` : t.team.needTwo}
</span>
<span style={{ flex: 1 }} />
<button
onClick={() => setSel([])}
className="ghost-btn"
style={{ fontSize: 11.5, color: tk.textMuted, border: `1px solid ${tk.border}`, background: 'transparent', borderRadius: 8, padding: '3px 9px', cursor: 'pointer' }}
>{t.team.clearSel}</button>
<button
data-role="team-custom"
disabled={!custom}
onClick={() => custom && onConvene(custom)}
className="ghost-btn"
style={{
fontSize: 11.5, fontWeight: 700, borderRadius: 8, padding: '3px 11px',
cursor: custom ? 'pointer' : 'default',
color: custom ? tk.onAccent : tk.textMuted,
background: custom ? tk.accent : tk.panelBgAlt,
border: `1px solid ${custom ? 'transparent' : tk.border}`,
}}
>
{t.team.conveneN.replace('{n}', String(sel.length))}
</button>
</div>
</div>
</div>
);
}
@@ -1,228 +0,0 @@
import { Fragment, useMemo, useState } from 'react';
import { BellRing, ChevronDown, ChevronRight } from 'lucide-react';
import PanelShell, { CountBadge } from '../layout/PanelShell';
import { AutoScrollProvider, AutoScrollToggle, ScrollList } from '../layout/AutoScroll';
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
import { useText } from '../../i18n/useText';
import {
alertKindLabel, alertSummary, qualityAlertsAt,
type AlertLevel, type QualityAlert,
} from '../../lib/qualityAlerts';
import { CURRENT_PERIOD, periodLabel } from '../../lib/time';
interface Props {
expanded: boolean;
onToggle: () => void;
/** 全局回放游标:告警流与中央六页签同一时点读数 */
period: number;
}
/** 档位色:muted 走中性灰,已闭环的条目不该再占一个告警色 */
function levelColor(lv: AlertLevel, tk: ThemeTokens): string {
if (lv === 'red') return tk.danger;
if (lv === 'orange') return tk.warning;
if (lv === 'blue') return tk.info;
return tk.textMuted;
}
/** 档位底色(很淡的一层,只给角标和分带线用) */
function levelBg(lv: AlertLevel, tk: ThemeTokens): string {
if (lv === 'red') return tk.dangerBg;
if (lv === 'orange') return tk.warningBg;
if (lv === 'blue') return tk.infoBg;
return tk.panelBgAlt;
}
/**
* 右栏「质量告警」:DS-15/DS-16/DS-14/DS-07 四张源表汇成一条按严重度分带的告警流,
* 卡片默认收起,点一下在原处展开该条的原表字段与处置动作(不跳页、不切舞台)。
* 判定与读数全部来自 qualityAlerts(),页面不写死任何统计值。
*/
export default function QualityAlertPanel({ expanded, onToggle, period }: Props) {
const { tokens } = useTheme();
const { t } = useText();
/* 列表多到一屏装不下时缓慢下滚,标题栏按钮可关;和左栏同一套开关语义 */
const [autoScroll, setAutoScroll] = useState(true);
/* 同一时刻只展开一张:滚动的信息流里同时摊开两张就看不出顺序了 */
const [openId, setOpenId] = useState<string | null>(null);
const list = useMemo(() => qualityAlertsAt(period), [period]);
const sum = useMemo(() => alertSummary(list), [list]);
const a = t.alert;
const levelName: Record<AlertLevel, string> = {
red: a.levelRed, orange: a.levelOrange, blue: a.levelBlue, muted: a.levelMuted,
};
const allBands: { lv: AlertLevel; n: number }[] = [
{ lv: 'red', n: sum.red }, { lv: 'orange', n: sum.orange },
{ lv: 'blue', n: sum.blue }, { lv: 'muted', n: sum.muted },
];
/* 计数为 0 的档位不占汇总位,否则「蓝 0」看着像漏采 */
const bands = allBands.filter(x => x.n > 0);
return (
<PanelShell
side="right" expanded={expanded} onToggle={onToggle}
widthCollapsed={268} widthExpanded={468}
icon={<BellRing size={16} />}
title={a.title}
badge={<CountBadge n={sum.total} color={tokens.danger} />}
extra={<AutoScrollToggle on={autoScroll} onToggle={() => setAutoScroll(v => !v)} expanded={expanded} />}
animClass="space-animate-right"
>
{/* 汇总带固定在标题下方,不随列表滚走:滚到哪儿都知道整池是什么结构 */}
<div style={{
flex: '0 0 auto', marginBottom: 8, padding: '7px 9px', borderRadius: 9,
background: tokens.cardBg, border: `1px solid ${tokens.border}`,
}}>
<div style={{
display: 'flex', alignItems: 'center', gap: 5, marginBottom: 5,
fontSize: 10.5, color: period === CURRENT_PERIOD ? tokens.textMuted : tokens.warning,
fontVariantNumeric: 'tabular-nums', letterSpacing: '0.02em',
}}>
<span style={{
padding: '1px 5px', borderRadius: 4,
border: `1px solid ${period === CURRENT_PERIOD ? tokens.border : tokens.warning}55`,
background: period === CURRENT_PERIOD ? 'transparent' : tokens.warningBg,
fontWeight: 700,
}}>{period === CURRENT_PERIOD ? '源表当期' : '回放推算'}</span>
<span>{period === CURRENT_PERIOD ? '2026-10 快照' : `${periodLabel(period)} · 缺口明细仍为源表`}</span>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 7, flexWrap: 'wrap' }}>
{bands.map(x => (
<span key={x.lv} style={{ display: 'flex', alignItems: 'center', gap: 3, fontSize: 11, color: tokens.textSub }}>
<span style={{ width: 7, height: 7, borderRadius: '50%', background: levelColor(x.lv, tokens) }} />
<b style={{ color: levelColor(x.lv, tokens), fontVariantNumeric: 'tabular-nums' }}>{x.n}</b>
{levelName[x.lv]}
</span>
))}
</div>
</div>
<AutoScrollProvider value={autoScroll}>
<ScrollList>
{list.length === 0 && (
<div style={{ fontSize: 12, color: tokens.textMuted, padding: '18px 4px', textAlign: 'center' }}>{a.empty}</div>
)}
{list.map((x, i) => {
const prev = list[i - 1];
/* 换档时插一条分带线:滚动流里靠颜色条看不出档位变化 */
return (
<Fragment key={x.id}>
{!prev || prev.level !== x.level ? (
<div data-role={`band-${x.level}`} style={{ display: 'flex', alignItems: 'center', gap: 6, margin: i === 0 ? '0 0 6px' : '10px 0 6px' }}>
<span style={{ fontSize: 10.5, fontWeight: 700, color: levelColor(x.level, tokens), whiteSpace: 'nowrap' }}>
{levelName[x.level]} · {sum[x.level]}
</span>
<span style={{ flex: 1, borderTop: `1px dashed ${tokens.border}` }} />
</div>
) : null}
<AlertCard alert={x} open={openId === x.id} onToggle={() => setOpenId(openId === x.id ? null : x.id)} tk={tokens} />
</Fragment>
);
})}
</ScrollList>
</AutoScrollProvider>
</PanelShell>
);
}
/* ── 单张告警卡 ───────────────────────────────────────────────────────── */
function AlertCard({ alert: x, open, onToggle, tk }: {
alert: QualityAlert; open: boolean; onToggle: () => void; tk: ThemeTokens;
}) {
const { t } = useText();
const a = t.alert;
const c = levelColor(x.level, tk);
return (
<div
data-role={`alert-${x.id}`}
style={{
marginBottom: 6, borderRadius: 10, overflow: 'hidden',
background: tk.cardBg, border: `1px solid ${open ? c : tk.border}`,
boxShadow: open ? `0 0 0 1px ${c}33` : 'none',
}}
>
<button
onClick={onToggle}
aria-expanded={open}
style={{
display: 'block', width: '100%', textAlign: 'left', cursor: 'pointer',
background: 'transparent', border: 0, padding: 0, color: 'inherit', font: 'inherit',
}}
>
{/* 左侧档位条 + 收起态两行 */}
<div style={{ display: 'flex', gap: 7, padding: '7px 9px 7px 0' }}>
<span style={{ width: 3, alignSelf: 'stretch', borderRadius: 2, background: c, flexShrink: 0, marginLeft: 3 }} />
<span style={{ minWidth: 0, flex: 1 }}>
<span style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
<span style={{
fontSize: 10, fontWeight: 700, padding: '0 5px', borderRadius: 5, flexShrink: 0,
color: c, background: levelBg(x.level, tk), border: `1px solid ${c}33`, lineHeight: '15px',
}}>{alertKindLabel(x.kind)}</span>
{/* 两行截断而不是单行省略:收起态宽度下「激光功率 超差(已出允差)」
被截成「激光功率 超差(已…」会把判档依据丢掉 */}
<span style={{
fontSize: 12.5, fontWeight: 600, color: tk.text, minWidth: 0, flex: 1,
display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical',
overflow: 'hidden', lineHeight: 1.35,
}}>{x.title}</span>
{open
? <ChevronDown size={13} color={tk.textMuted} style={{ flexShrink: 0 }} />
: <ChevronRight size={13} color={tk.textMuted} style={{ flexShrink: 0 }} />}
</span>
<span style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 3 }}>
<span style={{
fontSize: 10.5, color: tk.textMuted, minWidth: 0, flex: 1,
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
}}>{x.subject || x.role}</span>
<span style={{ fontSize: 10.5, color: tk.textSub, whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums' }}>
{x.metric.label} <b style={{ color: c, fontWeight: 700 }}>{x.metric.value}</b>
</span>
</span>
</span>
</div>
</button>
{/* 展开态:原表全部字段 + 处置动作 + 判定口径 + 来源,就地给出,不跳转 */}
{open && (
<div data-role={`alert-detail-${x.id}`} style={{ padding: '0 10px 9px 13px', borderTop: `1px dashed ${tk.border}` }}>
<div style={{ display: 'flex', flexDirection: 'column', gap: 3, paddingTop: 7 }}>
{x.fields.map(f => (
<div key={f.label} style={{ display: 'flex', gap: 6, fontSize: 11, lineHeight: 1.5 }}>
{/* 标签列不折行:'标准值 / 允许偏差' 被压成两行时整块明细读起来很碎 */}
<span style={{ color: tk.textMuted, flex: '0 0 auto', minWidth: 62, whiteSpace: 'nowrap' }}>{f.label}</span>
<span style={{ color: tk.text, minWidth: 0, wordBreak: 'break-word' }}>{f.value}</span>
</div>
))}
</div>
<div style={{
marginTop: 7, padding: '6px 8px', borderRadius: 8,
background: tk.accentBg, border: `1px solid ${tk.borderAccent}`,
}}>
<span style={{ fontSize: 10.5, color: tk.textMuted }}>{a.action}</span>
<div style={{ fontSize: 11.5, color: tk.text, lineHeight: 1.55, marginTop: 1 }}>{x.action}</div>
{(x.owner || x.role) && (
<div style={{ fontSize: 10.5, color: tk.textSub, marginTop: 3 }}>
{a.owner}:{x.owner || '—'} · {x.role}
</div>
)}
</div>
<div style={{ marginTop: 6, fontSize: 10.5, color: tk.textMuted, lineHeight: 1.55 }}>
<div>{a.caliber}:{x.caliber}</div>
<div style={{ marginTop: 2, display: 'flex', alignItems: 'center', gap: 4 }}>
<span style={{
fontSize: 10, fontWeight: 700, padding: '0 5px', borderRadius: 5, lineHeight: '15px',
color: tk.accent, background: tk.accentBg, border: `1px solid ${tk.borderAccent}`,
}}>{x.source.ds}</span>
<span>{a.source}:{x.source.table}</span>
</div>
</div>
</div>
)}
</div>
);
}
@@ -1,149 +0,0 @@
import { useMemo } from 'react';
import { Building2, Link2, X } from 'lucide-react';
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
import { customers, salesOrders, type Customer } from '../../data/ibp';
import { ScrollList } from '../supply/PurchaseOrderList';
/**
* 客户资料页签:Excel「客户资料」的 9 个字段全量展示(订单笔数 / 订单金额沿用表内汇总口径)。
* 左栏选中销售订单时,只列出该订单的客户——关联关系由销售订单行反推,不另外造数据。
*/
/** 客户金额是Excel原值(两位小数),此处与供应商资料页签同口径 */
export const money2 = (n: number) => n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
/** 按订单金额从大到小:贡献多的客户先看 */
export function sortCustomers(rows: Customer[]): Customer[] {
return [...rows].sort((a, b) => b.订单金额 - a.订单金额);
}
/** filterSO 非空时用销售订单行反查该订单的客户编码 */
export function buildCustomers(filterSO: string | null): Customer[] {
if (!filterSO) return sortCustomers(customers);
const codes = new Set(salesOrders.filter(s => s.销售订单号 === filterSO).map(s => s.客户编码));
return sortCustomers(customers.filter(c => codes.has(c.客户编码)));
}
/** 编码 / 简称 / 客户分类 / 所属类别 / 分管部门 五向模糊匹配 */
export function filterCustomers(rows: Customer[], query: string): Customer[] {
const q = query.trim().toLowerCase();
if (!q) return rows;
return rows.filter(c =>
c.客户编码.toLowerCase().includes(q)
|| c.客户简称.toLowerCase().includes(q)
|| c.客户分类.toLowerCase().includes(q)
|| c.所属类别.toLowerCase().includes(q)
|| (c.分管部门 ?? '').toLowerCase().includes(q));
}
/** 客商一体(性质=客户/供应商)是治理关注项,单独给色 */
const natureColor = (nature: string, tk: ThemeTokens) =>
nature === '客户/供应商' ? { c: tk.warning, bg: tk.warningBg } : { c: tk.info, bg: tk.infoBg };
interface Props {
query: string;
filterSO: string | null;
onClearFilter: () => void;
/** 点击客户:把客户编码填进搜索框并切回销售订单页签 */
onPickCustomer: (code: string) => void;
}
export default function CustomerList({ query, filterSO, onClearFilter, onPickCustomer }: Props) {
const { tokens } = useTheme();
const list = useMemo(() => filterCustomers(buildCustomers(filterSO), query), [filterSO, query]);
const total = useMemo(() => list.reduce((a, c) => a + c.订单金额, 0), [list]);
const totalOrders = useMemo(() => list.reduce((a, c) => a + c.订单笔数, 0), [list]);
return (
<>
{filterSO && (
<div style={{
display: 'flex', alignItems: 'center', gap: 6, flex: '0 0 auto', marginBottom: 8,
padding: '5px 9px', borderRadius: 8, fontSize: 11.5, fontWeight: 600,
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
}}>
<Link2 size={12} style={{ flexShrink: 0 }} />
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>关联订单 {filterSO} · 仅该单涉及的客户</span>
<span style={{ flex: 1 }} />
<button onClick={onClearFilter} title="显示全部客户" style={{ background: 'none', border: 'none', color: tokens.accent, cursor: 'pointer', display: 'flex', padding: 2 }}>
<X size={13} />
</button>
</div>
)}
{/* 汇总条 */}
<div style={{
display: 'flex', justifyContent: 'space-between', alignItems: 'center', flex: '0 0 auto',
padding: '6px 10px', marginBottom: 10, borderRadius: 8, fontSize: 12,
background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`, color: tokens.textSub,
}}>
<span>{list.length} 家客户 · {totalOrders} 笔订单</span>
<span style={{ color: tokens.accent, fontWeight: 700, fontVariantNumeric: 'tabular-nums' }}>¥{money2(total)}</span>
</div>
<ScrollList>
{list.length === 0 && (
<div style={{ padding: '20px 0', textAlign: 'center', fontSize: 13, color: tokens.textMuted }}>
{filterSO ? '该销售订单暂无匹配客户' : '无匹配客户'}
</div>
)}
{list.map(c => {
const nc = natureColor(c.性质, tokens);
return (
<div
key={c.客户编码}
onClick={() => onPickCustomer(c.客户编码)}
title="点击只看这家客户的销售订单"
style={{
marginBottom: 8, padding: '9px 11px', borderRadius: 9, cursor: 'pointer',
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
transition: 'background .15s, border-color .15s',
}}
>
{/* 行1:简称 + 编码 + 性质 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<Building2 size={12} style={{ color: tokens.textMuted, flexShrink: 0 }} />
<span style={{ fontSize: 13, fontWeight: 700, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{c.客户简称}
</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>{c.客户编码}</span>
<span style={{ flex: 1 }} />
<span style={{
fontSize: 10.5, fontWeight: 600, padding: '1px 7px', borderRadius: 99,
color: nc.c, background: nc.bg, border: `1px solid ${nc.c}44`, whiteSpace: 'nowrap',
}}>{c.性质}</span>
</div>
{/* 行2:客户分类 + 所属类别 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 5 }}>
<span style={{ fontSize: 10.5, color: tokens.textSub, padding: '0 6px', borderRadius: 99, border: `1px solid ${tokens.border}`, whiteSpace: 'nowrap' }}>{c.客户分类}</span>
<span style={{ fontSize: 10.5, color: tokens.textSub, padding: '0 6px', borderRadius: 99, border: `1px solid ${tokens.border}`, whiteSpace: 'nowrap' }}>{c.所属类别}</span>
</div>
{/* 行3:分管部门 + 序号 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 5 }}>
<span style={{ fontSize: 11, color: tokens.textMuted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{c.分管部门 || '分管部门未填'}
</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 10.5, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>序 {c.序号}</span>
</div>
{/* 行4:金额 + 笔数 */}
<div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 5 }}>
<span style={{ fontSize: 14, fontWeight: 800, color: tokens.accent, fontVariantNumeric: 'tabular-nums' }}>¥{money2(c.订单金额)}</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 11, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>{c.订单笔数} 笔订单</span>
</div>
</div>
);
})}
</ScrollList>
<div style={{
display: 'flex', alignItems: 'center', gap: 5, flex: '0 0 auto', paddingTop: 6,
fontSize: 10.5, color: tokens.textMuted, borderTop: `1px solid ${tokens.border}`,
}}>
<span style={{ flex: 1 }}>笔数与金额为该客户在本批销售订单中的合计,与销售订单页签同源可核对</span>
</div>
</>
);
}
@@ -1,111 +0,0 @@
import { useMemo } from 'react';
import { Package } from 'lucide-react';
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
import { salesOrders, type SalesOrder } from '../../data/ibp';
import { ScrollList } from '../supply/PurchaseOrderList';
/**
* 销售订单页签内容:Excel「销售订单」全量卡片列表。
* 列表口径交给纯函数,DemandPanel 用同一函数算页签徽标数,标题数字与条数不会各说各话。
*/
export const money = (n: number) => n.toLocaleString('zh-CN', { minimumFractionDigits: 1, maximumFractionDigits: 1 });
/** 订单号 / 客户简称 / 客户编码 / 产品编码 四向模糊匹配 */
export function filterSalesOrders(rows: SalesOrder[], query: string): SalesOrder[] {
const q = query.trim().toLowerCase();
if (!q) return rows;
return rows.filter((s: SalesOrder) =>
s.销售订单号.toLowerCase().includes(q)
|| s.客户简称.toLowerCase().includes(q)
|| s.客户编码.toLowerCase().includes(q)
|| s.产品编码.toLowerCase().includes(q));
}
const statusColor = (s: string, tk: ThemeTokens) =>
s === '生效' || s === '已下达' ? { c: tk.success, bg: tk.successBg } : { c: tk.warning, bg: tk.warningBg };
interface Props {
query: string;
expanded: boolean;
/** 当前选中的销售订单号(联动右侧采购单 / 生产工单 / 供应商与本页客户资料过滤) */
selectedSO: string | null;
onSelectSO: (so: string | null) => void;
}
export default function SalesOrderList({ query, expanded, selectedSO, onSelectSO }: Props) {
const { tokens } = useTheme();
const list = useMemo(() => filterSalesOrders(salesOrders, query), [query]);
const total = useMemo(() => list.reduce((a, s) => a + s.含税金额, 0), [list]);
return (
<>
{/* 汇总条 */}
<div style={{
display: 'flex', justifyContent: 'space-between', alignItems: 'center', flex: '0 0 auto',
padding: '6px 10px', marginBottom: 10, borderRadius: 8, fontSize: 12,
background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`, color: tokens.textSub,
}}>
<span>{list.length} 张订单 · {new Set(list.map(s => s.客户编码)).size} 家客户</span>
<span style={{ color: tokens.accent, fontWeight: 700, fontVariantNumeric: 'tabular-nums' }}>¥{money(total)}</span>
</div>
<ScrollList>
{list.length === 0 && (
<div style={{ padding: '20px 0', textAlign: 'center', fontSize: 13, color: tokens.textMuted }}>无匹配订单</div>
)}
{list.map(s => {
const active = selectedSO === s.销售订单号;
const sc = statusColor(s.单据状态, tokens);
return (
<div
key={s.销售订单号}
onClick={() => onSelectSO(active ? null : s.销售订单号)}
style={{
position: 'relative', marginBottom: 8, padding: '9px 11px', borderRadius: 9, cursor: 'pointer',
background: active ? tokens.accentBg : tokens.panelBgAlt,
border: `1px solid ${active ? tokens.accent : tokens.border}`,
transition: 'background .15s, border-color .15s',
}}
>
{active && <span style={{ position: 'absolute', left: -1, top: 10, bottom: 10, width: 3, borderRadius: 2, background: tokens.accent }} />}
{/* 行1:单号 + 状态 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<span style={{ fontSize: 13.5, fontWeight: 700, color: active ? tokens.accent : tokens.text, fontVariantNumeric: 'tabular-nums', letterSpacing: '0.02em' }}>
{s.销售订单号}
</span>
<span style={{ flex: 1 }} />
<span style={{
fontSize: 10.5, fontWeight: 600, padding: '1px 7px', borderRadius: 99,
color: sc.c, background: sc.bg, border: `1px solid ${sc.c}44`, whiteSpace: 'nowrap',
}}>{s.单据状态}</span>
</div>
{/* 行2:客户 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 4 }}>
<span style={{ fontSize: 12, color: tokens.textSub, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{s.客户简称}</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted, padding: '0 6px', borderRadius: 99, border: `1px solid ${tokens.border}`, whiteSpace: 'nowrap' }}>{s.客户分类}</span>
</div>
{/* 行3:产品 + 数量 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 5, marginTop: 5 }}>
<Package size={12} style={{ color: tokens.textMuted, flexShrink: 0 }} />
<span style={{ fontSize: 12.5, color: tokens.text, fontFamily: 'ui-monospace, monospace', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{s.产品编码}</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 12, color: tokens.textSub, fontVariantNumeric: 'tabular-nums' }}>{s.数量.toLocaleString()} PCS</span>
</div>
{/* 行4:金额 + 交期 */}
<div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 5 }}>
<span style={{ fontSize: 14.5, fontWeight: 800, color: tokens.accent, fontVariantNumeric: 'tabular-nums' }}>¥{money(s.含税金额)}</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 11, color: tokens.textMuted }}>发货 {s.预计发货日期}</span>
</div>
{expanded && (
<div style={{ fontSize: 10.5, color: tokens.textMuted, marginTop: 4 }}>{s.仓库名称} · {s.制单人} · 下单 {s.单据日期}</div>
)}
</div>
);
})}
</ScrollList>
</>
);
}
@@ -1,953 +0,0 @@
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 = 'tfamd-oee.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}`,
});
@@ -1,235 +0,0 @@
import { CircleDollarSign, FlaskConical, ShoppingCart, Target, Factory, Truck } from 'lucide-react';
import { useTheme } from '../../context/ThemeContext';
import { useText } from '../../i18n/useText';
import { PanelBody } from '../layout/PanelShell';
import type { MetricNode } from '../../data/sqlite';
import { alertColor, fmt } from '../../lib/metric';
import { achieveAt, levelAt, periodLabel, valueAt } from '../../lib/time';
import { STAGES, flowStats, type FlowIcon } from '../../lib/process';
/**
* 流程效能看板(研产供销六段价值链 · 过程指标层)。
*
* 与指标树的分工写在标题下那句话里:指标树是**结果**(钱和率的达成),
* 这里是**过程**(一批商机/项目/工单在链上每段停留多久、流过多少、返工多少)。
* 每段下方的指标片是真实 metric_node,点开即联动中央看板;
* 过程量则是可复现的模拟值,随底部时间轴游标一起演变。
*/
interface Props {
byCode: Map<string, MetricNode>;
selected: string;
onSelect: (code: string) => void;
period: number;
}
const ICONS: Record<FlowIcon, typeof Target> = {
target: Target, flask: FlaskConical, cart: ShoppingCart, factory: Factory, truck: Truck, cash: CircleDollarSign,
};
export default function ProcessFlowPanel({ byCode, selected, onSelect, period }: Props) {
const { tokens } = useTheme();
const { t } = useText();
const { stats, summary } = flowStats(period);
const bottleneck = STAGES.findIndex(s => s.key === summary.bottleneckKey);
const constraint = STAGES.findIndex(s => s.key === summary.constraintKey);
/* 在制品堆得最高的一段:比“总和”更能指出哪里在堵 */
const wipTop = stats.reduce((mi, x, i) => (x.wip > stats[mi].wip ? i : mi), 0);
const tile = (label: string, value: string, sub: string | null, color: string) => (
<div style={{
background: tokens.cardBg, border: `1px solid ${tokens.border}`, borderRadius: 9, padding: '5px 8px', minWidth: 0,
}}>
<div style={{ fontSize: 10, color: tokens.textMuted, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{label}</div>
<div style={{
fontSize: 16, fontWeight: 800, color, lineHeight: 1.25, fontVariantNumeric: 'tabular-nums',
fontFamily: 'ui-monospace, monospace', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
}}>{value}</div>
{sub && <div style={{ fontSize: 9.5, color: tokens.textMuted, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{sub}</div>}
</div>
);
/** 过程量小格:标签 + 值 + 目标/环比提示 */
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.textMuted, marginBottom: 8,
padding: '6px 9px', borderRadius: 8, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
}}>
{t.flow.hint}
</div>
{/* 全链汇总 */}
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 6, marginBottom: 4 }}>
{tile(t.flow.cycle, `${fmt(summary.cycle)}${t.flow.unitDay}`, `${t.flow.base} ${fmt(summary.cycleBase)}${t.flow.unitDay}`, tokens.text)}
{tile(t.flow.e2e, `${fmt(summary.e2e)}%`, `${t.flow.base} ${fmt(summary.e2eBase)}%`, summary.e2e >= 55 ? tokens.success : summary.e2e >= 40 ? tokens.warning : tokens.danger)}
{tile(t.flow.throughput, summary.throughput.toLocaleString(), `${t.flow.constraint} · ${STAGES[constraint].zh}`, tokens.info)}
{tile(t.flow.wip, summary.wip.toLocaleString(), `max · ${STAGES[wipTop].zh}`, tokens.textSub)}
</div>
<div
title={t.flow.bottleneckTip}
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.flow.bottleneck}</span>
<span style={{ color: tokens.text, fontWeight: 700, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{STAGES[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>
{/* 六段流程 */}
{STAGES.map((s, i) => {
const st = stats[i];
const c = alertColor(st.status, tokens);
const Icon = ICONS[s.icon];
const active = s.codes.includes(selected);
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;
return (
<div key={s.key}>
{/* 段间连线:在制品沿链流动 */}
{i > 0 && (
<div style={{ display: 'flex', gap: 8 }}>
<div style={{ width: 26, flexShrink: 0, position: 'relative', height: 26 }}>
<svg width={26} height={26} style={{ position: 'absolute', inset: 0, overflow: 'visible' }}>
<line x1={13} y1={-2} x2={13} y2={28} stroke={tokens.border} strokeWidth={1.4} />
<line
className="dash-flow" x1={13} y1={-2} x2={13} y2={28}
stroke={alertColor(stats[i - 1].status, tokens)} strokeWidth={1.6} strokeDasharray="3 5" strokeLinecap="round"
/>
<path d="M 9.5,23 L 13,28 L 16.5,23" fill="none" stroke={tokens.border} strokeWidth={1.4} strokeLinecap="round" />
</svg>
<span style={{
position: 'absolute', left: 30, top: 4, fontSize: 10, whiteSpace: 'nowrap', color: tokens.textMuted,
fontVariantNumeric: 'tabular-nums',
}}>
{t.flow.wip} {stats[i - 1].wip.toLocaleString()}
</span>
</div>
<div style={{ flex: 1, minWidth: 0 }} />
</div>
)}
<div style={{ display: 'flex', gap: 8 }}>
{/* 轨道节点 */}
<div style={{ width: 26, flexShrink: 0, display: 'flex', justifyContent: 'center', paddingTop: 8 }}>
<span style={{
display: 'grid', placeItems: 'center', width: 26, height: 26, borderRadius: 9, flexShrink: 0,
background: `${c}1f`, border: `1px solid ${c}66`, color: c,
boxShadow: active ? `0 0 10px ${c}66` : 'none',
}}>
<Icon size={14} />
</span>
</div>
{/* 段卡 */}
<div style={{
flex: 1, minWidth: 0, marginBottom: 2, borderRadius: 10, padding: '7px 9px',
background: tokens.panelBgAlt,
border: `1px solid ${active ? c : tokens.border}`,
boxShadow: active ? `0 0 0 1px ${c}44, 0 4px 14px ${c}22` : 'none',
transition: 'border-color 0.2s ease, box-shadow 0.2s ease',
}}>
<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: 13.5, fontWeight: 800, color: tokens.text, minWidth: 0, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{s.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' }}>
{s.roleZh} · {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>
{/* 关联指标片:真实 metric_node,点开联动中央看板 */}
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
{s.codes.map(cd => {
const n = byCode.get(cd);
if (!n) return null;
const nc = alertColor(levelAt(n, period), tokens);
const on = cd === selected;
const val = valueAt(n, period);
return (
<button
key={cd} onClick={() => onSelect(cd)} className="ghost-btn"
title={`${t.flow.linked} ${n.code} · ${n.name_zh} · ${t.flow.clickTip}`}
style={{
display: 'flex', alignItems: 'center', gap: 4, maxWidth: '100%', cursor: 'pointer',
padding: '2px 6px', borderRadius: 7, fontSize: 10.5,
background: on ? `${nc}22` : tokens.cardBg,
border: `1px solid ${on ? nc : tokens.border}`,
color: tokens.textSub,
}}
>
<span style={{ width: 5, height: 5, borderRadius: '50%', background: nc, flexShrink: 0 }} />
<span style={{ minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', color: on ? tokens.text : undefined }}>
{n.name_zh}
</span>
<span style={{ color: nc, fontWeight: 700, fontVariantNumeric: 'tabular-nums', fontFamily: 'ui-monospace, monospace', flexShrink: 0 }}>
{fmt(val)}{n.unit}
</span>
<span style={{ color: tokens.textMuted, fontVariantNumeric: 'tabular-nums', flexShrink: 0 }}>
{fmt(achieveAt(n, period), 0)}%
</span>
</button>
);
})}
</div>
</div>
</div>
</div>
);
})}
<div style={{ fontSize: 10, color: tokens.textMuted, lineHeight: 1.6, padding: '8px 2px 12px' }}>
{periodLabel(period)} · {t.flow.wipTip}
</div>
</PanelBody>
);
}
@@ -1,298 +0,0 @@
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>
);
}
@@ -6,7 +6,7 @@ import { alertColor, fmt } from '../../lib/metric';
import { ROLES, qualityStats, type QIcon } from '../../lib/qualityFlow';
/**
* 质量流程横条(PE → IE → QE → ME):与左栏 QualityFlowPanel 同一个 qualityStats 源,
* 质量流程横条(PE → IE → QE → ME):质量读数统一来自 lib/qualityFlow 的 qualityStats,
* 只换成横向一行等分的紧凑形态;点某段向下展开该段流转三行 + 4 项质量 KPI(含现状原文)。
*/
const ICONS: Record<QIcon, typeof Wrench> = { wrench: Wrench, ruler: Ruler, shield: ShieldCheck, cog: Cog };
@@ -1,161 +0,0 @@
import { useMemo } from 'react';
import { Boxes, Link2, Package, X } from 'lucide-react';
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
import { productionOrders, type ProductionOrder } from '../../data/ibp';
import { ScrollList } from './PurchaseOrderList';
/**
* 生产工单页签内容:一单一工单(工单号 = WO-销售订单号),按「离完工最近的先处理」排序,已完工沉底。
* 点卡片等于把它的来源销售订单送回左栏,与采购单页签共用同一条联动链路。
*/
export const fmtQty = (n: number) => n.toLocaleString('zh-CN');
/** 未完结工单按预计完工日升序,已完工排最后 */
export function sortWorkOrders(rows: ProductionOrder[]): ProductionOrder[] {
return [...rows].sort((a, b) => {
const doneA = a.单据状态 === '已完工' ? 1 : 0;
const doneB = b.单据状态 === '已完工' ? 1 : 0;
if (doneA !== doneB) return doneA - doneB;
return a.预计完工日期 < b.预计完工日期 ? -1 : a.预计完工日期 > b.预计完工日期 ? 1 : 0;
});
}
/** filterSO 非空时只保留该销售订单派生的工单 */
export function buildWorkOrders(filterSO: string | null): ProductionOrder[] {
return sortWorkOrders(filterSO ? productionOrders.filter(w => w.来源销售订单号 === filterSO) : productionOrders);
}
/** 工单号 / 来源订单 / 产品编码 / 车间 四向模糊匹配 */
export function filterWorkOrders(rows: ProductionOrder[], query: string): ProductionOrder[] {
const q = query.trim().toLowerCase();
if (!q) return rows;
return rows.filter(w =>
w.工单号.toLowerCase().includes(q)
|| w.来源销售订单号.toLowerCase().includes(q)
|| w.产品编码.toLowerCase().includes(q)
|| w.生产车间.toLowerCase().includes(q));
}
const statusColor = (s: string, tk: ThemeTokens) =>
s === '已完工' ? { c: tk.success, bg: tk.successBg }
: s === '已下达' ? { c: tk.info, bg: tk.infoBg }
: { c: tk.warning, bg: tk.warningBg };
interface Props {
query: string;
filterSO: string | null;
onClearFilter: () => void;
/** 点击工单:把来源销售订单交给左栏选中态 */
onSelectSO: (so: string | null) => void;
/** 当前左栏选中订单,用于卡片高亮 */
selectedSO: string | null;
}
export default function ProductionOrderList({ query, filterSO, onClearFilter, onSelectSO, selectedSO }: Props) {
const { tokens } = useTheme();
const list = useMemo(() => filterWorkOrders(buildWorkOrders(filterSO), query), [filterSO, query]);
const totalQty = useMemo(() => list.reduce((a, w) => a + w.生产数量, 0), [list]);
return (
<>
{/* 左栏订单联动条 */}
{filterSO && (
<div style={{
display: 'flex', alignItems: 'center', gap: 6, flex: '0 0 auto', marginBottom: 8,
padding: '5px 9px', borderRadius: 8, fontSize: 11.5, fontWeight: 600,
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
}}>
<Link2 size={12} style={{ flexShrink: 0 }} />
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>关联订单 {filterSO}</span>
<span style={{ flex: 1 }} />
<button onClick={onClearFilter} title="显示全部工单" style={{ background: 'none', border: 'none', color: tokens.accent, cursor: 'pointer', display: 'flex', padding: 2 }}>
<X size={13} />
</button>
</div>
)}
{/* 汇总条 */}
<div style={{
display: 'flex', justifyContent: 'space-between', alignItems: 'center', flex: '0 0 auto',
padding: '6px 10px', marginBottom: 10, borderRadius: 8, fontSize: 12,
background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`, color: tokens.textSub,
}}>
<span>{list.length} 张工单 · {new Set(list.map(w => w.生产车间)).size} 个车间</span>
<span style={{ color: tokens.accent, fontWeight: 700, fontVariantNumeric: 'tabular-nums' }}>{fmtQty(totalQty)} PCS</span>
</div>
<ScrollList>
{list.length === 0 && (
<div style={{ padding: '20px 0', textAlign: 'center', fontSize: 13, color: tokens.textMuted }}>
{filterSO ? '该销售订单暂无生产工单' : '无匹配工单'}
</div>
)}
{list.map(w => {
const active = selectedSO === w.来源销售订单号;
const sc = statusColor(w.单据状态, tokens);
return (
<div
key={w.工单号}
onClick={() => onSelectSO(active ? null : w.来源销售订单号)}
style={{
position: 'relative', marginBottom: 8, padding: '9px 11px', borderRadius: 9, cursor: 'pointer',
background: active ? tokens.accentBg : tokens.panelBgAlt,
border: `1px solid ${active ? tokens.accent : tokens.border}`,
transition: 'background .15s, border-color .15s',
}}
>
{active && <span style={{ position: 'absolute', left: -1, top: 10, bottom: 10, width: 3, borderRadius: 2, background: tokens.accent }} />}
{/* 行1:工单号 + 状态 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<span style={{ fontSize: 13, fontWeight: 700, color: active ? tokens.accent : tokens.text, fontVariantNumeric: 'tabular-nums', letterSpacing: '0.02em' }}>
{w.工单号}
</span>
<span style={{ flex: 1 }} />
<span style={{
fontSize: 10.5, fontWeight: 600, padding: '1px 7px', borderRadius: 99,
color: sc.c, background: sc.bg, border: `1px solid ${sc.c}44`, whiteSpace: 'nowrap',
}}>{w.单据状态}</span>
</div>
{/* 行2:来源订单 + 车间 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 4 }}>
<span style={{ fontSize: 11, color: tokens.textMuted }}>来自</span>
<span style={{ fontSize: 11.5, color: tokens.textSub, fontVariantNumeric: 'tabular-nums', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{w.来源销售订单号}</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted, padding: '0 6px', borderRadius: 99, border: `1px solid ${tokens.border}`, whiteSpace: 'nowrap' }}>{w.生产车间}</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 10.5, color: tokens.textMuted, whiteSpace: 'nowrap' }}>BOM {w.BOM版本}</span>
</div>
{/* 行3:产品 + 规格 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 5, marginTop: 5 }}>
<Package size={12} style={{ color: tokens.textMuted, flexShrink: 0 }} />
<span style={{ fontSize: 12.5, color: tokens.text, fontFamily: 'ui-monospace, monospace', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{w.产品编码}</span>
{w.规格型号 && (
<span style={{ fontSize: 10.5, color: tokens.textMuted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{w.规格型号}</span>
)}
</div>
{/* 行4:数量 + 工期 */}
<div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 5 }}>
<span style={{ fontSize: 14, fontWeight: 800, color: tokens.accent, fontVariantNumeric: 'tabular-nums' }}>{fmtQty(w.生产数量)}</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted }}>{w.计量单位}</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 11, color: tokens.textMuted, whiteSpace: 'nowrap' }}>
{w.预计开工日期} → {w.预计完工日期} · {w['生产周期(天)']} 天
</span>
</div>
</div>
);
})}
</ScrollList>
{/* 底部口径说明:工单由销售订单派生,一单一工单 */}
<div style={{
display: 'flex', alignItems: 'center', gap: 5, flex: '0 0 auto', paddingTop: 6,
fontSize: 10.5, color: tokens.textMuted, borderTop: `1px solid ${tokens.border}`,
}}>
<Boxes size={11} style={{ flexShrink: 0 }} />
<span>工单由销售订单派生 · 生产数量已对齐订单数量 · 点击卡片可联动左栏订单</span>
</div>
</>
);
}
@@ -1,154 +0,0 @@
import { useMemo } from 'react';
import { Link2, PackageSearch, X } from 'lucide-react';
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
import { purchaseOrders, type PurchaseOrder } from '../../data/ibp';
import { ScrollList } from '../layout/AutoScroll';
/**
* 采购单页签内容:按采购订单号把多行料项归并为一张卡片。
* 列表口径(分组 / 过滤 / 金额汇总)全部由这里的纯函数给出,SupplyPanel 复用同一函数算徽标数,
* 避免页签标题数字与实际条数各说各话。
*/
export interface POGroup {
采购订单号: string; 采购日期: string; 供应商编码: string; 供应商简称: string;
预计到货日期: string; 订单状态: string; 金额: number; 行数: number; 材料: string[];
来源销售订单: string[];
}
export const money = (n: number) => n.toLocaleString('zh-CN', { minimumFractionDigits: 1, maximumFractionDigits: 1 });
/** 按采购订单号归并;filterSO 非空时只保留该销售订单反查到的采购单 */
export function buildPurchaseGroups(filterSO: string | null): POGroup[] {
const src = filterSO ? purchaseOrders.filter(p => p.来源销售订单号 === filterSO) : purchaseOrders;
const byNo = new Map<string, POGroup>();
src.forEach((p: PurchaseOrder) => {
let g = byNo.get(p.采购订单号);
if (!g) {
g = {
采购订单号: p.采购订单号, 采购日期: p.采购日期, 供应商编码: p.供应商编码, 供应商简称: p.供应商简称,
预计到货日期: p.预计到货日期, 订单状态: p.订单状态, 金额: 0, 行数: 0, 材料: [], 来源销售订单: [],
};
byNo.set(p.采购订单号, g);
}
g.金额 += p.含税金额;
g.行数 += 1;
if (!g.材料.includes(p.材料编码)) g.材料.push(p.材料编码);
if (p.来源销售订单号 && !g.来源销售订单.includes(p.来源销售订单号)) g.来源销售订单.push(p.来源销售订单号);
});
return [...byNo.values()].sort((a, b) => (a.采购日期 < b.采购日期 ? 1 : -1));
}
/** 单号 / 供应商编码 / 供应商简称 / 物料 四向模糊匹配 */
export function filterPurchaseGroups(groups: POGroup[], query: string): POGroup[] {
const q = query.trim().toLowerCase();
if (!q) return groups;
return groups.filter(g =>
g.采购订单号.toLowerCase().includes(q)
|| g.供应商编码.toLowerCase().includes(q)
|| g.供应商简称.toLowerCase().includes(q)
|| g.材料.some(m => m.toLowerCase().includes(q)));
}
const statusColor = (s: string, tk: ThemeTokens) =>
s === '生效' ? { c: tk.success, bg: tk.successBg } : { c: tk.warning, bg: tk.warningBg };
interface Props {
query: string;
/** 左栏选中的销售订单号:非空时只看该订单反查到的采购单 */
filterSO: string | null;
onClearFilter: () => void;
}
export default function PurchaseOrderList({ query, filterSO, onClearFilter }: Props) {
const { tokens } = useTheme();
const list = useMemo(() => filterPurchaseGroups(buildPurchaseGroups(filterSO), query), [filterSO, query]);
const total = useMemo(() => list.reduce((a, g) => a + g.金额, 0), [list]);
return (
<>
{/* 左栏订单联动条 */}
{filterSO && (
<div style={{
display: 'flex', alignItems: 'center', gap: 6, flex: '0 0 auto', marginBottom: 8,
padding: '5px 9px', borderRadius: 8, fontSize: 11.5, fontWeight: 600,
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
}}>
<Link2 size={12} style={{ flexShrink: 0 }} />
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>关联订单 {filterSO}</span>
<span style={{ flex: 1 }} />
<button onClick={onClearFilter} title="显示全部采购单" style={{ background: 'none', border: 'none', color: tokens.accent, cursor: 'pointer', display: 'flex', padding: 2 }}>
<X size={13} />
</button>
</div>
)}
{/* 汇总条 */}
<div style={{
display: 'flex', justifyContent: 'space-between', alignItems: 'center', flex: '0 0 auto',
padding: '6px 10px', marginBottom: 10, borderRadius: 8, fontSize: 12,
background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`, color: tokens.textSub,
}}>
<span>{list.length} 张采购单 · {new Set(list.flatMap(g => g.材料)).size} 种物料</span>
<span style={{ color: tokens.accent, fontWeight: 700, fontVariantNumeric: 'tabular-nums' }}>¥{money(total)}</span>
</div>
<ScrollList>
{list.length === 0 && (
<div style={{ padding: '20px 0', textAlign: 'center', fontSize: 13, color: tokens.textMuted }}>
{filterSO ? '该销售订单暂无关联采购单' : '无匹配采购单'}
</div>
)}
{list.map(g => {
const sc = statusColor(g.订单状态, tokens);
return (
<div key={g.采购订单号} style={{
marginBottom: 8, padding: '9px 11px', borderRadius: 9,
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
}}>
{/* 行1:单号 + 状态 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<span style={{ fontSize: 13, fontWeight: 700, color: tokens.text, fontVariantNumeric: 'tabular-nums', letterSpacing: '0.02em' }}>
{g.采购订单号}
</span>
<span style={{ flex: 1 }} />
<span style={{
fontSize: 10.5, fontWeight: 600, padding: '1px 7px', borderRadius: 99,
color: sc.c, background: sc.bg, border: `1px solid ${sc.c}44`, whiteSpace: 'nowrap',
}}>{g.订单状态}</span>
</div>
{/* 行2:供应商 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 4 }}>
<span style={{ fontSize: 12, color: tokens.textSub, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{g.供应商简称}</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted }}>{g.供应商编码}</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 10.5, color: tokens.textMuted, whiteSpace: 'nowrap' }}>下单 {g.采购日期}</span>
</div>
{/* 行3:材料 */}
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 5, marginTop: 5 }}>
<PackageSearch size={12} style={{ color: tokens.textMuted, flexShrink: 0, marginTop: 2 }} />
<span style={{ fontSize: 12, color: tokens.text, fontFamily: 'ui-monospace, monospace', lineHeight: 1.5, wordBreak: 'break-all' }}>
{g.材料.slice(0, 3).join('、')}{g.材料.length > 3 ? ` 等 ${g.材料.length} 种` : ''}
</span>
</div>
{/* 行4:金额 + 到货 */}
<div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 5 }}>
<span style={{ fontSize: 14, fontWeight: 800, color: tokens.accent, fontVariantNumeric: 'tabular-nums' }}>¥{money(g.金额)}</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted }}>{g.行数} 行</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 11, color: tokens.textMuted }}>到货 {g.预计到货日期}</span>
</div>
</div>
);
})}
</ScrollList>
</>
);
}
/**
* 滚动区已上移到 layout/AutoScroll(新告警面板也用它),这里只留转发导出,
* 免得 demand/supply 三个旧列表各自再抄一份。
*/
export { ScrollList };
@@ -1,141 +0,0 @@
import { useMemo } from 'react';
import { Link2, Users, X } from 'lucide-react';
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
import { purchaseOrders, suppliers, type Supplier } from '../../data/ibp';
import { ScrollList } from './PurchaseOrderList';
/**
* 供应商资料页签:Excel「供应商资料」的 8 个字段全量展示(采购行数 / 采购金额沿用表内汇总口径)。
* 左栏选中销售订单时,只列出该订单实际下单过的供应商——关联关系由采购订单行反推,不另外造数据。
*/
export const money2 = (n: number) => n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
/** 按采购金额从大到小:钱多的供应商先看 */
export function sortSuppliers(rows: Supplier[]): Supplier[] {
return [...rows].sort((a, b) => b.采购金额 - a.采购金额);
}
/** filterSO 非空时用采购订单行反查该订单涉及的供应商编码 */
export function buildSuppliers(filterSO: string | null): Supplier[] {
if (!filterSO) return sortSuppliers(suppliers);
const codes = new Set(purchaseOrders.filter(p => p.来源销售订单号 === filterSO).map(p => p.供应商编码));
return sortSuppliers(suppliers.filter(s => codes.has(s.供应商编码)));
}
/** 编码 / 简称 / 所属类别 / 分管部门 四向模糊匹配 */
export function filterSuppliers(rows: Supplier[], query: string): Supplier[] {
const q = query.trim().toLowerCase();
if (!q) return rows;
return rows.filter(s =>
s.供应商编码.toLowerCase().includes(q)
|| s.供应商简称.toLowerCase().includes(q)
|| s.所属类别.toLowerCase().includes(q)
|| (s.分管部门 ?? '').toLowerCase().includes(q));
}
/** 客商一体(性质=客户/供应商)是治理关注项,单独给色 */
const natureColor = (nature: string, tk: ThemeTokens) =>
nature === '客户/供应商' ? { c: tk.warning, bg: tk.warningBg } : { c: tk.info, bg: tk.infoBg };
interface Props {
query: string;
filterSO: string | null;
onClearFilter: () => void;
/** 点击供应商:筛出它的采购单行,回到采购单页签看 */
onPickSupplier: (code: string) => void;
}
export default function SupplierList({ query, filterSO, onClearFilter, onPickSupplier }: Props) {
const { tokens } = useTheme();
const list = useMemo(() => filterSuppliers(buildSuppliers(filterSO), query), [filterSO, query]);
const total = useMemo(() => list.reduce((a, s) => a + s.采购金额, 0), [list]);
const totalLines = useMemo(() => list.reduce((a, s) => a + s.采购行数, 0), [list]);
return (
<>
{filterSO && (
<div style={{
display: 'flex', alignItems: 'center', gap: 6, flex: '0 0 auto', marginBottom: 8,
padding: '5px 9px', borderRadius: 8, fontSize: 11.5, fontWeight: 600,
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
}}>
<Link2 size={12} style={{ flexShrink: 0 }} />
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>关联订单 {filterSO} · 仅该单涉及的供应商</span>
<span style={{ flex: 1 }} />
<button onClick={onClearFilter} title="显示全部供应商" style={{ background: 'none', border: 'none', color: tokens.accent, cursor: 'pointer', display: 'flex', padding: 2 }}>
<X size={13} />
</button>
</div>
)}
{/* 汇总条 */}
<div style={{
display: 'flex', justifyContent: 'space-between', alignItems: 'center', flex: '0 0 auto',
padding: '6px 10px', marginBottom: 10, borderRadius: 8, fontSize: 12,
background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`, color: tokens.textSub,
}}>
<span>{list.length} 家供应商 · {totalLines} 行采购</span>
<span style={{ color: tokens.accent, fontWeight: 700, fontVariantNumeric: 'tabular-nums' }}>¥{money2(total)}</span>
</div>
<ScrollList>
{list.length === 0 && (
<div style={{ padding: '20px 0', textAlign: 'center', fontSize: 13, color: tokens.textMuted }}>
{filterSO ? '该销售订单暂无涉及供应商' : '无匹配供应商'}
</div>
)}
{list.map(s => {
const nc = natureColor(s.性质, tokens);
return (
<div
key={s.供应商编码}
onClick={() => onPickSupplier(s.供应商编码)}
title="点击只看这家供应商的采购单"
style={{
marginBottom: 8, padding: '9px 11px', borderRadius: 9, cursor: 'pointer',
background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
transition: 'background .15s, border-color .15s',
}}
>
{/* 行1:简称 + 编码 + 性质 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<Users size={12} style={{ color: tokens.textMuted, flexShrink: 0 }} />
<span style={{ fontSize: 13, fontWeight: 700, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{s.供应商简称}
</span>
<span style={{ fontSize: 10.5, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>{s.供应商编码}</span>
<span style={{ flex: 1 }} />
<span style={{
fontSize: 10.5, fontWeight: 600, padding: '1px 7px', borderRadius: 99,
color: nc.c, background: nc.bg, border: `1px solid ${nc.c}44`, whiteSpace: 'nowrap',
}}>{s.性质}</span>
</div>
{/* 行2:类别 + 部门 */}
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 5 }}>
<span style={{ fontSize: 10.5, color: tokens.textSub, padding: '0 6px', borderRadius: 99, border: `1px solid ${tokens.border}`, whiteSpace: 'nowrap' }}>{s.所属类别}</span>
<span style={{ fontSize: 11, color: tokens.textMuted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{s.分管部门 || '分管部门未填'}
</span>
</div>
{/* 行3:金额 + 行数 */}
<div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 5 }}>
<span style={{ fontSize: 14, fontWeight: 800, color: tokens.accent, fontVariantNumeric: 'tabular-nums' }}>¥{money2(s.采购金额)}</span>
<span style={{ flex: 1 }} />
<span style={{ fontSize: 11, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>{s.采购行数} 行采购</span>
</div>
</div>
);
})}
</ScrollList>
<div style={{
display: 'flex', alignItems: 'center', gap: 5, flex: '0 0 auto', paddingTop: 6,
fontSize: 10.5, color: tokens.textMuted, borderTop: `1px solid ${tokens.border}`,
}}>
<span style={{ flex: 1 }}>行数与金额为该供应商在本批采购订单中的合计,与采购单页签同源可核对</span>
</div>
</>
);
}