优化 简化统一代码
This commit is contained in:
1 parent
1d206fe179
commit
59abbf30d9
11 files changed
+332
-401
No files matched your search
@@ -257,9 +257,9 @@ function ImageWaterfall() {
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
filename: img.filename,
|
||||
thumbnail_path: img.thumbnail_path,
|
||||
thumbnailPath: img.thumbnailPath,
|
||||
path: img.path,
|
||||
file_type: img.file_type,
|
||||
fileType: img.fileType,
|
||||
format: img.format
|
||||
}));
|
||||
|
||||
@@ -360,8 +360,8 @@ function ImageWaterfall() {
|
||||
const rows = useWorker ? workerRows : syncRows;
|
||||
|
||||
const getThumbnailUrl = (image) => {
|
||||
// 注意:store中将thumbnail_path转换为thumbnailPath(驼峰命名)
|
||||
const thumbnailPath = image.thumbnailPath || image.thumbnail_path;
|
||||
// 后端已统一转换为 camelCase
|
||||
const thumbnailPath = image.thumbnailPath;
|
||||
|
||||
if (!currentLibraryId || !thumbnailPath) {
|
||||
return '';
|
||||
@@ -460,7 +460,7 @@ function ImageWaterfall() {
|
||||
}}
|
||||
onClick={(e) => handleImageClick(image, e, flatIndex)}
|
||||
onDoubleClick={() => {
|
||||
const fileType = image.file_type || 'image';
|
||||
const fileType = image.fileType || 'image';
|
||||
if (fileType === 'image') {
|
||||
setPhotoIndex(flatIndex);
|
||||
} else {
|
||||
@@ -481,19 +481,19 @@ function ImageWaterfall() {
|
||||
/>
|
||||
|
||||
{/* 文件类型标识 */}
|
||||
{image.file_type && image.file_type !== 'image' && (
|
||||
{image.fileType && image.fileType !== 'image' && (
|
||||
<div className={`absolute top-2 right-2 rounded-md px-2 py-1 flex items-center gap-1 shadow-lg ${
|
||||
image.file_type === 'video' ? 'bg-blue-500 bg-opacity-90' :
|
||||
image.file_type === 'audio' ? 'bg-pink-500 bg-opacity-90' :
|
||||
image.file_type === 'document' ? 'bg-green-500 bg-opacity-90' :
|
||||
image.file_type === 'design' ? 'bg-purple-500 bg-opacity-90' :
|
||||
image.fileType === 'video' ? 'bg-blue-500 bg-opacity-90' :
|
||||
image.fileType === 'audio' ? 'bg-pink-500 bg-opacity-90' :
|
||||
image.fileType === 'document' ? 'bg-green-500 bg-opacity-90' :
|
||||
image.fileType === 'design' ? 'bg-purple-500 bg-opacity-90' :
|
||||
'bg-gray-500 bg-opacity-90'
|
||||
}`}>
|
||||
{image.file_type === 'video' && <Play className="w-4 h-4 text-white fill-white" />}
|
||||
{image.file_type === 'audio' && <Music className="w-4 h-4 text-white" />}
|
||||
{image.file_type === 'document' && <FileText className="w-4 h-4 text-white" />}
|
||||
{image.file_type === 'design' && <Palette className="w-4 h-4 text-white" />}
|
||||
{image.file_type === 'other' && <File className="w-4 h-4 text-white" />}
|
||||
{image.fileType === 'video' && <Play className="w-4 h-4 text-white fill-white" />}
|
||||
{image.fileType === 'audio' && <Music className="w-4 h-4 text-white" />}
|
||||
{image.fileType === 'document' && <FileText className="w-4 h-4 text-white" />}
|
||||
{image.fileType === 'design' && <Palette className="w-4 h-4 text-white" />}
|
||||
{image.fileType === 'other' && <File className="w-4 h-4 text-white" />}
|
||||
<span className="text-white text-xs font-semibold uppercase">
|
||||
{image.format || image.filename.split('.').pop()}
|
||||
</span>
|
||||
|
||||
@@ -34,21 +34,9 @@ const useStore = create((set, get) => ({
|
||||
filteredImages: [],
|
||||
totalImageCount: 0, // 整个素材库的总图片数
|
||||
|
||||
// 设置图片(只存储必要字段)
|
||||
// 设置图片(后端已统一转换为 camelCase,直接使用)
|
||||
setImages: (images) => {
|
||||
// 只保留必要字段,减少内存占用
|
||||
const lightweightImages = images.map(img => ({
|
||||
id: img.id,
|
||||
path: img.path,
|
||||
filename: img.filename,
|
||||
size: img.size,
|
||||
format: img.format,
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
thumbnailPath: img.thumbnail_path || img.thumbnailPath,
|
||||
folder: img.folder
|
||||
}));
|
||||
set({ images: lightweightImages, filteredImages: lightweightImages });
|
||||
set({ images, filteredImages: images });
|
||||
},
|
||||
|
||||
setFilteredImages: (filteredImages) => set({ filteredImages }),
|
||||
@@ -75,19 +63,9 @@ const useStore = create((set, get) => ({
|
||||
folders: [],
|
||||
selectedFolder: null,
|
||||
|
||||
// 设置文件夹(只保留必要字段)
|
||||
// 设置文件夹(后端已统一转换为 camelCase,直接使用)
|
||||
setFolders: (folders) => {
|
||||
// 递归转换文件夹,确保所有层级的字段名一致
|
||||
const transformFolder = (folder) => ({
|
||||
path: folder.path,
|
||||
name: folder.name,
|
||||
imageCount: folder.image_count || folder.imageCount,
|
||||
parentPath: folder.parent_path || folder.parentPath,
|
||||
children: (folder.children || []).map(transformFolder)
|
||||
});
|
||||
|
||||
const lightweightFolders = folders.map(transformFolder);
|
||||
set({ folders: lightweightFolders });
|
||||
set({ folders });
|
||||
},
|
||||
|
||||
// 切换文件夹时清理缓存
|
||||
|
||||
Reference in new issue
Block a user