From 03fb69f892902d55c375e431771d1e51b8dd9e73 Mon Sep 17 00:00:00 2001 From: jinghui Date: Wed, 18 Nov 2026 12:47:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B9=B3=E9=93=BA=E5=BA=93(=E6=97=A0?= =?UTF-8?q?=E5=AD=90=E6=96=87=E4=BB=B6=E5=A4=B9)=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E8=BF=9B=E7=80=91=E5=B8=83=E8=A7=86=E5=9B=BE=20=E2=80=94=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9B=E5=85=A5=E5=BA=93=E5=90=8E=E8=AF=AF?= =?UTF-8?q?=E6=98=BE'=E7=B4=A0=E6=9D=90=E5=BA=93=E4=BC=BC=E4=B9=8E?= =?UTF-8?q?=E6=98=AF=E7=A9=BA=E7=9A=84'=E4=B8=94=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - useImageStore: 新增 foldersLoaded 标记,区分「文件夹加载中」与「确认无子文件夹」 - MainContent: 早退/渲染分支加条件 — folders 加载完成且为空时不再停 Dashboard,直接请求全部图片 - App: scan 回调 images=null 不再清空已显示图片 - Dashboard: 空文案按 totalImageCount 分流(有图时不再误报空库) --- frontend/src/App.jsx | 6 ++++-- frontend/src/components/Dashboard.jsx | 4 +++- frontend/src/components/MainContent.jsx | 10 +++++----- frontend/src/stores/useImageStore.js | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index e3bb702..df7e220 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -137,12 +137,14 @@ function App() { // 如果没有选中文件夹且没有搜索条件,不加载图片(保持在 Dashboard) (imageState.selectedFolder || imageState.searchKeywords || imageState.filters.formats.length > 0 || imageState.favoritesView) ? imageAPI.search(libraryId, params) - : Promise.resolve({ images: [] }), + : Promise.resolve({ images: null }), // null = 本次不刷新图片(平铺库由 MainContent 直接加载,避免清空已显示的图片) // 扫描完成后重新获取统计信息(包含 totalSize) imageAPI.getStats(libraryId) ]).then(([foldersRes, imagesRes, statsRes]) => { useImageStore.getState().setFolders(foldersRes.folders); - useImageStore.getState().setImages(imagesRes.images); + if (imagesRes.images) { + useImageStore.getState().setImages(imagesRes.images); + } useImageStore.getState().setTotalImageCount(statsRes.total || 0); useImageStore.getState().setTotalSize(statsRes.totalSize || 0); }).catch(err => { diff --git a/frontend/src/components/Dashboard.jsx b/frontend/src/components/Dashboard.jsx index f645b68..dc555d3 100644 --- a/frontend/src/components/Dashboard.jsx +++ b/frontend/src/components/Dashboard.jsx @@ -99,7 +99,9 @@ function Dashboard() {

暂无文件夹

- 您的素材库似乎是空的。请将图片添加到素材库目录中,系统会自动扫描。 + {totalImageCount > 0 + ? `此素材库的 ${totalImageCount} 张图片没有子文件夹,已在下方瀑布视图中直接显示。` + : '您的素材库似乎是空的。请将图片添加到素材库目录中,系统会自动扫描。'}

)} diff --git a/frontend/src/components/MainContent.jsx b/frontend/src/components/MainContent.jsx index dd2820e..e3dae46 100644 --- a/frontend/src/components/MainContent.jsx +++ b/frontend/src/components/MainContent.jsx @@ -15,7 +15,7 @@ const logger = createLogger('MainContent'); function MainContent() { const { currentLibraryId } = useLibraryStore(); - const { searchKeywords, filters, selectedFolder, favoritesView, setImages, setOriginalImages, imageLoadingState, images, refreshTick } = useImageStore(); + const { searchKeywords, filters, selectedFolder, favoritesView, setImages, setOriginalImages, imageLoadingState, images, refreshTick, folders, foldersLoaded } = useImageStore(); const { scanProgress } = useScanStore(); // 使用 ref 跟踪最新的请求上下文 @@ -47,8 +47,8 @@ function MainContent() { const loadImages = useCallback(async (isInitialLoad = true) => { if (!currentLibraryId) return; - // 如果没有选中文件夹且没有搜索条件,显示 Dashboard(「我的收藏」视图除外) - if (!selectedFolder && !searchKeywords && filters.formats.length === 0 && !favoritesView) { + // 如果没有选中文件夹且没有搜索条件,显示 Dashboard(「我的收藏」视图除外;无子文件夹的平铺库直接进瀑布) + if (!selectedFolder && !searchKeywords && filters.formats.length === 0 && !favoritesView && (!foldersLoaded || folders.length > 0)) { setImages([]); useImageStore.getState().setImageLoadingState({ isLoading: false, @@ -162,7 +162,7 @@ function MainContent() { clearTimeout(debounceTimerRef.current); } }; - }, [currentLibraryId, searchKeywords, selectedFolder, favoritesView, refreshTick, loadImages, cancelCurrentRequest]); + }, [currentLibraryId, searchKeywords, selectedFolder, favoritesView, refreshTick, folders, foldersLoaded, loadImages, cancelCurrentRequest]); // 恢复撤销前的文件夹状态 useEffect(() => { @@ -233,7 +233,7 @@ function MainContent() { {/* Content */}
- {(!selectedFolder && !searchKeywords && filters.formats.length === 0 && !favoritesView) ? ( + {(!selectedFolder && !searchKeywords && filters.formats.length === 0 && !favoritesView && (!foldersLoaded || folders.length > 0)) ? ( ) : ( diff --git a/frontend/src/stores/useImageStore.js b/frontend/src/stores/useImageStore.js index 5aa95c5..d6a2982 100644 --- a/frontend/src/stores/useImageStore.js +++ b/frontend/src/stores/useImageStore.js @@ -15,6 +15,7 @@ export const useImageStore = create((set, get) => ({ // 文件夹 folders: [], + foldersLoaded: false, // folders 是否已完成首次加载(区分「加载中」与「确认无文件夹」) selectedFolder: null, // 当前浏览的文件夹路径 selectedFolderItem: null, // 选中的文件夹对象(用于显示详情、操作等) @@ -82,7 +83,7 @@ export const useImageStore = create((set, get) => ({ clearSelection: () => set({ selectedImages: [], selectedImage: null, selectedFolderItem: null }), // 文件夹操作 - setFolders: (folders) => set({ folders }), + setFolders: (folders) => set({ folders, foldersLoaded: true }), setSelectedFolder: (folder) => set((state) => ({ selectedFolder: folder,