feat(v1.3.0): 图片编辑器(裁剪/旋转/图像大小/调色) + 批量水印 + AI生图 + 收藏体系 + 图片新窗口打开按钮 + 合拼拼图 + 返回顶部
This commit is contained in:
1 parent
e345456abf
commit
94ac94436c
46 files changed
+6521
-114
No files matched your search
@@ -11,6 +11,7 @@ import { VariableSizeList as List } from 'react-window';
|
||||
// Stores
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { useUIStore } from '../stores/useUIStore';
|
||||
|
||||
// Custom Hooks
|
||||
import { useWaterfallLayout } from '../hooks/useWaterfallLayout';
|
||||
@@ -26,7 +27,7 @@ import { useInfiniteScroll } from '../hooks/useInfiniteScroll';
|
||||
|
||||
// Utils
|
||||
import { filterImages } from '../utils/imageFilters';
|
||||
import { imageAPI } from '../api';
|
||||
import { imageAPI, fileAPI } from '../api';
|
||||
|
||||
// Components
|
||||
import ImageCell from './ImageCell';
|
||||
@@ -53,8 +54,9 @@ function ImageWaterfall() {
|
||||
const {
|
||||
images, selectedImage, setSelectedImage, selectedImages, setSelectedImages,
|
||||
toggleImageSelection, clearSelection, imageLoadingState, selectedFolder,
|
||||
searchKeywords, filters, folders, setSelectedFolderItem
|
||||
searchKeywords, filters, folders, setSelectedFolderItem, updateImage
|
||||
} = useImageStore();
|
||||
const { setEditingImage, setMergeImages } = useUIStore();
|
||||
|
||||
// 状态
|
||||
const [photoIndex, setPhotoIndex] = useState(-1);
|
||||
@@ -184,7 +186,7 @@ function ImageWaterfall() {
|
||||
const getThumbnailUrl = useCallback((image) => {
|
||||
if (!currentLibraryId || !image.thumbnailPath) return '';
|
||||
const filename = image.thumbnailPath.replace(/\\/g, '/').split('/').pop();
|
||||
return imageAPI.getThumbnailUrl(currentLibraryId, filename);
|
||||
return imageAPI.getThumbnailUrl(currentLibraryId, filename, image.modifiedAt);
|
||||
}, [currentLibraryId]);
|
||||
|
||||
const getOriginalUrl = useCallback((image) => {
|
||||
@@ -276,6 +278,20 @@ function ImageWaterfall() {
|
||||
e.dataTransfer.effectAllowed = 'move';
|
||||
}, [selectedImages]);
|
||||
|
||||
const handleToggleFavorite = useCallback(async (image) => {
|
||||
const targets = (selectedImages && selectedImages.length > 1 && selectedImages.includes(image))
|
||||
? selectedImages : [image];
|
||||
const newVal = image.favorite ? 0 : 1;
|
||||
try {
|
||||
for (const img of targets) {
|
||||
await fileAPI.updateMetadata(currentLibraryId, img.path, { favorite: newVal });
|
||||
updateImage(img.path, { favorite: newVal });
|
||||
}
|
||||
} catch (e) {
|
||||
alert('收藏操作失败: ' + (e?.message || '未知错误'));
|
||||
}
|
||||
}, [currentLibraryId, selectedImages, updateImage]);
|
||||
|
||||
// 准备移动文件(用于右键菜单)
|
||||
const handlePrepareMove = useCallback(() => {
|
||||
const itemsToMove = selectedImages.length > 0
|
||||
@@ -342,6 +358,10 @@ function ImageWaterfall() {
|
||||
|
||||
if (!isMultiSelection) {
|
||||
menuOptions.push(
|
||||
menuItems.edit(() => {
|
||||
setContextMenu({ isOpen: false, position: null, image: null });
|
||||
setEditingImage(image);
|
||||
}),
|
||||
menuItems.rename(() => {
|
||||
setContextMenu({ isOpen: false, position: null, image: null });
|
||||
handleStartRename(image);
|
||||
@@ -351,6 +371,10 @@ function ImageWaterfall() {
|
||||
|
||||
menuOptions.push(
|
||||
menuItems.move(handlePrepareMove),
|
||||
menuItems.favorite(() => {
|
||||
setContextMenu({ isOpen: false, position: null, image: null });
|
||||
handleToggleFavorite(image);
|
||||
}, image?.favorite),
|
||||
menuItems.delete(async () => {
|
||||
setContextMenu({ isOpen: false, position: null, image: null });
|
||||
await handleQuickDelete();
|
||||
@@ -358,7 +382,7 @@ function ImageWaterfall() {
|
||||
);
|
||||
|
||||
return menuOptions;
|
||||
}, [selectedImages, handlePrepareMove, handleStartRename, handleCopy, handleQuickDelete, setUndoToast]);
|
||||
}, [selectedImages, handlePrepareMove, handleStartRename, handleCopy, handleQuickDelete, setUndoToast, handleToggleFavorite, setEditingImage]);
|
||||
|
||||
// 渲染单行
|
||||
const renderRow = useCallback(({ index, style }) => {
|
||||
@@ -388,8 +412,10 @@ function ImageWaterfall() {
|
||||
editingFilename={editingFilename}
|
||||
editInputRef={editInputRef}
|
||||
getThumbnailUrl={getThumbnailUrl}
|
||||
getOriginalUrl={getOriginalUrl}
|
||||
onImageClick={handleImageClick}
|
||||
onImageDoubleClick={handleImageDoubleClick}
|
||||
onToggleFavorite={handleToggleFavorite}
|
||||
onContextMenu={handleContextMenu}
|
||||
onDragStart={handleDragStart}
|
||||
onEditingChange={setEditingFilename}
|
||||
@@ -408,6 +434,7 @@ function ImageWaterfall() {
|
||||
renamingImage,
|
||||
editingFilename,
|
||||
getThumbnailUrl,
|
||||
getOriginalUrl,
|
||||
handleImageClick,
|
||||
handleImageDoubleClick,
|
||||
handleContextMenu,
|
||||
@@ -471,6 +498,49 @@ function ImageWaterfall() {
|
||||
>
|
||||
<DragDropOverlay isVisible={isDraggingOver} />
|
||||
<UploadProgress progress={uploadProgress} />
|
||||
|
||||
{/* 多选浮动操作条:显式删除入口(计数 = selectedImages ∪ selectedImage) */}
|
||||
{(() => {
|
||||
const union = [...selectedImages];
|
||||
if (selectedImage && !union.some(img => img.path === selectedImage.path)) {
|
||||
union.push(selectedImage);
|
||||
}
|
||||
const unionCount = union.length;
|
||||
if (unionCount <= 1) return null;
|
||||
return (
|
||||
<div className="absolute bottom-4 left-1/2 -translate-x-1/2 z-30 flex items-center gap-3 bg-gray-900/90 dark:bg-gray-800/90 backdrop-blur text-white rounded-full pl-5 pr-2 py-2 shadow-2xl">
|
||||
<span className="text-sm whitespace-nowrap">已选 {unionCount} 张图片</span>
|
||||
<button
|
||||
onClick={() => {
|
||||
setMergeImages(union);
|
||||
setEditingImage(union[0]);
|
||||
clearSelection();
|
||||
}}
|
||||
className="flex items-center gap-1.5 px-4 py-1.5 rounded-full bg-blue-600 hover:bg-blue-700 text-sm font-medium transition-colors"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 5a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1V5zm9 0a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 14a1 1 0 011-1h6a1 1 0 011 1v5a1 1 0 01-1 1H5a1 1 0 01-1-1v-5zm9 1a1 1 0 001 1h4a1 1 0 001-1v-4a1 1 0 00-1-1h-4a1 1 0 00-1 1v4z" />
|
||||
</svg>
|
||||
合拼
|
||||
</button>
|
||||
<button
|
||||
onClick={handleQuickDelete}
|
||||
className="flex items-center gap-1.5 px-4 py-1.5 rounded-full bg-red-600 hover:bg-red-700 text-sm font-medium transition-colors"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||
</svg>
|
||||
移入回收站
|
||||
</button>
|
||||
<button
|
||||
onClick={clearSelection}
|
||||
className="px-3 py-1.5 rounded-full text-sm text-gray-300 hover:text-white hover:bg-white/10 transition-colors"
|
||||
>
|
||||
取消选择
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
|
||||
<PhotoProvider
|
||||
images={providerImages}
|
||||
@@ -536,8 +606,10 @@ function ImageWaterfall() {
|
||||
editingFilename={editingFilename}
|
||||
editInputRef={editInputRef}
|
||||
getThumbnailUrl={getThumbnailUrl}
|
||||
getOriginalUrl={getOriginalUrl}
|
||||
onImageClick={handleImageClick}
|
||||
onImageDoubleClick={handleImageDoubleClick}
|
||||
onToggleFavorite={handleToggleFavorite}
|
||||
onContextMenu={handleContextMenu}
|
||||
onDragStart={handleDragStart}
|
||||
onEditingChange={setEditingFilename}
|
||||
|
||||
Reference in new issue
Block a user