'use client'; import { useState } from 'react'; import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, Chip, Box, Pagination, Tooltip, IconButton, Avatar, Dialog, DialogContent, Typography, Button, Checkbox } from '@mui/material'; import QuestionMarkIcon from '@mui/icons-material/QuestionMark'; import DatasetIcon from '@mui/icons-material/Dataset'; import DeleteIcon from '@mui/icons-material/Delete'; import EditNoteIcon from '@mui/icons-material/EditNote'; import PhotoLibraryIcon from '@mui/icons-material/PhotoLibrary'; import VisibilityIcon from '@mui/icons-material/Visibility'; import { useTranslation } from 'react-i18next'; import { imageStyles } from '../styles/imageStyles'; export default function ImageList({ images, total, page, pageSize, onPageChange, onGenerateQuestions, onGenerateDataset, onDelete, onAnnotate, selectedIds = [], onSelectionChange }) { const { t } = useTranslation(); const [previewImage, setPreviewImage] = useState(null); // 处理全选/取消全选 const handleSelectAll = event => { if (event.target.checked) { const allIds = images.map(img => img.id); onSelectionChange?.(allIds); } else { onSelectionChange?.([]); } }; // 处理单个选择 const handleSelectOne = (imageId, checked) => { if (checked) { onSelectionChange?.([...selectedIds, imageId]); } else { onSelectionChange?.(selectedIds.filter(id => id !== imageId)); } }; // 判断是否全选 const isAllSelected = images.length > 0 && selectedIds.length === images.length; const isSomeSelected = selectedIds.length > 0 && selectedIds.length < images.length; // 格式化日期 const formatDate = dateString => { if (!dateString) return '-'; const date = new Date(dateString); return date.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); }; // 格式化文件大小 const formatSize = bytes => { if (!bytes) return '-'; if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`; return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; }; if (!images || images.length === 0) { return ( {t('images.noImages', { defaultValue: '还没有图片' })} {t('images.noImagesDescription', { defaultValue: '开始导入图片,创建您的第一个图片数据集' })} ); } return ( <> {t('images.preview', { defaultValue: '预览' })} {t('images.fileName', { defaultValue: '文件名' })} {t('images.size', { defaultValue: '大小' })} {t('images.dimensions', { defaultValue: '尺寸' })} {t('images.questionCount', { defaultValue: '问题数' })} {t('images.datasetCount', { defaultValue: '数据集数' })} {t('images.uploadTime', { defaultValue: '上传时间' })} {t('common.actions', { defaultValue: '操作' })} {images.map(image => ( {/* 复选框 */} handleSelectOne(image.id, e.target.checked)} /> {/* 预览缩略图 */} setPreviewImage(image)} /> {/* 文件名 */} {image.imageName} {/* 文件大小 */} {formatSize(image.size)} {/* 尺寸 */} {image.width && image.height ? ( {image.width} × {image.height} ) : ( - )} {/* 问题数 */} 0 ? 'primary' : 'default'} variant="outlined" /> {/* 数据集数 */} 0 ? 'success' : 'default'} variant="outlined" /> {/* 上传时间 */} {formatDate(image.createAt)} {/* 操作按钮 */} setPreviewImage(image)}> onAnnotate(image)}> onGenerateQuestions(image)}> onGenerateDataset(image)}> onDelete(image.id)}> ))}
{/* 分页 */} {total > pageSize && ( onPageChange(newPage)} color="primary" size="large" showFirstButton showLastButton /> )} {/* 图片预览对话框 */} setPreviewImage(null)} maxWidth="lg" fullWidth PaperProps={{ sx: { bgcolor: 'transparent', boxShadow: 'none', overflow: 'hidden' } }} > {previewImage && ( {previewImage.imageName} {previewImage.imageName} )} ); }