重构 更规范性的文件组织
This commit is contained in:
1 parent
59abbf30d9
commit
ea6c87ad25
53 files changed
+3274
-2110
No files matched your search
+37
-39
@@ -1,7 +1,10 @@
|
||||
import { useEffect, useState, useRef } from 'react';
|
||||
import { io } from 'socket.io-client';
|
||||
import useStore from './store/useStore';
|
||||
import { libraryAPI, imageAPI, scanAPI } from './services/api';
|
||||
import { useUIStore } from './stores/useUIStore';
|
||||
import { useLibraryStore } from './stores/useLibraryStore';
|
||||
import { useImageStore } from './stores/useImageStore';
|
||||
import { useScanStore } from './stores/useScanStore';
|
||||
import { libraryAPI, imageAPI, scanAPI } from './api';
|
||||
import domCleanup from './utils/domCleanup';
|
||||
import Sidebar from './components/Sidebar';
|
||||
import MainContent from './components/MainContent';
|
||||
@@ -9,15 +12,10 @@ import RightPanel from './components/RightPanel';
|
||||
import Header from './components/Header';
|
||||
|
||||
function App() {
|
||||
const {
|
||||
theme,
|
||||
setLibraries,
|
||||
setCurrentLibrary,
|
||||
setScanProgress,
|
||||
mobileView,
|
||||
setMobileView,
|
||||
selectedImage
|
||||
} = useStore();
|
||||
const { theme, mobileView, setMobileView } = useUIStore();
|
||||
const { setLibraries, setCurrentLibrary } = useLibraryStore();
|
||||
const { selectedImage } = useImageStore();
|
||||
const { setScanProgress } = useScanStore();
|
||||
const [leftWidth, setLeftWidth] = useState(256); // 默认 256px (w-64)
|
||||
const [rightWidth, setRightWidth] = useState(320); // 默认 320px (w-80)
|
||||
const [isDraggingLeft, setIsDraggingLeft] = useState(false);
|
||||
@@ -81,7 +79,7 @@ function App() {
|
||||
|
||||
socket.on('scanProgress', (progress) => {
|
||||
// 只显示当前素材库的进度
|
||||
const currentLibId = useStore.getState().currentLibraryId;
|
||||
const currentLibId = useLibraryStore.getState().currentLibraryId;
|
||||
if (progress.libraryId === currentLibId) {
|
||||
setScanProgress(progress);
|
||||
}
|
||||
@@ -91,40 +89,40 @@ function App() {
|
||||
console.log('📊 Scan complete:', { libraryId, results });
|
||||
|
||||
// Only reload if this is the current library
|
||||
const currentLibId = useStore.getState().currentLibraryId;
|
||||
const currentLibId = useLibraryStore.getState().currentLibraryId;
|
||||
console.log('🔍 Current library:', currentLibId, 'Scan library:', libraryId, 'Match:', libraryId === currentLibId);
|
||||
|
||||
if (libraryId === currentLibId) {
|
||||
console.log('🔄 Reloading folders and images...');
|
||||
|
||||
// 获取当前的筛选条件
|
||||
const state = useStore.getState();
|
||||
const imageState = useImageStore.getState();
|
||||
const params = {
|
||||
keywords: state.searchKeywords,
|
||||
...state.filters
|
||||
keywords: imageState.searchKeywords,
|
||||
...imageState.filters
|
||||
};
|
||||
|
||||
// 只有选中了文件夹才添加 folder 参数
|
||||
if (state.selectedFolder) {
|
||||
params.folder = state.selectedFolder;
|
||||
if (imageState.selectedFolder) {
|
||||
params.folder = imageState.selectedFolder;
|
||||
}
|
||||
|
||||
// 并行加载文件夹和图片
|
||||
Promise.all([
|
||||
imageAPI.getFolders(libraryId),
|
||||
// 如果没有选中文件夹且没有搜索条件,不加载图片(保持在 Dashboard)
|
||||
(state.selectedFolder || state.searchKeywords || state.filters.formats.length > 0)
|
||||
(imageState.selectedFolder || imageState.searchKeywords || imageState.filters.formats.length > 0)
|
||||
? imageAPI.search(libraryId, params)
|
||||
: Promise.resolve({ data: { images: [] } }),
|
||||
: Promise.resolve({ images: [] }),
|
||||
// 扫描完成后总是重新获取总数
|
||||
imageAPI.getCount(libraryId)
|
||||
]).then(([foldersRes, imagesRes, countRes]) => {
|
||||
useStore.getState().setFolders(foldersRes.data.folders);
|
||||
useStore.getState().setImages(imagesRes.data.images);
|
||||
useImageStore.getState().setFolders(foldersRes.folders);
|
||||
useImageStore.getState().setImages(imagesRes.images);
|
||||
// 更新图片总数
|
||||
useStore.getState().setTotalImageCount(countRes.data.count);
|
||||
useImageStore.getState().setTotalImageCount(countRes.count);
|
||||
|
||||
console.log(`✅ Data reloaded, total: ${countRes.data.count}`);
|
||||
console.log(`✅ Data reloaded, total: ${countRes.count}`);
|
||||
}).catch(err => {
|
||||
console.error('❌ Error reloading data:', err);
|
||||
}).finally(() => {
|
||||
@@ -162,7 +160,7 @@ function App() {
|
||||
const loadLibraries = async () => {
|
||||
try {
|
||||
const response = await libraryAPI.getAll();
|
||||
const { libraries, currentLibraryId: libId, theme: configTheme, preferences } = response.data;
|
||||
const { libraries, currentLibraryId: libId, theme: configTheme, preferences } = response;
|
||||
|
||||
// 立即更新基础状态
|
||||
setLibraries(libraries);
|
||||
@@ -170,11 +168,11 @@ function App() {
|
||||
|
||||
// 加载主题和偏好设置
|
||||
if (configTheme) {
|
||||
useStore.getState().setTheme(configTheme);
|
||||
useUIStore.getState().setTheme(configTheme);
|
||||
}
|
||||
if (preferences) {
|
||||
const { thumbnailHeight, leftPanelWidth, rightPanelWidth } = preferences;
|
||||
if (thumbnailHeight) useStore.getState().setThumbnailHeight(thumbnailHeight);
|
||||
if (thumbnailHeight) useUIStore.getState().setThumbnailHeight(thumbnailHeight);
|
||||
if (leftPanelWidth) setLeftWidth(leftPanelWidth);
|
||||
if (rightPanelWidth) setRightWidth(rightPanelWidth);
|
||||
}
|
||||
@@ -186,12 +184,12 @@ function App() {
|
||||
imageAPI.getFolders(libId)
|
||||
]);
|
||||
|
||||
useStore.getState().setFolders(foldersRes.data.folders);
|
||||
useImageStore.getState().setFolders(foldersRes.folders);
|
||||
|
||||
// 获取总数
|
||||
try {
|
||||
const countRes = await imageAPI.getCount(libId);
|
||||
useStore.getState().setTotalImageCount(countRes.data.count);
|
||||
useImageStore.getState().setTotalImageCount(countRes.count);
|
||||
} catch (e) {
|
||||
console.error('Failed to get image count:', e);
|
||||
}
|
||||
@@ -200,7 +198,7 @@ function App() {
|
||||
|
||||
// 后台检查扫描状态(不阻塞主流程)
|
||||
scanAPI.getStatus(libId).then(scanStatus => {
|
||||
const { status, progress, pendingCount } = scanStatus.data;
|
||||
const { status, progress, pendingCount } = scanStatus;
|
||||
if (status === 'scanning' || status === 'paused') {
|
||||
console.log(`🔄 恢复扫描状态: ${status}, 进度: ${progress?.percent || 0}%`);
|
||||
setScanProgress({
|
||||
@@ -222,13 +220,13 @@ function App() {
|
||||
const params = {};
|
||||
|
||||
// Get current selected folder
|
||||
const selectedFolder = useStore.getState().selectedFolder;
|
||||
const selectedFolder = useImageStore.getState().selectedFolder;
|
||||
if (selectedFolder) {
|
||||
params.folder = selectedFolder;
|
||||
}
|
||||
|
||||
const response = await imageAPI.search(libraryId, params);
|
||||
useStore.getState().setImages(response.data.images);
|
||||
useImageStore.getState().setImages(response.images);
|
||||
} catch (error) {
|
||||
console.error('Error loading images:', error);
|
||||
}
|
||||
@@ -237,7 +235,7 @@ function App() {
|
||||
const loadFolders = async (libraryId) => {
|
||||
try {
|
||||
const response = await imageAPI.getFolders(libraryId);
|
||||
useStore.getState().setFolders(response.data.folders);
|
||||
useImageStore.getState().setFolders(response.folders);
|
||||
} catch (error) {
|
||||
console.error('Error loading folders:', error);
|
||||
}
|
||||
@@ -325,8 +323,8 @@ function App() {
|
||||
setIsDraggingLeft(false);
|
||||
setIsDraggingRight(false);
|
||||
// 拖动结束,恢复
|
||||
useStore.getState().setIsResizingPanels(false);
|
||||
useStore.getState().setResizingSide(null);
|
||||
useUIStore.getState().setIsResizingPanels(false);
|
||||
useUIStore.getState().setResizingSide(null);
|
||||
};
|
||||
|
||||
// 使用 passive: false 确保可以阻止默认行为
|
||||
@@ -434,8 +432,8 @@ function App() {
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault();
|
||||
// 标记正在拖动,供其他组件抑制重算
|
||||
useStore.getState().setIsResizingPanels(true);
|
||||
useStore.getState().setResizingSide('left');
|
||||
useUIStore.getState().setIsResizingPanels(true);
|
||||
useUIStore.getState().setResizingSide('left');
|
||||
setIsDraggingLeft(true);
|
||||
}}
|
||||
>
|
||||
@@ -455,8 +453,8 @@ function App() {
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault();
|
||||
// 标记正在拖动,供其他组件抑制重算
|
||||
useStore.getState().setIsResizingPanels(true);
|
||||
useStore.getState().setResizingSide('right');
|
||||
useUIStore.getState().setIsResizingPanels(true);
|
||||
useUIStore.getState().setResizingSide('right');
|
||||
setIsDraggingRight(true);
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* HTTP 客户端
|
||||
* 使用原生 Fetch API
|
||||
*/
|
||||
|
||||
const API_BASE = '/api';
|
||||
|
||||
/**
|
||||
* API 错误类
|
||||
*/
|
||||
class APIError extends Error {
|
||||
constructor(message, status, data) {
|
||||
super(message);
|
||||
this.name = 'APIError';
|
||||
this.status = status;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送请求
|
||||
*/
|
||||
async function request(url, options = {}) {
|
||||
const config = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers
|
||||
},
|
||||
...options
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}${url}`, config);
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new APIError(
|
||||
data.error?.message || data.error || 'Request failed',
|
||||
response.status,
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
// 直接返回数据,不包装
|
||||
return data.data !== undefined ? data.data : data;
|
||||
} catch (error) {
|
||||
if (error instanceof APIError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 网络错误或解析错误
|
||||
throw new APIError(
|
||||
error.message || 'Network error',
|
||||
0,
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET 请求
|
||||
*/
|
||||
function get(url, options = {}) {
|
||||
return request(url, { method: 'GET', ...options });
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求
|
||||
*/
|
||||
function post(url, body, options = {}) {
|
||||
return request(url, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
...options
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT 请求
|
||||
*/
|
||||
function put(url, body, options = {}) {
|
||||
return request(url, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(body),
|
||||
...options
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE 请求
|
||||
*/
|
||||
function del(url, options = {}) {
|
||||
return request(url, { method: 'DELETE', ...options });
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get,
|
||||
post,
|
||||
put,
|
||||
delete: del
|
||||
};
|
||||
|
||||
export { APIError };
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 图片 API
|
||||
*/
|
||||
|
||||
import { api } from '../client';
|
||||
|
||||
/**
|
||||
* 搜索图片
|
||||
*/
|
||||
export async function search(libraryId, params = {}, options = {}) {
|
||||
const query = new URLSearchParams({
|
||||
libraryId,
|
||||
...params
|
||||
});
|
||||
|
||||
return api.get(`/image?${query}`, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片总数
|
||||
*/
|
||||
export async function getCount(libraryId) {
|
||||
return api.get(`/image/count?libraryId=${libraryId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取统计信息
|
||||
*/
|
||||
export async function getStats(libraryId) {
|
||||
return api.get(`/image/stats?libraryId=${libraryId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件夹列表
|
||||
*/
|
||||
export async function getFolders(libraryId) {
|
||||
return api.get(`/image/folders?libraryId=${libraryId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存元数据
|
||||
*/
|
||||
export async function getCacheMeta(libraryId) {
|
||||
return api.get(`/image/cache-meta?libraryId=${libraryId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缩略图 URL
|
||||
* 使用分片结构,不再需要 size 参数
|
||||
*/
|
||||
export function getThumbnailUrl(libraryId, filename) {
|
||||
return `/api/image/thumbnail/${libraryId}/${filename}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取原图 URL
|
||||
*/
|
||||
export function getOriginalUrl(libraryId, path) {
|
||||
return `/api/image/original/${libraryId}/${path}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在文件管理器中打开
|
||||
*/
|
||||
export async function openInExplorer(libraryId, path) {
|
||||
return api.post(`/image/${libraryId}/open-file`, { path });
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 素材库 API
|
||||
*/
|
||||
|
||||
import { api } from '../client';
|
||||
|
||||
/**
|
||||
* 获取所有素材库
|
||||
*/
|
||||
export async function getAll() {
|
||||
return api.get('/library');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加素材库
|
||||
*/
|
||||
export async function add(name, path) {
|
||||
return api.post('/library', { name, path });
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新素材库
|
||||
*/
|
||||
export async function update(id, updates) {
|
||||
return api.put(`/library/${id}`, updates);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除素材库
|
||||
*/
|
||||
export async function remove(id) {
|
||||
return api.delete(`/library/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除素材库(别名)
|
||||
*/
|
||||
export const deleteLibrary = remove;
|
||||
|
||||
/**
|
||||
* 设置当前素材库
|
||||
*/
|
||||
export async function setCurrent(id) {
|
||||
return api.post(`/library/${id}/set-current`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新偏好设置
|
||||
*/
|
||||
export async function updatePreferences(preferences) {
|
||||
return api.put('/library/preferences', preferences);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新主题
|
||||
*/
|
||||
export async function updateTheme(theme) {
|
||||
return api.put('/library/theme', { theme });
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 扫描 API
|
||||
*/
|
||||
|
||||
import { api } from '../client';
|
||||
|
||||
/**
|
||||
* 全量扫描
|
||||
*/
|
||||
export async function fullScan(libraryId, wait = false) {
|
||||
return api.post('/scan/full', { libraryId, wait });
|
||||
}
|
||||
|
||||
/**
|
||||
* 增量同步
|
||||
*/
|
||||
export async function sync(libraryId, wait = false) {
|
||||
return api.post('/scan/sync', { libraryId, wait });
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止扫描
|
||||
*/
|
||||
export async function stop(libraryId) {
|
||||
return api.post('/scan/stop', { libraryId });
|
||||
}
|
||||
|
||||
/**
|
||||
* 继续扫描
|
||||
*/
|
||||
export async function resume(libraryId) {
|
||||
return api.post('/scan/resume', { libraryId });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扫描状态
|
||||
*/
|
||||
export async function getStatus(libraryId) {
|
||||
return api.get(`/scan/status/${libraryId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复文件夹路径
|
||||
*/
|
||||
export async function fixFolders(libraryId) {
|
||||
return api.post('/scan/fix-folders', { libraryId });
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* API 统一导出
|
||||
*/
|
||||
|
||||
import * as library from './endpoints/library';
|
||||
import * as image from './endpoints/image';
|
||||
import * as scan from './endpoints/scan';
|
||||
|
||||
export const libraryAPI = library;
|
||||
export const imageAPI = image;
|
||||
export const scanAPI = scan;
|
||||
|
||||
export { api, APIError } from './client';
|
||||
|
||||
// watchAPI 空实现(已废弃)
|
||||
export const watchAPI = {
|
||||
start: () => Promise.resolve({}),
|
||||
stop: () => Promise.resolve({}),
|
||||
status: () => Promise.resolve({ watching: false }),
|
||||
list: () => Promise.resolve({ watchers: [] })
|
||||
};
|
||||
@@ -1,15 +1,14 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import useStore from '../store/useStore';
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { useUIStore } from '../stores/useUIStore';
|
||||
import { useScanStore } from '../stores/useScanStore';
|
||||
import { Folder, Image as ImageIcon, HardDrive } from 'lucide-react';
|
||||
import { imageAPI } from '../services/api';
|
||||
import { imageAPI } from '../api';
|
||||
|
||||
function Dashboard() {
|
||||
const {
|
||||
totalImageCount,
|
||||
folders,
|
||||
currentLibraryId,
|
||||
getCurrentLibrary
|
||||
} = useStore();
|
||||
const { currentLibraryId, getCurrentLibrary } = useLibraryStore();
|
||||
const { totalImageCount, folders } = useImageStore();
|
||||
|
||||
const currentLibrary = getCurrentLibrary();
|
||||
const [librarySize, setLibrarySize] = useState(0);
|
||||
@@ -25,7 +24,7 @@ function Dashboard() {
|
||||
if (currentLibraryId) {
|
||||
imageAPI.getStats(currentLibraryId)
|
||||
.then(res => {
|
||||
setLibrarySize(res.data.totalSize || 0);
|
||||
setLibrarySize(res.totalSize || 0);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Failed to fetch library stats:', err);
|
||||
@@ -110,7 +109,7 @@ function Dashboard() {
|
||||
<div
|
||||
key={folder.path}
|
||||
className="bg-white dark:bg-gray-800 rounded-lg p-4 shadow-sm border border-gray-100 dark:border-gray-700 hover:shadow-md transition-shadow cursor-pointer group"
|
||||
onClick={() => useStore.getState().setSelectedFolder(folder.path)}
|
||||
onClick={() => useImageStore.getState().setSelectedFolder(folder.path)}
|
||||
>
|
||||
<div className="flex items-center gap-3 mb-2">
|
||||
<Folder className="w-8 h-8 text-yellow-500 group-hover:text-yellow-400 transition-colors" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { X, ExternalLink } from 'lucide-react';
|
||||
import { imageAPI } from '../services/api';
|
||||
import { imageAPI } from '../api';
|
||||
|
||||
/**
|
||||
* 文件查看器 - 支持视频播放和文档查看
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
import { useState, useEffect, useMemo, useRef } from 'react';
|
||||
import { Sun, Moon, Search, Filter, Sliders, RefreshCw } from 'lucide-react';
|
||||
import useStore from '../store/useStore';
|
||||
import { libraryAPI, scanAPI, watchAPI } from '../services/api';
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { useUIStore } from '../stores/useUIStore';
|
||||
import { useScanStore } from '../stores/useScanStore';
|
||||
import { libraryAPI, scanAPI, watchAPI } from '../api';
|
||||
|
||||
function Header() {
|
||||
const {
|
||||
theme,
|
||||
toggleTheme,
|
||||
searchKeywords,
|
||||
thumbnailHeight,
|
||||
images,
|
||||
filteredImages,
|
||||
selectedFolder,
|
||||
currentLibraryId,
|
||||
setSearchKeywords,
|
||||
setThumbnailHeight,
|
||||
setFilteredImages,
|
||||
mobileView
|
||||
} = useStore();
|
||||
const { currentLibraryId } = useLibraryStore();
|
||||
const { searchKeywords, images, selectedFolder, setSearchKeywords } = useImageStore();
|
||||
const { theme, toggleTheme, thumbnailHeight, setThumbnailHeight, mobileView } = useUIStore();
|
||||
|
||||
const [showFilters, setShowFilters] = useState(false);
|
||||
const [selectedFormats, setSelectedFormats] = useState([]);
|
||||
@@ -256,10 +248,7 @@ function Header() {
|
||||
});
|
||||
}, [images, selectedFormats, selectedSizes, selectedOrientation]);
|
||||
|
||||
// 更新 filteredImages
|
||||
useEffect(() => {
|
||||
setFilteredImages(filteredResult);
|
||||
}, [filteredResult, setFilteredImages]);
|
||||
// 注意:过滤逻辑已移至后端,这里的 filteredResult 仅用于显示统计
|
||||
|
||||
// 切换选项
|
||||
const toggleFormat = (format) => {
|
||||
|
||||
@@ -3,48 +3,43 @@ import { PhotoProvider } from 'react-photo-view';
|
||||
import 'react-photo-view/dist/react-photo-view.css';
|
||||
import { VariableSizeList as List } from 'react-window';
|
||||
import { Play, FileText, Palette, Music, File } from 'lucide-react';
|
||||
import useStore from '../store/useStore';
|
||||
import { imageAPI } from '../services/api';
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { useUIStore } from '../stores/useUIStore';
|
||||
import { useScanStore } from '../stores/useScanStore';
|
||||
import { imageAPI } from '../api';
|
||||
import requestManager, { RequestType } from '../services/requestManager';
|
||||
import FileViewer from './FileViewer';
|
||||
|
||||
// 虚拟滚动阈值:超过此数量启用虚拟滚动
|
||||
const VIRTUAL_SCROLL_THRESHOLD = 100;
|
||||
|
||||
// Web Worker 阈值:超过此数量使用 Worker 计算布局
|
||||
const WORKER_THRESHOLD = 500;
|
||||
// 加载配置
|
||||
const LOAD_CONFIG = {
|
||||
pageSize: 100, // 每次加载 100 张(更轻量)
|
||||
preloadThreshold: 300, // 距离边界 300px 时预加载
|
||||
overscanCount: 4, // 预渲染 4 行(减少内存)
|
||||
};
|
||||
|
||||
function ImageWaterfall() {
|
||||
const { currentLibraryId } = useLibraryStore();
|
||||
const {
|
||||
filteredImages,
|
||||
currentLibraryId,
|
||||
thumbnailHeight,
|
||||
selectedImage,
|
||||
setSelectedImage,
|
||||
selectedImages,
|
||||
setSelectedImages,
|
||||
toggleImageSelection,
|
||||
clearSelection,
|
||||
isResizingPanels,
|
||||
imageLoadingState,
|
||||
selectedFolder,
|
||||
searchKeywords,
|
||||
filters,
|
||||
appendImages,
|
||||
setImageLoadingState
|
||||
} = useStore();
|
||||
images, selectedImage, setSelectedImage, selectedImages, setSelectedImages,
|
||||
toggleImageSelection, clearSelection, imageLoadingState, selectedFolder,
|
||||
searchKeywords, filters, appendImages, setImageLoadingState
|
||||
} = useImageStore();
|
||||
|
||||
const filteredImages = images;
|
||||
const { thumbnailHeight, isResizingPanels } = useUIStore();
|
||||
const containerRef = useRef(null);
|
||||
const listRef = useRef(null);
|
||||
const workerRef = useRef(null);
|
||||
const requestIdRef = useRef(0);
|
||||
const [containerWidth, setContainerWidth] = useState(0);
|
||||
const [containerHeight, setContainerHeight] = useState(0);
|
||||
const [photoIndex, setPhotoIndex] = useState(-1);
|
||||
const [lastSelectedIndex, setLastSelectedIndex] = useState(null);
|
||||
const [viewerFile, setViewerFile] = useState(null);
|
||||
const [workerRows, setWorkerRows] = useState([]); // Worker 计算的行
|
||||
|
||||
// 加载更多图片
|
||||
// 简单的向下无限滚动加载
|
||||
const loadMoreImages = useCallback(async () => {
|
||||
if (!currentLibraryId || !imageLoadingState.hasMore || imageLoadingState.isLoading) {
|
||||
return;
|
||||
@@ -55,8 +50,8 @@ function ImageWaterfall() {
|
||||
|
||||
try {
|
||||
const params = {
|
||||
offset: imageLoadingState.loadedCount,
|
||||
limit: 200
|
||||
offset: images.length,
|
||||
limit: LOAD_CONFIG.pageSize
|
||||
};
|
||||
if (selectedFolder) params.folder = selectedFolder;
|
||||
if (searchKeywords) params.keywords = searchKeywords;
|
||||
@@ -70,15 +65,15 @@ function ImageWaterfall() {
|
||||
return;
|
||||
}
|
||||
|
||||
const { images, total, hasMore } = response.data;
|
||||
const { images: newImages, total, hasMore } = response;
|
||||
requestManager.complete(requestContext.id);
|
||||
|
||||
appendImages(images);
|
||||
appendImages(newImages);
|
||||
setImageLoadingState({
|
||||
isLoading: false,
|
||||
loadedCount: imageLoadingState.loadedCount + images.length,
|
||||
loadedCount: images.length + newImages.length,
|
||||
totalCount: total,
|
||||
hasMore: hasMore || false
|
||||
hasMore: hasMore || false,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.name === 'CanceledError' || error.name === 'AbortError') {
|
||||
@@ -88,7 +83,7 @@ function ImageWaterfall() {
|
||||
requestManager.error(requestContext.id);
|
||||
setImageLoadingState({ isLoading: false });
|
||||
}
|
||||
}, [currentLibraryId, imageLoadingState, selectedFolder, searchKeywords, filters, appendImages, setImageLoadingState]);
|
||||
}, [currentLibraryId, imageLoadingState, images.length, selectedFolder, searchKeywords, filters, appendImages, setImageLoadingState]);
|
||||
|
||||
// 监听容器宽度变化(使用 ResizeObserver + 去抖/阈值抑制)
|
||||
useEffect(() => {
|
||||
@@ -134,7 +129,7 @@ function ImageWaterfall() {
|
||||
if (containerRef.current) {
|
||||
resizeObserver = new ResizeObserver(() => {
|
||||
// 拖动时跳过更新,避免频繁重算布局
|
||||
if (useStore.getState().isResizingPanels) return;
|
||||
if (useUIStore.getState().isResizingPanels) return;
|
||||
measureAndEmit();
|
||||
});
|
||||
resizeObserver.observe(containerRef.current);
|
||||
@@ -175,115 +170,14 @@ function ImageWaterfall() {
|
||||
}
|
||||
}, [isResizingPanels]);
|
||||
|
||||
// 是否使用 Worker 计算布局
|
||||
const useWorker = filteredImages.length > WORKER_THRESHOLD;
|
||||
|
||||
// 跟踪图片数据变化,用于增量计算判断
|
||||
const prevImagesRef = useRef({ length: 0, firstId: null, libraryId: null });
|
||||
const incrementalModeRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const prevLen = prevImagesRef.current.length;
|
||||
const currLen = filteredImages.length;
|
||||
const prevFirstId = prevImagesRef.current.firstId;
|
||||
const currFirstId = filteredImages[0]?.id;
|
||||
const prevLibraryId = prevImagesRef.current.libraryId;
|
||||
|
||||
// 判断是否需要重置
|
||||
const shouldReset =
|
||||
(prevLen > 0 && currLen === 0) || // 图片被清空
|
||||
(currFirstId !== prevFirstId) || // 第一张图片变了(切换文件夹/素材库)
|
||||
(currentLibraryId !== prevLibraryId); // 素材库变了
|
||||
|
||||
if (shouldReset) {
|
||||
// 重置 Worker 状态
|
||||
setWorkerRows([]);
|
||||
requestIdRef.current = 0;
|
||||
incrementalModeRef.current = false;
|
||||
|
||||
// 通知 Worker 重置缓存
|
||||
if (workerRef.current) {
|
||||
workerRef.current.postMessage({ reset: true, requestId: 0 });
|
||||
}
|
||||
} else if (currLen > prevLen) {
|
||||
// 图片数量增加,可以使用增量模式
|
||||
incrementalModeRef.current = true;
|
||||
}
|
||||
|
||||
prevImagesRef.current = {
|
||||
length: currLen,
|
||||
firstId: currFirstId,
|
||||
libraryId: currentLibraryId
|
||||
};
|
||||
}, [filteredImages, currentLibraryId]);
|
||||
|
||||
// 初始化 Web Worker
|
||||
useEffect(() => {
|
||||
if (typeof Worker !== 'undefined') {
|
||||
workerRef.current = new Worker(
|
||||
new URL('../workers/layoutWorker.js', import.meta.url),
|
||||
{ type: 'module' }
|
||||
);
|
||||
|
||||
workerRef.current.onmessage = (e) => {
|
||||
const { rows, requestId } = e.data;
|
||||
// 只处理最新的请求结果
|
||||
if (requestId === requestIdRef.current) {
|
||||
setWorkerRows(rows);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (workerRef.current) {
|
||||
workerRef.current.terminate();
|
||||
workerRef.current = null;
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 使用 Worker 计算布局(大量图片时)
|
||||
useEffect(() => {
|
||||
if (!useWorker || !workerRef.current || !filteredImages.length || !containerWidth) {
|
||||
return;
|
||||
}
|
||||
|
||||
const requestId = ++requestIdRef.current;
|
||||
|
||||
// 只传输必要的字段,减少数据传输开销
|
||||
// 对于大量图片,这可以显著减少序列化/反序列化时间
|
||||
const minimalImages = filteredImages.map(img => ({
|
||||
id: img.id,
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
filename: img.filename,
|
||||
thumbnailPath: img.thumbnailPath,
|
||||
path: img.path,
|
||||
fileType: img.fileType,
|
||||
format: img.format
|
||||
}));
|
||||
|
||||
workerRef.current.postMessage({
|
||||
images: minimalImages,
|
||||
containerWidth,
|
||||
targetHeight: thumbnailHeight,
|
||||
requestId,
|
||||
incremental: incrementalModeRef.current
|
||||
});
|
||||
}, [filteredImages, containerWidth, thumbnailHeight, useWorker]);
|
||||
|
||||
// 同步计算布局(少量图片时直接在主线程计算)
|
||||
const syncRows = useMemo(() => {
|
||||
// 使用 Worker 时返回空数组,由 workerRows 提供数据
|
||||
if (useWorker) return [];
|
||||
|
||||
// 布局计算(始终在主线程同步执行)
|
||||
const rows = useMemo(() => {
|
||||
if (!filteredImages.length || !containerWidth) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const gap = 16;
|
||||
const targetHeight = thumbnailHeight;
|
||||
|
||||
const calculatedRows = [];
|
||||
let currentRow = [];
|
||||
let currentRowWidthSum = 0;
|
||||
@@ -354,10 +248,7 @@ function ImageWaterfall() {
|
||||
});
|
||||
|
||||
return calculatedRows;
|
||||
}, [filteredImages, thumbnailHeight, containerWidth, useWorker]);
|
||||
|
||||
// 统一使用的行数据:Worker 模式用 workerRows,否则用 syncRows
|
||||
const rows = useWorker ? workerRows : syncRows;
|
||||
}, [filteredImages, thumbnailHeight, containerWidth]);
|
||||
|
||||
const getThumbnailUrl = (image) => {
|
||||
// 后端已统一转换为 camelCase
|
||||
@@ -368,8 +259,8 @@ function ImageWaterfall() {
|
||||
}
|
||||
// 提取文件名(兼容反斜杠)
|
||||
const filename = thumbnailPath.replace(/\\/g, '/').split('/').pop();
|
||||
// 统一使用 480 尺寸(与 Billfish 一致)
|
||||
return imageAPI.getThumbnailUrl(currentLibraryId, '480', filename);
|
||||
// 使用分片结构,不再需要 size 参数
|
||||
return imageAPI.getThumbnailUrl(currentLibraryId, filename);
|
||||
};
|
||||
|
||||
const getOriginalUrl = (image) => {
|
||||
@@ -387,9 +278,12 @@ function ImageWaterfall() {
|
||||
|
||||
// 获取行高(用于虚拟滚动)
|
||||
const getRowHeight = useCallback((index) => {
|
||||
if (!rows[index] || rows[index].length === 0) return thumbnailHeight + 40;
|
||||
if (!rows || !rows[index] || rows[index].length === 0) {
|
||||
return thumbnailHeight + 40;
|
||||
}
|
||||
// 行高 = 图片高度 + 文件名区域 + 行间距
|
||||
return rows[index][0].calculatedHeight + 28 + 32;
|
||||
const firstImage = rows[index][0];
|
||||
return (firstImage?.calculatedHeight || thumbnailHeight) + 28 + 32;
|
||||
}, [rows, thumbnailHeight]);
|
||||
|
||||
// 跟踪上次的行数,用于增量更新虚拟列表
|
||||
@@ -402,11 +296,13 @@ function ImageWaterfall() {
|
||||
const currRowCount = rows.length;
|
||||
|
||||
if (currRowCount > prevRowCount && prevRowCount > 0) {
|
||||
// 增量更新:只重置新增的行
|
||||
// 从上一个最后一行开始重置(因为最后一行可能被重新计算)
|
||||
listRef.current.resetAfterIndex(Math.max(0, prevRowCount - 1));
|
||||
} else {
|
||||
// 完全重置
|
||||
// 增量更新:只重置新增的行,保持滚动位置
|
||||
const resetIndex = Math.max(0, prevRowCount - 1);
|
||||
listRef.current.resetAfterIndex(resetIndex);
|
||||
|
||||
// 不需要手动恢复滚动位置,react-window 会自动保持
|
||||
} else if (currRowCount !== prevRowCount) {
|
||||
// 完全重置(只在行数减少或首次加载时)
|
||||
listRef.current.resetAfterIndex(0);
|
||||
}
|
||||
|
||||
@@ -415,7 +311,10 @@ function ImageWaterfall() {
|
||||
}, [rows, useVirtualScroll]);
|
||||
|
||||
// 扁平化的图片列表(用于 Shift 多选)
|
||||
const flatImages = useMemo(() => rows.flat(), [rows]);
|
||||
const flatImages = useMemo(() => {
|
||||
if (!rows || rows.length === 0) return [];
|
||||
return rows.flat();
|
||||
}, [rows]);
|
||||
|
||||
// 处理图片点击(支持 Ctrl/Shift 多选)
|
||||
const handleImageClick = useCallback((image, event, imageIndex) => {
|
||||
@@ -535,6 +434,14 @@ function ImageWaterfall() {
|
||||
);
|
||||
};
|
||||
|
||||
// 加载中时显示空容器,避免闪烁"暂无图片"
|
||||
if (!filteredImages.length && imageLoadingState.isLoading) {
|
||||
return (
|
||||
<div ref={containerRef} className="h-full overflow-hidden" />
|
||||
);
|
||||
}
|
||||
|
||||
// 真正没有图片时才显示提示
|
||||
if (!filteredImages.length) {
|
||||
return (
|
||||
<div ref={containerRef} className="flex items-center justify-center h-full text-gray-500 dark:text-gray-400">
|
||||
@@ -546,18 +453,6 @@ function ImageWaterfall() {
|
||||
);
|
||||
}
|
||||
|
||||
// Worker 正在计算中,显示加载状态(只在容器宽度已知且 Worker 已触发时)
|
||||
if (useWorker && rows.length === 0 && filteredImages.length > 0 && containerWidth > 0) {
|
||||
return (
|
||||
<div ref={containerRef} className="flex items-center justify-center h-full text-gray-500 dark:text-gray-400">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin w-8 h-8 border-2 border-blue-500 border-t-transparent rounded-full mx-auto mb-2"></div>
|
||||
<p className="text-sm">正在计算布局...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 等待容器宽度初始化
|
||||
if (!containerWidth && filteredImages.length > 0) {
|
||||
return (
|
||||
@@ -575,7 +470,7 @@ function ImageWaterfall() {
|
||||
onIndexChange={setPhotoIndex}
|
||||
>
|
||||
{useVirtualScroll ? (
|
||||
/* 虚拟滚动模式(>500张图片) */
|
||||
/* 虚拟滚动模式 */
|
||||
<List
|
||||
ref={listRef}
|
||||
height={containerHeight || 600}
|
||||
@@ -583,14 +478,13 @@ function ImageWaterfall() {
|
||||
itemCount={rows.length}
|
||||
itemSize={getRowHeight}
|
||||
className="p-4"
|
||||
overscanCount={3}
|
||||
overscanCount={LOAD_CONFIG.overscanCount}
|
||||
onScroll={({ scrollOffset, scrollDirection }) => {
|
||||
// 滚动到接近底部时触发加载更多
|
||||
// 向下滚动:接近底部时加载更多
|
||||
if (scrollDirection === 'forward' && imageLoadingState.hasMore && !imageLoadingState.isLoading) {
|
||||
const totalHeight = rows.reduce((sum, _, i) => sum + getRowHeight(i), 0);
|
||||
const scrollBottom = scrollOffset + (containerHeight || 600);
|
||||
// 距离底部 500px 时触发加载
|
||||
if (totalHeight - scrollBottom < 500) {
|
||||
if (totalHeight - scrollBottom < LOAD_CONFIG.preloadThreshold) {
|
||||
loadMoreImages();
|
||||
}
|
||||
}
|
||||
@@ -603,10 +497,10 @@ function ImageWaterfall() {
|
||||
<div
|
||||
className="h-full overflow-y-auto p-4"
|
||||
onScroll={(e) => {
|
||||
// 滚动到接近底部时触发加载更多
|
||||
// 向下滚动:接近底部时加载更多
|
||||
if (imageLoadingState.hasMore && !imageLoadingState.isLoading) {
|
||||
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
||||
if (scrollHeight - scrollTop - clientHeight < 500) {
|
||||
if (scrollHeight - scrollTop - clientHeight < LOAD_CONFIG.preloadThreshold) {
|
||||
loadMoreImages();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
import { useEffect, useRef, useState, useCallback } from 'react';
|
||||
import { Pause, Play } from 'lucide-react';
|
||||
import useStore from '../store/useStore';
|
||||
import { imageAPI, scanAPI } from '../services/api';
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { useUIStore } from '../stores/useUIStore';
|
||||
import { useScanStore } from '../stores/useScanStore';
|
||||
import { imageAPI, scanAPI } from '../api';
|
||||
import { onUserActionStart, onUserActionEnd } from '../services/imageLoadService';
|
||||
import requestManager, { RequestType } from '../services/requestManager';
|
||||
import PaginationManager from '../utils/paginationManager';
|
||||
import imageCache from '../utils/imageCache';
|
||||
import domCleanup from '../utils/domCleanup';
|
||||
import ImageWaterfall from './ImageWaterfall';
|
||||
import Dashboard from './Dashboard';
|
||||
|
||||
function MainContent() {
|
||||
const {
|
||||
currentLibraryId,
|
||||
searchKeywords,
|
||||
filters,
|
||||
selectedFolder,
|
||||
setImages,
|
||||
scanProgress,
|
||||
imageLoadingState
|
||||
} = useStore();
|
||||
const { currentLibraryId } = useLibraryStore();
|
||||
const { searchKeywords, filters, selectedFolder, setImages, imageLoadingState, images } = useImageStore();
|
||||
const { scanProgress } = useScanStore();
|
||||
|
||||
// 使用 ref 跟踪最新的请求上下文
|
||||
const currentRequestContextRef = useRef(null);
|
||||
@@ -27,12 +24,6 @@ function MainContent() {
|
||||
// 扫描控制
|
||||
const [scanPaused, setScanPaused] = useState(false);
|
||||
const [isStoppingOrResuming, setIsStoppingOrResuming] = useState(false);
|
||||
|
||||
// 分页管理器 - 超激进内存控制
|
||||
const paginationManagerRef = useRef(new PaginationManager({
|
||||
pageSize: 100, // 每页100张图片(你的建议)
|
||||
windowSize: 200 // 内存窗口:最多保留200张,超过就释放旧的
|
||||
}));
|
||||
|
||||
// 计算预估剩余时间
|
||||
const getEstimatedTime = () => {
|
||||
@@ -54,15 +45,14 @@ function MainContent() {
|
||||
currentRequestContextRef.current = null;
|
||||
}, []);
|
||||
|
||||
// 加载图片 - 核心函数(使用分页)
|
||||
// 加载图片 - 核心函数(使用后端分页,前端不再维护本地分页窗口)
|
||||
const loadImages = useCallback(async (isInitialLoad = true) => {
|
||||
if (!currentLibraryId) return;
|
||||
|
||||
// 如果没有选中文件夹且没有搜索条件,显示 Dashboard
|
||||
if (!selectedFolder && !searchKeywords && filters.formats.length === 0) {
|
||||
setImages([]);
|
||||
paginationManagerRef.current.reset();
|
||||
useStore.getState().setImageLoadingState({
|
||||
useImageStore.getState().setImageLoadingState({
|
||||
isLoading: false,
|
||||
loadedCount: 0,
|
||||
totalCount: 0,
|
||||
@@ -71,9 +61,8 @@ function MainContent() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 初始加载时重置分页
|
||||
// 初始加载时重置本地缓存
|
||||
if (isInitialLoad) {
|
||||
paginationManagerRef.current.reset();
|
||||
imageCache.clear(); // 清理缓存
|
||||
}
|
||||
|
||||
@@ -85,34 +74,27 @@ function MainContent() {
|
||||
const requestContext = requestManager.createRequest(RequestType.IMAGES);
|
||||
currentRequestContextRef.current = requestContext;
|
||||
|
||||
// 设置加载状态
|
||||
const paginationState = paginationManagerRef.current.getCurrentState();
|
||||
useStore.getState().setImageLoadingState({
|
||||
isLoading: true,
|
||||
loadedCount: paginationState.loadedCount,
|
||||
totalCount: paginationState.totalCount,
|
||||
hasMore: paginationState.hasMore
|
||||
// 设置加载状态(保持当前计数不变,只更新 loading 标志)
|
||||
useImageStore.getState().setImageLoadingState({
|
||||
...imageLoadingState,
|
||||
isLoading: true
|
||||
});
|
||||
|
||||
try {
|
||||
// 使用分页管理器加载下一页
|
||||
const fetchFunction = async (libraryId, offset, limit) => {
|
||||
const params = { offset, limit };
|
||||
if (selectedFolder) params.folder = selectedFolder;
|
||||
if (searchKeywords) params.keywords = searchKeywords;
|
||||
if (filters.formats?.length > 0) params.formats = filters.formats.join(',');
|
||||
|
||||
const response = await imageAPI.search(libraryId, params, {
|
||||
signal: requestContext.signal
|
||||
});
|
||||
|
||||
return response.data;
|
||||
// 直接从后端加载一页数据(每次 100 张,更轻量)
|
||||
const params = {
|
||||
offset: isInitialLoad ? 0 : imageLoadingState.loadedCount,
|
||||
limit: 100
|
||||
};
|
||||
if (selectedFolder) params.folder = selectedFolder;
|
||||
if (searchKeywords) params.keywords = searchKeywords;
|
||||
if (filters.formats?.length > 0) params.formats = filters.formats.join(',');
|
||||
|
||||
const newImages = await paginationManagerRef.current.loadNextPage(
|
||||
fetchFunction,
|
||||
currentLibraryId
|
||||
);
|
||||
const response = await imageAPI.search(currentLibraryId, params, {
|
||||
signal: requestContext.signal
|
||||
});
|
||||
|
||||
const { images, total, hasMore } = response;
|
||||
|
||||
// 检查请求是否被取消
|
||||
if (!requestManager.isValid(requestContext.id)) {
|
||||
@@ -122,25 +104,23 @@ function MainContent() {
|
||||
// 标记请求完成
|
||||
requestManager.complete(requestContext.id);
|
||||
|
||||
// 获取所有已加载的图片
|
||||
const allLoadedImages = paginationManagerRef.current.getLoadedImages();
|
||||
|
||||
// 更新状态
|
||||
setImages(allLoadedImages);
|
||||
|
||||
const finalState = paginationManagerRef.current.getCurrentState();
|
||||
useStore.getState().setImageLoadingState({
|
||||
// 初次加载:设置图片数据
|
||||
if (isInitialLoad) {
|
||||
setImages(images);
|
||||
}
|
||||
|
||||
useImageStore.getState().setImageLoadingState({
|
||||
isLoading: false,
|
||||
loadedCount: finalState.loadedCount,
|
||||
totalCount: finalState.totalCount,
|
||||
hasMore: finalState.hasMore
|
||||
loadedCount: images.length,
|
||||
totalCount: total,
|
||||
hasMore: hasMore || false,
|
||||
});
|
||||
|
||||
console.log(`[MainContent] Loaded ${newImages.length} images, total: ${finalState.loadedCount}/${finalState.totalCount}`);
|
||||
console.log(`[MainContent] Loaded page: +${images.length}, total: ${(isInitialLoad ? images.length : imageLoadingState.loadedCount + images.length)}/${total}`);
|
||||
|
||||
// 如果还有更多数据,恢复空闲加载
|
||||
if (finalState.hasMore) {
|
||||
onUserActionEnd(finalState.hasMore);
|
||||
if (hasMore) {
|
||||
onUserActionEnd(hasMore);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
@@ -158,7 +138,7 @@ function MainContent() {
|
||||
}
|
||||
}, [currentLibraryId, searchKeywords, filters, selectedFolder, setImages, cancelCurrentRequest]);
|
||||
|
||||
// 监听文件夹变化
|
||||
// 监听文件夹/搜索/筛选变化
|
||||
useEffect(() => {
|
||||
if (!currentLibraryId) return;
|
||||
|
||||
@@ -170,9 +150,17 @@ function MainContent() {
|
||||
// 立即取消之前的请求(关键!)
|
||||
cancelCurrentRequest();
|
||||
|
||||
// 重置分页并清空图片,让 UI 快速响应
|
||||
paginationManagerRef.current.reset();
|
||||
// 清空当前图片并设置加载中状态(防止闪烁"暂无图片")
|
||||
setImages([]);
|
||||
useImageStore.getState().setImageLoadingState({
|
||||
isLoading: true, // 关键:立即设为加载中
|
||||
loadedCount: 0,
|
||||
totalCount: 0,
|
||||
hasMore: false
|
||||
});
|
||||
|
||||
// 清理图片缓存
|
||||
imageCache.clear();
|
||||
|
||||
// 使用防抖避免快速连续点击
|
||||
debounceTimerRef.current = setTimeout(() => {
|
||||
@@ -194,7 +182,6 @@ function MainContent() {
|
||||
clearTimeout(debounceTimerRef.current);
|
||||
}
|
||||
// DOM 清理:取消待加载的图片,清理事件监听器
|
||||
const domCleanup = require('../utils/domCleanup').default;
|
||||
domCleanup.cancelPendingLoads();
|
||||
domCleanup.removeAllEventListeners();
|
||||
};
|
||||
@@ -284,16 +271,16 @@ function MainContent() {
|
||||
)}
|
||||
|
||||
{/* Loading Progress */}
|
||||
{imageLoadingState.hasMore && imageLoadingState.loadedCount > 0 && (
|
||||
{imageLoadingState.totalCount > 0 && (
|
||||
<div className="px-4 py-2 bg-gray-100 dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span className="text-gray-600 dark:text-gray-400">
|
||||
已加载 {imageLoadingState.loadedCount} / {imageLoadingState.totalCount} 张
|
||||
已加载 {images.length} / {imageLoadingState.totalCount} 张
|
||||
</span>
|
||||
<div className="w-32 h-1.5 bg-gray-200 rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-blue-500"
|
||||
style={{ width: `${(imageLoadingState.loadedCount / imageLoadingState.totalCount) * 100}%` }}
|
||||
style={{ width: `${imageLoadingState.totalCount ? (images.length / imageLoadingState.totalCount) * 100 : 0}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Copy, Download, Check, FolderDown, ArrowLeft } from 'lucide-react';
|
||||
import useStore from '../store/useStore';
|
||||
import { imageAPI } from '../services/api';
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { useUIStore } from '../stores/useUIStore';
|
||||
import { useScanStore } from '../stores/useScanStore';
|
||||
import { imageAPI } from '../api';
|
||||
import JSZip from 'jszip';
|
||||
|
||||
function RightPanel() {
|
||||
const { selectedImage, selectedImages, currentLibraryId, selectedFolder, images, setMobileView, isResizingPanels, resizingSide } = useStore();
|
||||
const { currentLibraryId } = useLibraryStore();
|
||||
const { selectedImage, selectedImages, selectedFolder, images } = useImageStore();
|
||||
const { setMobileView, isResizingPanels, resizingSide } = useUIStore();
|
||||
const [isMobile, setIsMobile] = useState(false);
|
||||
const [imageUrl, setImageUrl] = useState(''); // 当前显示的图片URL
|
||||
const [isLoadingOriginal, setIsLoadingOriginal] = useState(false);
|
||||
@@ -15,9 +20,21 @@ function RightPanel() {
|
||||
const [isExportingFolder, setIsExportingFolder] = useState(false);
|
||||
const [folderExportProgress, setFolderExportProgress] = useState(0);
|
||||
|
||||
// 计算实际选中的图片数量(合并 selectedImage 和 selectedImages)
|
||||
const actualSelectedCount = (() => {
|
||||
if (selectedImages.length > 0) {
|
||||
// 检查 selectedImage 是否已经在 selectedImages 中
|
||||
if (selectedImage && !selectedImages.some(img => img.id === selectedImage.id)) {
|
||||
return selectedImages.length + 1;
|
||||
}
|
||||
return selectedImages.length;
|
||||
}
|
||||
return selectedImage ? 1 : 0;
|
||||
})();
|
||||
|
||||
// 判断是单选还是多选
|
||||
const isMultiSelect = selectedImages.length > 0;
|
||||
const displayImage = isMultiSelect ? selectedImages[0] : selectedImage;
|
||||
const isMultiSelect = actualSelectedCount > 1;
|
||||
const displayImage = selectedImages.length > 0 ? selectedImages[0] : selectedImage;
|
||||
|
||||
// 检测移动端
|
||||
useEffect(() => {
|
||||
@@ -81,14 +98,14 @@ function RightPanel() {
|
||||
}
|
||||
|
||||
const getThumbnailUrl = () => {
|
||||
if (!currentLibraryId || !selectedImage.thumbnail_path) return '';
|
||||
if (!currentLibraryId || !selectedImage?.thumbnail_path) return '';
|
||||
// Handle both forward and backslash
|
||||
const filename = selectedImage.thumbnail_path.replace(/\\/g, '/').split('/').pop();
|
||||
return imageAPI.getThumbnailUrl(currentLibraryId, '200', filename);
|
||||
return imageAPI.getThumbnailUrl(currentLibraryId, filename);
|
||||
};
|
||||
|
||||
const getOriginalUrl = () => {
|
||||
if (!currentLibraryId || !selectedImage.path) return '';
|
||||
if (!currentLibraryId || !selectedImage?.path) return '';
|
||||
return imageAPI.getOriginalUrl(currentLibraryId, selectedImage.path);
|
||||
};
|
||||
|
||||
@@ -414,10 +431,22 @@ function RightPanel() {
|
||||
});
|
||||
};
|
||||
|
||||
// 计算要操作的图片列表(合并 selectedImage 和 selectedImages,避免漏选)
|
||||
const getImagesToProcess = () => {
|
||||
if (selectedImages.length > 0) {
|
||||
// 如果有多选,检查 selectedImage 是否已经在列表中
|
||||
if (selectedImage && !selectedImages.some(img => img.id === selectedImage.id)) {
|
||||
return [selectedImage, ...selectedImages];
|
||||
}
|
||||
return selectedImages;
|
||||
}
|
||||
return selectedImage ? [selectedImage] : [];
|
||||
};
|
||||
|
||||
// 批量复制图片
|
||||
const copyMultipleImages = async () => {
|
||||
try {
|
||||
const imagesToCopy = isMultiSelect ? selectedImages : [selectedImage];
|
||||
const imagesToCopy = getImagesToProcess();
|
||||
|
||||
if (imagesToCopy.length === 1) {
|
||||
// 单张图片:直接复制
|
||||
@@ -507,7 +536,7 @@ function RightPanel() {
|
||||
const exportMultipleImages = async () => {
|
||||
setIsExporting(true);
|
||||
try {
|
||||
const imagesToExport = isMultiSelect ? selectedImages : [selectedImage];
|
||||
const imagesToExport = getImagesToProcess();
|
||||
|
||||
if (imagesToExport.length === 1) {
|
||||
// 单张图片直接下载
|
||||
@@ -755,12 +784,12 @@ function RightPanel() {
|
||||
{imageCopied ? (
|
||||
<>
|
||||
<Check className="w-4 h-4" />
|
||||
<span>已复制{isMultiSelect ? ` ${selectedImages.length} 张` : ''}</span>
|
||||
<span>已复制{isMultiSelect ? ` ${actualSelectedCount} 张` : ''}</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Copy className="w-4 h-4" />
|
||||
<span>复制图片{isMultiSelect ? ` (${selectedImages.length})` : ''}</span>
|
||||
<span>复制图片{isMultiSelect ? ` (${actualSelectedCount})` : ''}</span>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
@@ -776,7 +805,7 @@ function RightPanel() {
|
||||
<span>
|
||||
{isExporting
|
||||
? `打包中... ${exportProgress}%`
|
||||
: `导出图片${isMultiSelect ? ` (${selectedImages.length})` : ''}`
|
||||
: `导出图片${isMultiSelect ? ` (${actualSelectedCount})` : ''}`
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useState, useMemo, useEffect, useRef } from 'react';
|
||||
import { Folder, Search, ChevronRight, ChevronDown, X, Trash2, ChevronsRight, ChevronsDown } from 'lucide-react';
|
||||
import useStore from '../store/useStore';
|
||||
import { libraryAPI, scanAPI, imageAPI } from '../services/api';
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { useScanStore } from '../stores/useScanStore';
|
||||
import { libraryAPI, scanAPI, imageAPI } from '../api';
|
||||
import requestManager from '../services/requestManager';
|
||||
import { onUserActionStart } from '../services/imageLoadService';
|
||||
|
||||
@@ -16,17 +18,8 @@ const checkPausedScan = async (libraryId) => {
|
||||
};
|
||||
|
||||
function Sidebar() {
|
||||
const {
|
||||
libraries,
|
||||
currentLibraryId,
|
||||
folders,
|
||||
selectedFolder,
|
||||
totalImageCount,
|
||||
setCurrentLibrary,
|
||||
setSelectedFolder,
|
||||
addLibrary,
|
||||
removeLibrary
|
||||
} = useStore();
|
||||
const { libraries, currentLibraryId, setCurrentLibrary, addLibrary, removeLibrary } = useLibraryStore();
|
||||
const { folders, selectedFolder, totalImageCount, setSelectedFolder } = useImageStore();
|
||||
|
||||
const [showAddLibrary, setShowAddLibrary] = useState(false);
|
||||
const [newLibraryName, setNewLibraryName] = useState('');
|
||||
@@ -77,8 +70,8 @@ function Sidebar() {
|
||||
// 1. 添加素材库
|
||||
console.log('📝 添加素材库...');
|
||||
const response = await libraryAPI.add(newLibraryName.trim(), newLibraryPath.trim());
|
||||
const newLibId = response.data.id;
|
||||
const hasExistingIndex = response.data.hasExistingIndex;
|
||||
const newLibId = response.id;
|
||||
const hasExistingIndex = response.hasExistingIndex;
|
||||
|
||||
addLibrary({
|
||||
id: newLibId,
|
||||
@@ -99,13 +92,13 @@ function Sidebar() {
|
||||
setSelectedFolder(null);
|
||||
|
||||
// 4. 清空当前显示
|
||||
useStore.getState().setImages([]);
|
||||
useStore.getState().setFolders([]);
|
||||
useStore.getState().setSelectedImage(null);
|
||||
useStore.getState().setTotalImageCount(0); // 清空总数
|
||||
useImageStore.getState().setImages([]);
|
||||
useImageStore.getState().setFolders([]);
|
||||
useImageStore.getState().setSelectedImage(null);
|
||||
useImageStore.getState().setTotalImageCount(0); // 清空总数
|
||||
|
||||
// 5. 显示初始进度(立即显示,不等待后端)
|
||||
useStore.getState().setScanProgress({
|
||||
useScanStore.getState().setScanProgress({
|
||||
libraryId: newLibId,
|
||||
current: 0,
|
||||
total: 0,
|
||||
@@ -121,8 +114,8 @@ function Sidebar() {
|
||||
imageAPI.getFolders(newLibId),
|
||||
imageAPI.getCount(newLibId)
|
||||
]);
|
||||
useStore.getState().setFolders(foldersRes.data.folders);
|
||||
useStore.getState().setTotalImageCount(countRes.data.count);
|
||||
useImageStore.getState().setFolders(foldersRes.folders);
|
||||
useImageStore.getState().setTotalImageCount(countRes.count);
|
||||
console.log('✅ 已加载现有数据');
|
||||
} catch (err) {
|
||||
console.warn('⚠️ 加载现有数据失败:', err);
|
||||
@@ -145,7 +138,7 @@ function Sidebar() {
|
||||
} catch (error) {
|
||||
console.error('❌ Error adding library:', error);
|
||||
alert('添加素材库失败: ' + error.message);
|
||||
useStore.getState().setScanProgress(null);
|
||||
useScanStore.getState().setScanProgress(null);
|
||||
setIsAdding(false);
|
||||
}
|
||||
};
|
||||
@@ -160,15 +153,14 @@ function Sidebar() {
|
||||
requestManager.cancelAllRequests();
|
||||
|
||||
// 2. 清理当前素材库的状态(立即响应)
|
||||
useStore.getState().setScanProgress(null);
|
||||
useStore.getState().setSelectedImage(null);
|
||||
useStore.getState().setImages([]);
|
||||
useStore.getState().setFolders([]);
|
||||
useStore.getState().setImageLoadingState({
|
||||
useScanStore.getState().setScanProgress(null);
|
||||
useImageStore.getState().setSelectedImage(null);
|
||||
useImageStore.getState().setImages([]);
|
||||
useImageStore.getState().setFolders([]);
|
||||
useImageStore.getState().setImageLoadingState({
|
||||
isLoading: false,
|
||||
loadedCount: 0,
|
||||
totalCount: 0,
|
||||
hasMore: false
|
||||
});
|
||||
setSelectedFolder(null);
|
||||
|
||||
@@ -182,15 +174,15 @@ function Sidebar() {
|
||||
]);
|
||||
|
||||
// 5. 更新状态(包括 currentLibraryId,这样其他组件才会响应)
|
||||
useStore.getState().setFolders(foldersRes.data.folders);
|
||||
useStore.getState().setTotalImageCount(countRes.data.count);
|
||||
useImageStore.getState().setFolders(foldersRes.folders);
|
||||
useImageStore.getState().setTotalImageCount(countRes.count);
|
||||
setCurrentLibrary(libraryId); // 最后才更新 currentLibraryId
|
||||
|
||||
// 7. 后台检查新素材库是否有暂停的扫描(不阻塞主流程)
|
||||
checkPausedScan(libraryId).then(scanStatus => {
|
||||
if (scanStatus && scanStatus.status === 'paused') {
|
||||
if (scanStatus.needsRescan) {
|
||||
useStore.getState().setScanProgress({
|
||||
useScanStore.getState().setScanProgress({
|
||||
...scanStatus.progress,
|
||||
libraryId,
|
||||
canStop: true,
|
||||
@@ -200,7 +192,7 @@ function Sidebar() {
|
||||
});
|
||||
console.log(`⏸️ 发现中断的扫描,需要继续完成`);
|
||||
} else if (scanStatus.pendingCount > 0) {
|
||||
useStore.getState().setScanProgress({
|
||||
useScanStore.getState().setScanProgress({
|
||||
...scanStatus.progress,
|
||||
libraryId,
|
||||
canStop: true,
|
||||
@@ -214,7 +206,7 @@ function Sidebar() {
|
||||
} catch (error) {
|
||||
console.error('Error setting current library:', error);
|
||||
alert('切换素材库失败: ' + error.message);
|
||||
useStore.getState().setImageLoadingState({ isLoading: false });
|
||||
useImageStore.getState().setImageLoadingState({ isLoading: false });
|
||||
} finally {
|
||||
setIsSwitching(false);
|
||||
}
|
||||
@@ -241,14 +233,14 @@ function Sidebar() {
|
||||
|
||||
try {
|
||||
// 删除素材库(会自动关闭数据库连接)
|
||||
await libraryAPI.delete(currentLibraryId);
|
||||
await libraryAPI.remove(currentLibraryId);
|
||||
removeLibrary(currentLibraryId);
|
||||
|
||||
// Clear UI state
|
||||
useStore.getState().setImages([]);
|
||||
useStore.getState().setFolders([]);
|
||||
useStore.getState().setSelectedImage(null);
|
||||
useStore.getState().setSelectedFolder(null);
|
||||
useImageStore.getState().setImages([]);
|
||||
useImageStore.getState().setFolders([]);
|
||||
useImageStore.getState().setSelectedImage(null);
|
||||
useImageStore.getState().setSelectedFolder(null);
|
||||
|
||||
// Switch to first available library if exists
|
||||
const remainingLibs = libraries.filter(lib => lib.id !== currentLibraryId);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 前端常量配置
|
||||
*/
|
||||
|
||||
// 支持的图片格式
|
||||
export const IMAGE_FORMATS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'bmp', 'tiff'];
|
||||
|
||||
// 缩略图尺寸
|
||||
export const THUMBNAIL_SIZES = {
|
||||
SMALL: 200,
|
||||
MEDIUM: 480,
|
||||
LARGE: 800
|
||||
};
|
||||
|
||||
// 分页配置
|
||||
export const PAGINATION = {
|
||||
DEFAULT_PAGE_SIZE: 100,
|
||||
WINDOW_SIZE: 200
|
||||
};
|
||||
|
||||
// UI 配置
|
||||
export const UI = {
|
||||
MOBILE_BREAKPOINT: 768,
|
||||
SIDEBAR_MIN_WIDTH: 200,
|
||||
SIDEBAR_MAX_WIDTH: 400,
|
||||
SIDEBAR_DEFAULT_WIDTH: 256,
|
||||
PANEL_MIN_WIDTH: 280,
|
||||
PANEL_MAX_WIDTH: 500,
|
||||
PANEL_DEFAULT_WIDTH: 320
|
||||
};
|
||||
|
||||
// 防抖延迟
|
||||
export const DEBOUNCE = {
|
||||
SEARCH: 300,
|
||||
RESIZE: 150,
|
||||
FOLDER_SWITCH: 50
|
||||
};
|
||||
|
||||
// 缩略图高度范围
|
||||
export const THUMBNAIL_HEIGHT = {
|
||||
MIN: 150,
|
||||
MAX: 300,
|
||||
DEFAULT: 200
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* 防抖 Hook
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export function useDebounce(value, delay = 300) {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
setDebouncedValue(value);
|
||||
}, delay);
|
||||
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [value, delay]);
|
||||
|
||||
return debouncedValue;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* 图片 Hook
|
||||
*/
|
||||
|
||||
import { useState, useCallback, useRef } from 'react';
|
||||
import { useImageStore } from '../stores/useImageStore';
|
||||
import { imageAPI } from '../api';
|
||||
|
||||
export function useImages(libraryId) {
|
||||
const {
|
||||
images,
|
||||
setImages,
|
||||
appendImages,
|
||||
clearImages,
|
||||
setImageLoadingState
|
||||
} = useImageStore();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
const abortControllerRef = useRef(null);
|
||||
|
||||
/**
|
||||
* 加载图片
|
||||
*/
|
||||
const loadImages = useCallback(async (filters = {}, pagination = null) => {
|
||||
// 取消之前的请求
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
|
||||
abortControllerRef.current = new AbortController();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const params = { ...filters };
|
||||
if (pagination) {
|
||||
params.offset = pagination.offset;
|
||||
params.limit = pagination.limit;
|
||||
}
|
||||
|
||||
const response = await imageAPI.search(libraryId, params, {
|
||||
signal: abortControllerRef.current.signal
|
||||
});
|
||||
|
||||
// 分页追加或全量替换
|
||||
if (pagination && pagination.offset > 0) {
|
||||
appendImages(response.images || []);
|
||||
} else {
|
||||
setImages(response.images || []);
|
||||
}
|
||||
|
||||
// 更新加载状态
|
||||
if (response.total !== undefined) {
|
||||
setImageLoadingState({
|
||||
isLoading: false,
|
||||
loadedCount: response.images?.length || 0,
|
||||
totalCount: response.total,
|
||||
hasMore: response.hasMore || false
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (err) {
|
||||
if (err.name !== 'AbortError') {
|
||||
setError(err.message);
|
||||
throw err;
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
abortControllerRef.current = null;
|
||||
}
|
||||
}, [libraryId, setImages, appendImages, setImageLoadingState]);
|
||||
|
||||
/**
|
||||
* 取消加载
|
||||
*/
|
||||
const cancelLoading = useCallback(() => {
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* 清空图片
|
||||
*/
|
||||
const clear = useCallback(() => {
|
||||
clearImages();
|
||||
setImageLoadingState({
|
||||
isLoading: false,
|
||||
loadedCount: 0,
|
||||
totalCount: 0,
|
||||
hasMore: false
|
||||
});
|
||||
}, [clearImages, setImageLoadingState]);
|
||||
|
||||
return {
|
||||
images,
|
||||
loading,
|
||||
error,
|
||||
loadImages,
|
||||
cancelLoading,
|
||||
clear
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 素材库 Hook
|
||||
*/
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useLibraryStore } from '../stores/useLibraryStore';
|
||||
import { libraryAPI } from '../api';
|
||||
|
||||
export function useLibrary() {
|
||||
const {
|
||||
libraries,
|
||||
currentLibraryId,
|
||||
setLibraries,
|
||||
setCurrentLibrary,
|
||||
getCurrentLibrary
|
||||
} = useLibraryStore();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
/**
|
||||
* 加载所有素材库
|
||||
*/
|
||||
const loadLibraries = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await libraryAPI.getAll();
|
||||
setLibraries(response.libraries || []);
|
||||
setCurrentLibrary(response.currentLibraryId);
|
||||
return response;
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [setLibraries, setCurrentLibrary]);
|
||||
|
||||
/**
|
||||
* 创建素材库
|
||||
*/
|
||||
const createLibrary = useCallback(async (name, path) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const result = await libraryAPI.add(name, path);
|
||||
await loadLibraries(); // 重新加载列表
|
||||
return result;
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [loadLibraries]);
|
||||
|
||||
/**
|
||||
* 切换素材库
|
||||
*/
|
||||
const switchLibrary = useCallback(async (id) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await libraryAPI.setCurrent(id);
|
||||
setCurrentLibrary(id);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [setCurrentLibrary]);
|
||||
|
||||
/**
|
||||
* 删除素材库
|
||||
*/
|
||||
const deleteLibrary = useCallback(async (id) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await libraryAPI.remove(id);
|
||||
await loadLibraries(); // 重新加载列表
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [loadLibraries]);
|
||||
|
||||
return {
|
||||
libraries,
|
||||
currentLibraryId,
|
||||
currentLibrary: getCurrentLibrary(),
|
||||
loading,
|
||||
error,
|
||||
loadLibraries,
|
||||
createLibrary,
|
||||
switchLibrary,
|
||||
deleteLibrary
|
||||
};
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const API_BASE = '/api';
|
||||
|
||||
// Library API
|
||||
export const libraryAPI = {
|
||||
getAll: () => axios.get(`${API_BASE}/library`),
|
||||
add: (name, path) => axios.post(`${API_BASE}/library`, { name, path }),
|
||||
update: (id, updates) => axios.put(`${API_BASE}/library/${id}`, updates),
|
||||
delete: (id) => axios.delete(`${API_BASE}/library/${id}`),
|
||||
setCurrent: (id) => axios.post(`${API_BASE}/library/${id}/set-current`),
|
||||
updatePreferences: (preferences) => axios.put(`${API_BASE}/library/preferences`, preferences),
|
||||
updateTheme: (theme) => axios.put(`${API_BASE}/library/theme`, { theme })
|
||||
};
|
||||
|
||||
// Image API
|
||||
export const imageAPI = {
|
||||
search: (libraryId, params = {}, options = {}) => {
|
||||
const query = new URLSearchParams({
|
||||
libraryId,
|
||||
...params
|
||||
});
|
||||
return axios.get(`${API_BASE}/image?${query}`, options);
|
||||
},
|
||||
getCount: (libraryId) => axios.get(`${API_BASE}/image/count?libraryId=${libraryId}`),
|
||||
getStats: (libraryId) => axios.get(`${API_BASE}/image/stats?libraryId=${libraryId}`),
|
||||
getFolders: (libraryId) => axios.get(`${API_BASE}/image/folders?libraryId=${libraryId}`),
|
||||
getCacheMeta: (libraryId) => axios.get(`${API_BASE}/image/cache-meta?libraryId=${libraryId}`),
|
||||
getThumbnailUrl: (libraryId, size, filename) => `${API_BASE}/image/thumbnail/${libraryId}/${size}/${filename}`,
|
||||
getOriginalUrl: (libraryId, path) => `${API_BASE}/image/original/${libraryId}/${path}`,
|
||||
openInExplorer: (libraryId, path) => axios.post(`${API_BASE}/image/${libraryId}/open-file`, { path })
|
||||
};
|
||||
|
||||
// Scan API
|
||||
export const scanAPI = {
|
||||
fullScan: (libraryId, wait = false) => axios.post(`${API_BASE}/scan/full`, { libraryId, wait }),
|
||||
sync: (libraryId, wait = false) => axios.post(`${API_BASE}/scan/sync`, { libraryId, wait }),
|
||||
stop: (libraryId) => axios.post(`${API_BASE}/scan/stop`, { libraryId }),
|
||||
resume: (libraryId) => axios.post(`${API_BASE}/scan/resume`, { libraryId }),
|
||||
getStatus: (libraryId) => axios.get(`${API_BASE}/scan/status/${libraryId}`),
|
||||
fixFolders: (libraryId) => axios.post(`${API_BASE}/scan/fix-folders`, { libraryId })
|
||||
};
|
||||
|
||||
// Watch API
|
||||
export const watchAPI = {
|
||||
start: (libraryId) => axios.post(`${API_BASE}/watch/start/${libraryId}`),
|
||||
stop: (libraryId) => axios.post(`${API_BASE}/watch/stop/${libraryId}`),
|
||||
status: (libraryId) => axios.get(`${API_BASE}/watch/status/${libraryId}`),
|
||||
list: () => axios.get(`${API_BASE}/watch/list`)
|
||||
};
|
||||
@@ -1,178 +0,0 @@
|
||||
import { create } from 'zustand';
|
||||
import imageCache from '../utils/imageCache';
|
||||
import domCleanup from '../utils/domCleanup';
|
||||
|
||||
const useStore = create((set, get) => ({
|
||||
// Theme
|
||||
theme: 'light',
|
||||
setTheme: (theme) => set({ theme }),
|
||||
toggleTheme: () => set((state) => ({ theme: state.theme === 'light' ? 'dark' : 'light' })),
|
||||
|
||||
// Libraries
|
||||
libraries: [],
|
||||
currentLibraryId: null,
|
||||
setLibraries: (libraries) => set({ libraries }),
|
||||
|
||||
// 切换素材库时清理缓存
|
||||
setCurrentLibrary: (id) => {
|
||||
const state = get();
|
||||
if (state.currentLibraryId !== id) {
|
||||
console.log('[Store] Switching library, clearing caches...');
|
||||
imageCache.clear();
|
||||
domCleanup.revokeAllBlobUrls();
|
||||
}
|
||||
set({ currentLibraryId: id });
|
||||
},
|
||||
addLibrary: (library) => set((state) => ({ libraries: [...state.libraries, library] })),
|
||||
removeLibrary: (id) => set((state) => ({
|
||||
libraries: state.libraries.filter((lib) => lib.id !== id),
|
||||
currentLibraryId: state.currentLibraryId === id ? null : state.currentLibraryId
|
||||
})),
|
||||
|
||||
// Images (只存储轻量元数据)
|
||||
images: [],
|
||||
filteredImages: [],
|
||||
totalImageCount: 0, // 整个素材库的总图片数
|
||||
|
||||
// 设置图片(后端已统一转换为 camelCase,直接使用)
|
||||
setImages: (images) => {
|
||||
set({ images, filteredImages: images });
|
||||
},
|
||||
|
||||
setFilteredImages: (filteredImages) => set({ filteredImages }),
|
||||
setTotalImageCount: (count) => set({ totalImageCount: count }),
|
||||
|
||||
// 图片加载状态(用于分批加载)
|
||||
imageLoadingState: {
|
||||
isLoading: false,
|
||||
loadedCount: 0,
|
||||
totalCount: 0,
|
||||
hasMore: false
|
||||
},
|
||||
setImageLoadingState: (state) => set((prev) => ({
|
||||
imageLoadingState: { ...prev.imageLoadingState, ...state }
|
||||
})),
|
||||
|
||||
// 追加图片(用于分批加载)
|
||||
appendImages: (newImages) => set((state) => ({
|
||||
images: [...state.images, ...newImages],
|
||||
filteredImages: [...state.filteredImages, ...newImages]
|
||||
})),
|
||||
|
||||
// Folders (只存储路径和图片数量)
|
||||
folders: [],
|
||||
selectedFolder: null,
|
||||
|
||||
// 设置文件夹(后端已统一转换为 camelCase,直接使用)
|
||||
setFolders: (folders) => {
|
||||
set({ folders });
|
||||
},
|
||||
|
||||
// 切换文件夹时清理缓存
|
||||
setSelectedFolder: (folder) => {
|
||||
const state = get();
|
||||
if (state.selectedFolder !== folder) {
|
||||
console.log('[Store] Switching folder, clearing ALL data...');
|
||||
imageCache.clear();
|
||||
domCleanup.revokeAllBlobUrls();
|
||||
// 完全清空图片列表(真正的按需加载)
|
||||
set({
|
||||
selectedFolder: folder,
|
||||
images: [],
|
||||
filteredImages: []
|
||||
});
|
||||
return;
|
||||
}
|
||||
set({ selectedFolder: folder });
|
||||
},
|
||||
|
||||
// Search and filters
|
||||
searchKeywords: '',
|
||||
filters: {
|
||||
formats: [],
|
||||
minSize: null,
|
||||
maxSize: null,
|
||||
startDate: null,
|
||||
endDate: null
|
||||
},
|
||||
setSearchKeywords: (keywords) => set({ searchKeywords: keywords }),
|
||||
setFilters: (filters) => set((state) => ({ filters: { ...state.filters, ...filters } })),
|
||||
resetFilters: () => set({
|
||||
searchKeywords: '',
|
||||
filters: {
|
||||
formats: [],
|
||||
minSize: null,
|
||||
maxSize: null,
|
||||
startDate: null,
|
||||
endDate: null
|
||||
}
|
||||
}),
|
||||
|
||||
// Selected image (单选)
|
||||
selectedImage: null,
|
||||
setSelectedImage: (image) => set({ selectedImage: image }),
|
||||
|
||||
// Selected images (多选)
|
||||
selectedImages: [],
|
||||
setSelectedImages: (images) => set({ selectedImages: images }),
|
||||
toggleImageSelection: (image) => set((state) => {
|
||||
const isSelected = state.selectedImages.some(img => img.path === image.path);
|
||||
if (isSelected) {
|
||||
return { selectedImages: state.selectedImages.filter(img => img.path !== image.path) };
|
||||
} else {
|
||||
return { selectedImages: [...state.selectedImages, image] };
|
||||
}
|
||||
}),
|
||||
clearSelection: () => set({ selectedImages: [], selectedImage: null }),
|
||||
|
||||
// Scan progress
|
||||
scanProgress: null,
|
||||
scanStartTime: null, // 扫描开始时间
|
||||
setScanProgress: (progress) => set((state) => {
|
||||
// 第一次收到进度时记录开始时间
|
||||
if (progress && !state.scanStartTime && progress.current > 0) {
|
||||
return { scanProgress: progress, scanStartTime: Date.now() };
|
||||
}
|
||||
// 扫描结束时清空开始时间
|
||||
if (!progress) {
|
||||
return { scanProgress: null, scanStartTime: null };
|
||||
}
|
||||
return { scanProgress: progress };
|
||||
}),
|
||||
|
||||
// Panel resizing state(拖动侧边栏时置为 true,用于抑制重算)
|
||||
isResizingPanels: false,
|
||||
setIsResizingPanels: (value) => set({ isResizingPanels: value }),
|
||||
|
||||
// 正在拖动的侧边:'left' | 'right' | null
|
||||
resizingSide: null,
|
||||
setResizingSide: (side) => set({ resizingSide: side }),
|
||||
|
||||
// Thumbnail size
|
||||
thumbnailHeight: 200,
|
||||
setThumbnailHeight: (height) => set({ thumbnailHeight: height }),
|
||||
|
||||
// Mobile view state
|
||||
mobileView: 'main', // 'sidebar' | 'main' | 'detail'
|
||||
setMobileView: (view) => set({ mobileView: view }),
|
||||
|
||||
// Get current library
|
||||
getCurrentLibrary: () => {
|
||||
const state = get();
|
||||
return state.libraries.find((lib) => lib.id === state.currentLibraryId);
|
||||
},
|
||||
|
||||
// Image cache statistics
|
||||
getCacheStats: () => {
|
||||
return imageCache.getStats();
|
||||
},
|
||||
|
||||
// Clear all caches (for manual cleanup)
|
||||
clearAllCaches: () => {
|
||||
console.log('[Store] Clearing all caches...');
|
||||
imageCache.clear();
|
||||
domCleanup.cleanup();
|
||||
}
|
||||
}));
|
||||
|
||||
export default useStore;
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 图片状态管理
|
||||
* 简化版:只做向下无限滚动,依赖浏览器原生懒加载管理内存
|
||||
*/
|
||||
|
||||
import { create } from 'zustand';
|
||||
|
||||
export const useImageStore = create((set, get) => ({
|
||||
// 图片列表
|
||||
images: [],
|
||||
selectedImage: null,
|
||||
selectedImages: [],
|
||||
totalImageCount: 0,
|
||||
|
||||
// 文件夹
|
||||
folders: [],
|
||||
selectedFolder: null,
|
||||
|
||||
// 搜索和过滤
|
||||
searchKeywords: '',
|
||||
filters: {
|
||||
formats: [],
|
||||
minSize: null,
|
||||
maxSize: null,
|
||||
startDate: null,
|
||||
endDate: null
|
||||
},
|
||||
|
||||
// 加载状态
|
||||
imageLoadingState: {
|
||||
isLoading: false,
|
||||
loadedCount: 0,
|
||||
totalCount: 0,
|
||||
hasMore: false,
|
||||
},
|
||||
|
||||
// 图片操作
|
||||
setImages: (images) => set({ images }),
|
||||
|
||||
// 追加图片(向下滚动时)
|
||||
appendImages: (newImages) => set((state) => ({
|
||||
images: [...state.images, ...newImages]
|
||||
})),
|
||||
|
||||
clearImages: () => set({ images: [] }),
|
||||
|
||||
// 选择操作
|
||||
setSelectedImage: (image) => set({ selectedImage: image }),
|
||||
|
||||
setSelectedImages: (images) => set({ selectedImages: images }),
|
||||
|
||||
toggleImageSelection: (image) => set((state) => {
|
||||
const isSelected = state.selectedImages.some(img => img.path === image.path);
|
||||
return {
|
||||
selectedImages: isSelected
|
||||
? state.selectedImages.filter(img => img.path !== image.path)
|
||||
: [...state.selectedImages, image]
|
||||
};
|
||||
}),
|
||||
|
||||
clearSelection: () => set({ selectedImages: [], selectedImage: null }),
|
||||
|
||||
// 文件夹操作
|
||||
setFolders: (folders) => set({ folders }),
|
||||
|
||||
setSelectedFolder: (folder) => set({ selectedFolder: folder }),
|
||||
|
||||
// 搜索和过滤
|
||||
setSearchKeywords: (keywords) => set({ searchKeywords: keywords }),
|
||||
|
||||
setFilters: (filters) => set((state) => ({
|
||||
filters: { ...state.filters, ...filters }
|
||||
})),
|
||||
|
||||
resetFilters: () => set({
|
||||
searchKeywords: '',
|
||||
filters: {
|
||||
formats: [],
|
||||
minSize: null,
|
||||
maxSize: null,
|
||||
startDate: null,
|
||||
endDate: null
|
||||
}
|
||||
}),
|
||||
|
||||
// 统计
|
||||
setTotalImageCount: (count) => set({ totalImageCount: count }),
|
||||
|
||||
// 加载状态
|
||||
setImageLoadingState: (state) => set((prev) => ({
|
||||
imageLoadingState: { ...prev.imageLoadingState, ...state }
|
||||
}))
|
||||
}));
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 素材库状态管理
|
||||
*/
|
||||
|
||||
import { create } from 'zustand';
|
||||
|
||||
export const useLibraryStore = create((set, get) => ({
|
||||
// 状态
|
||||
libraries: [],
|
||||
currentLibraryId: null,
|
||||
|
||||
// 设置素材库列表
|
||||
setLibraries: (libraries) => set({ libraries }),
|
||||
|
||||
// 设置当前素材库
|
||||
setCurrentLibrary: (id) => set({ currentLibraryId: id }),
|
||||
|
||||
// 添加素材库
|
||||
addLibrary: (library) => set((state) => ({
|
||||
libraries: [...state.libraries, library]
|
||||
})),
|
||||
|
||||
// 移除素材库
|
||||
removeLibrary: (id) => set((state) => ({
|
||||
libraries: state.libraries.filter((lib) => lib.id !== id),
|
||||
currentLibraryId: state.currentLibraryId === id ? null : state.currentLibraryId
|
||||
})),
|
||||
|
||||
// 更新素材库
|
||||
updateLibrary: (id, updates) => set((state) => ({
|
||||
libraries: state.libraries.map((lib) =>
|
||||
lib.id === id ? { ...lib, ...updates } : lib
|
||||
)
|
||||
})),
|
||||
|
||||
// 获取当前素材库
|
||||
getCurrentLibrary: () => {
|
||||
const { libraries, currentLibraryId } = get();
|
||||
return libraries.find((lib) => lib.id === currentLibraryId);
|
||||
}
|
||||
}));
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 扫描状态管理
|
||||
*/
|
||||
|
||||
import { create } from 'zustand';
|
||||
|
||||
export const useScanStore = create((set, get) => ({
|
||||
// 扫描进度
|
||||
scanProgress: null,
|
||||
scanStartTime: null,
|
||||
|
||||
// 设置扫描进度
|
||||
setScanProgress: (progress) => set((state) => {
|
||||
// 第一次收到进度时记录开始时间
|
||||
if (progress && !state.scanStartTime && progress.current > 0) {
|
||||
return { scanProgress: progress, scanStartTime: Date.now() };
|
||||
}
|
||||
|
||||
// 扫描结束时清空开始时间
|
||||
if (!progress) {
|
||||
return { scanProgress: null, scanStartTime: null };
|
||||
}
|
||||
|
||||
return { scanProgress: progress };
|
||||
}),
|
||||
|
||||
// 清除扫描进度
|
||||
clearScanProgress: () => set({ scanProgress: null, scanStartTime: null }),
|
||||
|
||||
// 获取预估剩余时间
|
||||
getEstimatedTimeLeft: () => {
|
||||
const { scanProgress, scanStartTime } = get();
|
||||
|
||||
if (!scanProgress || !scanStartTime || scanProgress.current === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const elapsed = Date.now() - scanStartTime;
|
||||
const rate = scanProgress.current / elapsed; // 图片/毫秒
|
||||
const remaining = scanProgress.total - scanProgress.current;
|
||||
const estimatedMs = remaining / rate;
|
||||
|
||||
return Math.ceil(estimatedMs / 1000); // 返回秒数
|
||||
}
|
||||
}));
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* UI 状态管理
|
||||
*/
|
||||
|
||||
import { create } from 'zustand';
|
||||
|
||||
export const useUIStore = create((set) => ({
|
||||
// 主题
|
||||
theme: 'light',
|
||||
|
||||
// 移动端视图
|
||||
mobileView: 'main', // 'sidebar' | 'main' | 'detail'
|
||||
|
||||
// 缩略图高度
|
||||
thumbnailHeight: 200,
|
||||
|
||||
// 面板调整状态
|
||||
isResizingPanels: false,
|
||||
resizingSide: null, // 'left' | 'right' | null
|
||||
|
||||
// 主题操作
|
||||
setTheme: (theme) => set({ theme }),
|
||||
|
||||
toggleTheme: () => set((state) => ({
|
||||
theme: state.theme === 'light' ? 'dark' : 'light'
|
||||
})),
|
||||
|
||||
// 移动端视图
|
||||
setMobileView: (view) => set({ mobileView: view }),
|
||||
|
||||
// 缩略图高度
|
||||
setThumbnailHeight: (height) => set({ thumbnailHeight: height }),
|
||||
|
||||
// 面板调整
|
||||
setIsResizingPanels: (value) => set({ isResizingPanels: value }),
|
||||
|
||||
setResizingSide: (side) => set({ resizingSide: side })
|
||||
}));
|
||||
@@ -1,156 +0,0 @@
|
||||
/**
|
||||
* Pagination Manager
|
||||
* Manages paginated image loading with memory windowing
|
||||
*/
|
||||
|
||||
class PaginationManager {
|
||||
constructor(options = {}) {
|
||||
this.pageSize = options.pageSize || 50; // 50-100 images per page
|
||||
this.windowSize = options.windowSize || 200; // Keep 200 images max in memory
|
||||
this.currentPage = 0;
|
||||
this.loadedImages = [];
|
||||
this.totalCount = 0;
|
||||
this.hasMore = true;
|
||||
this.isLoading = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load next page of images
|
||||
* @param {Function} fetchFunction - Function to fetch images (libraryId, offset, limit)
|
||||
* @param {string} libraryId - Library ID
|
||||
* @returns {Promise<Array>} Loaded images
|
||||
*/
|
||||
async loadNextPage(fetchFunction, libraryId) {
|
||||
if (this.isLoading || !this.hasMore) {
|
||||
return [];
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
|
||||
try {
|
||||
const offset = this.currentPage * this.pageSize;
|
||||
const response = await fetchFunction(libraryId, offset, this.pageSize);
|
||||
|
||||
const { images, total, hasMore } = response;
|
||||
|
||||
// Update state
|
||||
this.loadedImages = [...this.loadedImages, ...images];
|
||||
this.totalCount = total;
|
||||
this.hasMore = hasMore;
|
||||
this.currentPage++;
|
||||
|
||||
// Apply memory windowing if needed
|
||||
this.applyMemoryWindow();
|
||||
|
||||
console.log(`[PaginationManager] Loaded page ${this.currentPage}, total: ${this.loadedImages.length}/${this.totalCount}`);
|
||||
|
||||
return images;
|
||||
} catch (error) {
|
||||
console.error('[PaginationManager] Error loading page:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply memory windowing: release old images when exceeding window size
|
||||
*/
|
||||
applyMemoryWindow() {
|
||||
if (this.loadedImages.length > this.windowSize) {
|
||||
const toRemove = this.loadedImages.length - this.windowSize;
|
||||
const removed = this.loadedImages.splice(0, toRemove);
|
||||
|
||||
console.log(`[PaginationManager] Memory window: removed ${removed.length} old images (${this.loadedImages.length} remaining)`);
|
||||
|
||||
// 立即清理缓存(真正释放内存)
|
||||
const imageCache = require('./imageCache').default;
|
||||
removed.forEach(img => {
|
||||
if (img.id) {
|
||||
imageCache.remove(img.id);
|
||||
}
|
||||
});
|
||||
|
||||
// Return removed images for cleanup
|
||||
return removed;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset pagination state
|
||||
*/
|
||||
reset() {
|
||||
this.currentPage = 0;
|
||||
this.loadedImages = [];
|
||||
this.totalCount = 0;
|
||||
this.hasMore = true;
|
||||
this.isLoading = false;
|
||||
|
||||
console.log('[PaginationManager] Pagination reset');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current pagination state
|
||||
* @returns {Object} Pagination state
|
||||
*/
|
||||
getCurrentState() {
|
||||
// Estimate memory usage: ~50KB per image metadata
|
||||
const memoryEstimate = this.loadedImages.length * 50 * 1024;
|
||||
|
||||
return {
|
||||
currentPage: this.currentPage,
|
||||
loadedCount: this.loadedImages.length,
|
||||
totalCount: this.totalCount,
|
||||
hasMore: this.hasMore,
|
||||
isLoading: this.isLoading,
|
||||
memoryEstimate,
|
||||
pageSize: this.pageSize,
|
||||
windowSize: this.windowSize
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get loaded images
|
||||
* @returns {Array} Loaded images
|
||||
*/
|
||||
getLoadedImages() {
|
||||
return this.loadedImages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set loaded images (for external updates)
|
||||
* @param {Array} images - Images to set
|
||||
*/
|
||||
setLoadedImages(images) {
|
||||
this.loadedImages = images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if should load next page based on scroll position
|
||||
* @param {number} scrollTop - Current scroll position
|
||||
* @param {number} scrollHeight - Total scroll height
|
||||
* @param {number} clientHeight - Visible height
|
||||
* @param {number} threshold - Distance from bottom to trigger load (default: 200px)
|
||||
* @returns {boolean} True if should load next page
|
||||
*/
|
||||
shouldLoadNextPage(scrollTop, scrollHeight, clientHeight, threshold = 200) {
|
||||
if (this.isLoading || !this.hasMore) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const distanceFromBottom = scrollHeight - (scrollTop + clientHeight);
|
||||
return distanceFromBottom < threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log pagination state (for debugging)
|
||||
*/
|
||||
logState() {
|
||||
const state = this.getCurrentState();
|
||||
console.log('[PaginationManager] State:', state);
|
||||
}
|
||||
}
|
||||
|
||||
export default PaginationManager;
|
||||
Reference in new issue
Block a user