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

153 lines
7.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { 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>
);
}