'use client'; import { Box, IconButton, ToggleButton, Tooltip, Divider, Autocomplete, TextField, Menu, MenuItem } from '@mui/material'; import SearchIcon from '@mui/icons-material/Search'; import ViewModuleIcon from '@mui/icons-material/ViewModule'; import ViewListIcon from '@mui/icons-material/ViewList'; import DeleteIcon from '@mui/icons-material/DeleteOutline'; // 使用 Outline 版本更精致 import CheckCircleIcon from '@mui/icons-material/CheckCircleOutline'; // 统一使用 Outline 风格图标 import RadioButtonCheckedIcon from '@mui/icons-material/RadioButtonChecked'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import CheckBoxIcon from '@mui/icons-material/CheckBoxOutlineBlank'; // 或者 CheckBox import ShortTextIcon from '@mui/icons-material/ShortText'; import NotesIcon from '@mui/icons-material/Notes'; import UploadFileIcon from '@mui/icons-material/UploadFile'; import StorageIcon from '@mui/icons-material/Storage'; import FileDownloadIcon from '@mui/icons-material/FileDownload'; import { useTranslation } from 'react-i18next'; import { useTheme, alpha } from '@mui/material/styles'; import { useState } from 'react'; import { ToolbarContainer, FilterGroup, FilterButton, SearchWrapper, StyledInputBase, ActionGroup, ActionButton, DeleteActionButton, StyledToggleButtonGroup } from './EvalToolbar.styles'; const STATS_CONFIG = [ { key: 'true_false', icon: CheckCircleIcon, color: 'success' }, { key: 'single_choice', icon: RadioButtonCheckedIcon, color: 'primary' }, { key: 'multiple_choice', icon: CheckBoxIcon, color: 'secondary' }, { key: 'short_answer', icon: ShortTextIcon, color: 'warning' }, { key: 'open_ended', icon: NotesIcon, color: 'info' } ]; export default function EvalToolbar({ keyword, onKeywordChange, viewMode, onViewModeChange, selectedCount, onDeleteSelected, stats, questionType, onTypeChange, tags, onTagsChange, onImport, onBuiltinImport, onExport }) { const { t } = useTranslation(); const theme = useTheme(); const [importAnchorEl, setImportAnchorEl] = useState(null); const handleImportClick = event => { setImportAnchorEl(event.currentTarget); }; const handleImportClose = () => { setImportAnchorEl(null); }; const handleCustomImport = () => { handleImportClose(); onImport?.(); }; const handleBuiltinImport = () => { handleImportClose(); onBuiltinImport?.(); }; const tagOptions = stats?.byTag ? Object.keys(stats.byTag).map(tag => ({ label: tag, count: stats.byTag[tag] })) : []; return ( {/* 顶部:题型统计筛选 */} {stats && STATS_CONFIG.map(({ key, icon: Icon, color }) => { const count = stats.byType?.[key] || 0; const isActive = questionType === key; return ( } active={isActive} colorType={color} onClick={() => onTypeChange(isActive ? '' : key)} > {t(`eval.questionTypes.${key}`)} ({count}) ); })} {/* 底部:筛选和操作 */} {/* 左侧:筛选器组 */} {/* 搜索框 */} onKeywordChange(e.target.value)} /> {/* 标签筛选 */} `${option.label} (${option.count})`} value={tagOptions.filter(o => tags.includes(o.label))} onChange={(e, newValue) => onTagsChange(newValue.map(v => v.label))} renderInput={params => ( )} sx={{ '& .MuiAutocomplete-tag': { height: 24, borderRadius: 1 } }} /> {/* 右侧:操作按钮组 */} {/* 导入按钮下拉菜单 */} } endIcon={} onClick={handleImportClick} > {t('common.import', '导入')} {t('evalDatasets.import.custom', '导入自定义数据集')} {t('evalDatasets.import.builtin', '导入内置数据集')} {/* 导出按钮 */} } onClick={onExport}> {t('common.export', '导出')} {selectedCount > 0 && ( } onClick={onDeleteSelected}> {t('eval.deleteSelectedCount', `删除选中 (${selectedCount})`, { count: selectedCount })} )} value && onViewModeChange(value)} size="small" > ); }