/**
* 图片单元格组件
*/
import { Play, FileText, Palette, Music, File, Star, ExternalLink } from 'lucide-react';
const ImageCell = ({
image,
flatIndex,
isSelected,
renamingImage,
editingFilename,
editInputRef,
getThumbnailUrl,
getOriginalUrl,
onImageClick,
onImageDoubleClick,
onToggleFavorite,
onContextMenu,
onDragStart,
onEditingChange,
onFinishRename,
onCancelRename,
onStartRename
}) => {
const handleKeyDown = (e) => {
if (e.key === 'Enter') {
e.preventDefault();
onFinishRename();
} else if (e.key === 'Escape') {
e.preventDefault();
onCancelRename();
}
};
const handleDoubleClickFilename = (e) => {
// 始终阻止事件冒泡,避免触发图片放大
e.stopPropagation();
// 只在单选且不在编辑状态时允许双击重命名
if (!renamingImage) {
onStartRename(image);
}
};
return (
onImageClick(image, e, flatIndex)}
onDoubleClick={() => onImageDoubleClick(image, flatIndex)}
onContextMenu={(e) => onContextMenu(e, image)}
draggable={true}
onDragStart={(e) => onDragStart(e, image)}
>
)
{
e.target.src = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="200" height="200"%3E%3Crect fill="%23fef2f2" width="200" height="200"/%3E%3Ctext x="50%25" y="45%25" dominant-baseline="middle" text-anchor="middle" fill="%23dc2626" font-family="sans-serif" font-size="14"%3E加载失败%3C/text%3E%3Ctext x="50%25" y="60%25" dominant-baseline="middle" text-anchor="middle" fill="%23f87171" font-family="sans-serif" font-size="12"%3E请重新同步%3C/text%3E%3C/svg%3E';
e.target.onerror = null;
}}
/>
{/* 文件类型标识(右让位给「新窗口打开」按钮) */}
{image.fileType && image.fileType !== 'image' && (
{image.fileType === 'video' &&
}
{image.fileType === 'audio' &&
}
{image.fileType === 'document' &&
}
{image.fileType === 'design' &&
}
{image.fileType === 'other' &&
}
{image.format || image.filename.split('.').pop()}
)}
{/* 视频时长角标(右下角) */}
{image.fileType === 'video' && image.duration > 0 && (
{Math.floor(image.duration / 60)}:{String(Math.floor(image.duration % 60)).padStart(2, '0')}
)}
{/* 在新窗口打开原图(右上角) */}
e.stopPropagation()}
onDoubleClick={(e) => e.stopPropagation()}
className="absolute top-2 right-2 z-10 p-1 rounded-full backdrop-blur-sm bg-black/40 hover:bg-black/70 transition-all opacity-0 group-hover:opacity-100"
>
{/* 收藏标记 / 收藏按钮 */}
{renamingImage?.id === image.id ? (
// 编辑模式
onEditingChange(e.target.value)}
onKeyDown={handleKeyDown}
onBlur={onFinishRename}
onClick={(e) => e.stopPropagation()}
className="w-full text-xs text-center bg-transparent border-none outline-none focus:outline-none underline decoration-2 decoration-blue-500 underline-offset-2 truncate leading-none"
style={{
color: isSelected ? '#3b82f6' : '#909090',
fontWeight: isSelected ? '600' : '400',
padding: 0,
margin: 0,
height: '1rem'
}}
/>
) : (
// 显示模式
{image.filename}
)}
);
};
export default ImageCell;