diff --git a/CHANGELOG.md b/CHANGELOG.md index a8a04e2..daa36d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # 更新日志 +## 2026-11-18 → v1.4.7 + +**文件类型自动识别(通用机制)**——原先统计卡、文件夹卡、多选条等多处硬编码「图片/N 张图片」,库里实际有图片/视频/文档三种类型(356 个文件被显示成「356 图片总数」)。现改为类型注册表驱动,**以后新增文件类型只需在注册表加一行,全站文案与统计自动识别**: + +- ✨ 新建 `frontend/src/utils/fileTypes.js` 类型注册表:image→图片/张、video→视频/个、document→文档/个、audio→音频/个,未知类型一律兜底「文件/个」;提供 `typeMeta`(单文件元信息)、`countLabel`(集合计数文案:单一类型→「102 张图片」,混合→「356 个文件」)、`typeLabelOf`(动词名词:复制图片/复制视频/复制文件自动切换)、`typeCountsOf`(从选中项聚合类型计数) +- ✨ 统计卡自动识别:图标与标题按库内实际类型显示(纯图库「图片总数」、混合库「文件总数」),下方分类型图例「图片 102 · 视频 181 · 文档 73」由注册表自动渲染,新类型自动出现 +- ✨ 文件夹卡与仪表盘提示句:「X 张图片」→ 按该文件夹实际内容显示(`countLabel`,含子目录分类型聚合,后端 `FolderModel.getTree()` 新增 `_attachTypeCounts`) +- ✨ 后端 `GET /api/image/stats` 新增 `typeCounts` 字段(按 file_type 分组计数) +- ✨ 右侧面板全部计数与动词文案通用化:已选择/基本信息/共同父路径/已复制/复制按钮/导出按钮 —— 消除 v1.4.4 的 `selectionHasVideo ? ... : ...` 硬编码分支(该变量已删除,零引用),选中集合含视频→「个文件/复制视频」、纯图→「张图片/复制图片」、文档→「复制文档」全自动 +- ✨ 多选工具条「已选 X 张图片」→ 按选中项类型自动(混合「个文件」);批量加水印「X 张图片」→「X 个文件」;扫描进度「X/Y 张图片」→「X/Y 个文件」;评分日志、双击查看 title 同步通用化 +- 🔍 搜索框 placeholder「搜索图片...」→「搜索文件...」(搜索本就覆盖全类型,OCR 说明保留) +- ✨ **右侧面板文件夹信息区(原截图问题点)**:「包含图片: X 张(含子文件夹)」→「包含: X 个视频/张图片/个文件(含子文件夹)」(由该文件夹实际类型自动);「导出文件夹 (X 张)」同步按类型 +- ✨ 加载进度「已加载 X/Y 张」→「已加载 X/Y 个文件」;评分 toast「(N 张)」→「(N 个)」;批量水印按钮「开始处理 N 张/该文件夹没有图片」→「开始处理 N 个文件/该文件夹没有可处理的文件」(与弹窗头部计数口径一致) +- ✨ 合拼入口过滤:多选点「合拼」只把图片送进画布(与 AI 生成视频入口同模式),视频/文档不参与,进入后由「至少需要 2 张图片」校验提示 +- 保留(功能输入校验,非数据展示):AI 生成视频「请至少选择 2 张图片」、合拼「至少需要 2 张图片」——这两个功能的输入确实限图片,且入口均已有类型过滤 +- ✨ 注册表与后端分类器完全对齐(backend thumbnail.js getFileType 共 6 类):补 design「设计」(psd/ai/sketch/fig…) 与 other「其他」两行——此前这两个类型在统计卡图例都兜底成「文件」导致出现两个重复的「文件 N」(如「我的素材」库 文件5/文件8);图例改按注册表固定顺序展示(orderedTypeEntries) +- 端到端实测:stats.typeCounts 正确、统计卡图例/文件夹卡「5 个视频」/右侧面板文件夹信息区/多选条浏览器核验 + ## 2026-11-18 → v1.4.6 - ✨ **文件夹右键新增「批量重命名文件」**:三种模式 —— 前面加(前缀)、后面加(后缀)、全部改名(原文件名整体替换,扩展名始终保留) diff --git a/backend/src/models/FolderModel.js b/backend/src/models/FolderModel.js index 2db912f..be9f2c8 100644 --- a/backend/src/models/FolderModel.js +++ b/backend/src/models/FolderModel.js @@ -35,7 +35,49 @@ class FolderModel extends BaseModel { if (diff !== 0) return diff; return String(b.name).localeCompare(String(a.name)); }); - return this._buildTree(folders); + return this._attachTypeCounts(this._buildTree(folders)); + } + + /** + * 给树中每个节点附着 typeCounts(按文件类型分组计数,含子目录) + * { image: 102, video: 181, document: 73 } + * 聚合范围与 updateImageCount 一致:本文件夹 + 所有子目录前缀 + * 供前端类型注册表自动识别渲染(新增类型无需改代码) + */ + _attachTypeCounts(tree) { + let rows = []; + try { + rows = this.db.prepare(` + SELECT folder, file_type, COUNT(*) as c + FROM images + GROUP BY folder, file_type + `).all(); + } catch { + return tree; // 查询失败时保持无 typeCounts,前端兜底"个文件" + } + const byFolder = new Map(); + for (const r of rows) { + if (!byFolder.has(r.folder)) byFolder.set(r.folder, {}); + const m = byFolder.get(r.folder); + const t = r.file_type || 'image'; + m[t] = (m[t] || 0) + r.c; + } + const walk = (nodes) => { + for (const n of nodes) { + const counts = {}; + for (const [f, m] of byFolder) { + if (f === n.path || f.startsWith(n.path + '/')) { + for (const [t, c] of Object.entries(m)) { + counts[t] = (counts[t] || 0) + c; + } + } + } + n.typeCounts = counts; + if (n.children && n.children.length) walk(n.children); + } + }; + walk(tree); + return tree; } /** diff --git a/backend/src/services/ImageService.js b/backend/src/services/ImageService.js index 62c992a..222d515 100644 --- a/backend/src/services/ImageService.js +++ b/backend/src/services/ImageService.js @@ -112,9 +112,21 @@ class ImageService { ORDER BY count DESC `).all(); + // 按文件类型分组计数(image/video/document/...),供前端类型注册表自动识别渲染 + const typeCountsList = db.db.prepare(` + SELECT file_type, COUNT(*) as count + FROM images + GROUP BY file_type + `).all(); + const typeCounts = {}; + for (const row of typeCountsList) { + typeCounts[row.file_type || 'image'] = row.count; + } + return { ...stats, - formats: formatStats + formats: formatStats, + typeCounts }; } finally { this.dbPool.release(library.path); diff --git a/backend/utils/hub.js b/backend/utils/hub.js index 7bdf79e..428a79e 100644 --- a/backend/utils/hub.js +++ b/backend/utils/hub.js @@ -16,7 +16,7 @@ const { getSettings } = require('./settings'); const HUB_URL = (process.env.HUB_URL || 'https://auth.88531.cn/api').replace(/\/+$/, ''); const HUB_PROJECT_ID = process.env.HUB_PROJECT_ID || ''; const HUB_API_KEY = process.env.HUB_API_KEY || ''; -const SITE_VERSION = process.env.SITE_VERSION || '1.4.6'; +const SITE_VERSION = process.env.SITE_VERSION || '1.4.7'; const TIMEOUT_MS = 8000; const state = { diff --git a/docker-compose.yml b/docker-compose.yml index dd5a941..80405a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: - HUB_API_KEY=${HUB_API_KEY:-} - NEWAPI_KEY=${NEWAPI_KEY:-} # 当前站点版本(与 frontend/package.json、CHANGELOG 保持一致,界面版本徽标来源) - - SITE_VERSION=1.4.6 + - SITE_VERSION=1.4.7 # 让容器经 host.docker.internal 访问宿主机的 AI 侧车 extra_hosts: - "host.docker.internal:host-gateway" diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 59ec6b2..73eddb1 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -149,6 +149,7 @@ function App() { } useImageStore.getState().setTotalImageCount(statsRes.total || 0); useImageStore.getState().setTotalSize(statsRes.totalSize || 0); + useImageStore.getState().setTypeCounts(statsRes.typeCounts); }).catch(err => { logger.error('扫描完成后加载数据失败:', err.message); }).finally(() => { @@ -188,6 +189,7 @@ function App() { // 注意:后端返回的字段是 total 和 totalSize useImageStore.getState().setTotalImageCount(statsResponse.total || 0); useImageStore.getState().setTotalSize(statsResponse.totalSize || 0); + useImageStore.getState().setTypeCounts(statsResponse.typeCounts); } catch (error) { logger.error('加载文件夹失败:', error.message); } diff --git a/frontend/src/components/BatchWatermarkModal.jsx b/frontend/src/components/BatchWatermarkModal.jsx index f8a5d7b..38b22b7 100644 --- a/frontend/src/components/BatchWatermarkModal.jsx +++ b/frontend/src/components/BatchWatermarkModal.jsx @@ -216,7 +216,7 @@ function BatchWatermarkModal({ isOpen, mode, folder, libraryId, onClose, onFinis {folder} - {imageCount} 张图片 + {imageCount} 个文件 )} diff --git a/frontend/src/components/Dashboard.jsx b/frontend/src/components/Dashboard.jsx index dc555d3..370673c 100644 --- a/frontend/src/components/Dashboard.jsx +++ b/frontend/src/components/Dashboard.jsx @@ -1,11 +1,12 @@ import React from 'react'; import { useLibraryStore } from '../stores/useLibraryStore'; import { useImageStore } from '../stores/useImageStore'; -import { Folder, Image as ImageIcon, HardDrive } from 'lucide-react'; +import { Folder, Image as ImageIcon, HardDrive, File as FileIcon } from 'lucide-react'; +import { countLabel, typeMeta, typeLabelOf, orderedTypeEntries } from '../utils/fileTypes'; function Dashboard() { const { currentLibraryId, getCurrentLibrary } = useLibraryStore(); - const { totalImageCount, totalSize, folders } = useImageStore(); + const { totalImageCount, totalSize, folders, typeCounts } = useImageStore(); const currentLibrary = getCurrentLibrary(); const folderCount = folders.length; @@ -35,11 +36,22 @@ function Dashboard() {
- + {(() => { + const types = orderedTypeEntries(typeCounts); + const StatIcon = types.length === 1 ? typeMeta(types[0][0]).icon : FileIcon; + return ; + })()}
{totalImageCount.toLocaleString()}
-
图片总数
+
{typeLabelOf(typeCounts)}总数
+ {/* 分类型图例:由类型注册表自动渲染,新类型无需改代码 */} +
+ {orderedTypeEntries(typeCounts) + .map(([t, n]) => ( + {typeMeta(t).label} {n.toLocaleString()} + ))} +
@@ -87,7 +99,7 @@ function Dashboard() { -
{folder.imageCount || 0} 张图片
+
{countLabel(folder.imageCount || 0, folder.typeCounts)}
))} @@ -100,7 +112,7 @@ function Dashboard() {

暂无文件夹

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

diff --git a/frontend/src/components/Header.jsx b/frontend/src/components/Header.jsx index 8445bf5..0995a46 100644 --- a/frontend/src/components/Header.jsx +++ b/frontend/src/components/Header.jsx @@ -38,7 +38,7 @@ function Header() { // 授权系统 hub:版本 / 公告 / 在线人数 const hub = useHub(); const announcements = hub.announcements || []; - const appVersion = hub.version ? `v${String(hub.version).replace(/^v/, '')}` : 'v1.4.6'; + const appVersion = hub.version ? `v${String(hub.version).replace(/^v/, '')}` : 'v1.4.7'; // 从全局 store 获取筛选状态 const selectedFormats = filters.formats || []; @@ -494,7 +494,7 @@ function Header() { handleSearchChange(e.target.value)} className="w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 text-sm" @@ -680,7 +680,7 @@ function Header() { handleSearchChange(e.target.value)} className="w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" diff --git a/frontend/src/components/ImageWaterfall.jsx b/frontend/src/components/ImageWaterfall.jsx index 060305d..f82ff04 100644 --- a/frontend/src/components/ImageWaterfall.jsx +++ b/frontend/src/components/ImageWaterfall.jsx @@ -27,6 +27,7 @@ import { useInfiniteScroll } from '../hooks/useInfiniteScroll'; // Utils import { filterImages } from '../utils/imageFilters'; +import { typeCountsOf, countLabel } from '../utils/fileTypes'; import { imageAPI, fileAPI } from '../api'; // Components @@ -536,13 +537,16 @@ onToggleFavorite={handleToggleFavorite} } const unionCount = union.length; if (unionCount <= 1) return null; + const unionTypeCounts = typeCountsOf(union); return (
- 已选 {unionCount} 张图片 + 已选 {countLabel(unionCount, unionTypeCounts)}
- 已处理 {scanProgress?.current || 0} / {scanProgress?.total || 0} 张图片 + 已处理 {scanProgress.processed} / {scanProgress.total} 个文件 {getEstimatedTime() && ` · ${getEstimatedTime()}`}
@@ -219,7 +219,7 @@ function MainContent() {
- 已加载 {images.length} / {imageLoadingState.totalCount} 张 + 已加载 {images.length} / {imageLoadingState.totalCount} 个文件
{rating === 0 ? '已取消评分' : `已评 ${rating} 星`} - {count > 1 ? ` (${count} 张)` : ''} + {count > 1 ? ` (${count} 个)` : ''}
diff --git a/frontend/src/components/RightPanel.jsx b/frontend/src/components/RightPanel.jsx index 983ed17..3c46cd0 100644 --- a/frontend/src/components/RightPanel.jsx +++ b/frontend/src/components/RightPanel.jsx @@ -9,6 +9,7 @@ import { imageAPI, fileAPI } from '../api'; import JSZip from 'jszip'; import RatingStars from './RatingStars'; import { createLogger } from '../utils/logger'; +import { typeMeta, typeCountsOf, countLabel, typeLabelOf } from '../utils/fileTypes'; const logger = createLogger('RightPanel'); @@ -321,7 +322,7 @@ function RightPanel() { setSelectedImages(updatedSelectedImages); } - logger.file(`已更新 ${paths.length} 张图片的评分为 ${newRating} 星`); + logger.file(`已更新 ${paths.length} 个文件的评分为 ${newRating} 星`); } catch (error) { logger.error('更新评分失败:', error); alert('更新评分失败: ' + (error.message || '未知错误')); @@ -779,8 +780,9 @@ function RightPanel() { return selectedImage ? [selectedImage] : []; }; - // 选中集合是否含视频(决定多选计数单位文案:视频用「个」,图片用「张」) - const selectionHasVideo = getImagesToProcess().some(img => img?.fileType === 'video'); + // 选中集合类型计数(由类型注册表驱动文案:图片/视频/文档…混合自动按"文件") + const selectionTypeCounts = typeCountsOf(getImagesToProcess()); + const selectionTypeLabel = typeLabelOf(selectionTypeCounts); // 批量复制图片 const copyMultipleImages = async () => { @@ -1095,15 +1097,16 @@ function RightPanel() { const totalCount = folderImages.length; const totalSize = folderImages.reduce((sum, img) => sum + (img.size || 0), 0); - - return { totalCount, totalSize }; + const folderTypeCounts = typeCountsOf(folderImages); + + return { totalCount, totalSize, folderTypeCounts }; }; // ========== 文件夹详情渲染 ========== if (isShowingFolder) { const folderPath = selectedFolderItem.path; const folderName = selectedFolderItem.name; - const { totalCount, totalSize } = getFolderStats(folderPath); + const { totalCount, totalSize, folderTypeCounts } = getFolderStats(folderPath); const fullPath = currentLibrary?.path ? normalizePath(`${currentLibrary.path}${getPathSeparator()}${folderPath}`) : folderPath; @@ -1160,8 +1163,8 @@ function RightPanel() { )}
- 包含图片: -

{totalCount} 张(含子文件夹)

+ 包含: +

{countLabel(totalCount, folderTypeCounts)}(含子文件夹)

总大小: @@ -1212,7 +1215,7 @@ function RightPanel() { {isExportingFolder ? `打包中... ${folderExportProgress}%` - : `导出文件夹 (${totalCount} 张)` + : `导出文件夹 (${countLabel(totalCount, folderTypeCounts)})` }
@@ -1263,7 +1266,7 @@ function RightPanel() { } } }} - title="双击查看第一张图片" + title="双击查看原文件" > {(() => { const imagesToShow = getImagesToProcess().slice(0, 5); @@ -1367,7 +1370,7 @@ function RightPanel() {

- {isMultiSelect ? `已选择 ${actualSelectedCount} ${selectionHasVideo ? '个文件' : '张图片'}` : '基本信息'} + {isMultiSelect ? `已选择 ${countLabel(actualSelectedCount, selectionTypeCounts)}` : '基本信息'}

{isMultiSelect ? ( @@ -1380,7 +1383,7 @@ function RightPanel() { <>
数量: -

{stats.count} {selectionHasVideo ? '个文件' : '张图片'}

+

{countLabel(stats.count, selectionTypeCounts)}

评分: @@ -1581,7 +1584,7 @@ function RightPanel() {
{isMultiSelect && (

- 已选择 {actualSelectedCount} {selectionHasVideo ? '个文件' : '张图片'}的共同父路径 + 已选择 {countLabel(actualSelectedCount, selectionTypeCounts)}的共同父路径

)}
@@ -1623,15 +1626,13 @@ function RightPanel() { {imageCopied ? ( <> - 已复制{isMultiSelect ? ` ${actualSelectedCount} ${selectionHasVideo ? '个' : '张'}` : ''} + 已复制{isMultiSelect ? ` ${countLabel(actualSelectedCount, selectionTypeCounts)}` : ''} ) : ( <> - {singleIsVideo - ? '复制视频' - : `${selectionHasVideo ? '复制文件' : '复制图片'}${isMultiSelect ? ` (${actualSelectedCount})` : ''}`} + {`复制${singleIsVideo ? '视频' : selectionTypeLabel}${isMultiSelect ? ` (${actualSelectedCount})` : ''}`} )} @@ -1648,7 +1649,7 @@ function RightPanel() { {isExporting ? `打包中... ${exportProgress}%` - : `${singleIsVideo ? '导出视频' : selectionHasVideo ? '导出文件' : '导出图片'}${isMultiSelect ? ` (${actualSelectedCount})` : ''}` + : `导出${singleIsVideo ? '视频' : selectionTypeLabel}${isMultiSelect ? ` (${actualSelectedCount})` : ''}` }
diff --git a/frontend/src/components/SettingsModal.jsx b/frontend/src/components/SettingsModal.jsx index 30aa2eb..663c8a2 100644 --- a/frontend/src/components/SettingsModal.jsx +++ b/frontend/src/components/SettingsModal.jsx @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'; import { X, ScanText, Info, Save, FlaskConical, Github, ExternalLink, Wand2 } from 'lucide-react'; import { settingsAPI } from '../api'; -const APP_VERSION = 'v1.4.6'; +const APP_VERSION = 'v1.4.7'; const REPO_URL = 'https://gitea.88531.cn/jinghui/flypic'; /** diff --git a/frontend/src/stores/useImageStore.js b/frontend/src/stores/useImageStore.js index d6a2982..a60d1f5 100644 --- a/frontend/src/stores/useImageStore.js +++ b/frontend/src/stores/useImageStore.js @@ -11,6 +11,7 @@ export const useImageStore = create((set, get) => ({ selectedImage: null, selectedImages: [], totalImageCount: 0, + typeCounts: {}, // 按文件类型计数 { image: 102, video: 181, document: 73 } totalSize: 0, // 素材库总大小(字节) // 文件夹 @@ -113,6 +114,7 @@ export const useImageStore = create((set, get) => ({ // 统计 setTotalImageCount: (count) => set({ totalImageCount: count }), + setTypeCounts: (counts) => set({ typeCounts: counts || {} }), setTotalSize: (size) => set({ totalSize: size }), // 加载状态 diff --git a/frontend/src/utils/fileTypes.js b/frontend/src/utils/fileTypes.js new file mode 100644 index 0000000..10fe033 --- /dev/null +++ b/frontend/src/utils/fileTypes.js @@ -0,0 +1,82 @@ +/** + * 文件类型注册表(单一数据源) + * + * 所有"图片/视频/文档…张/个"文案与图标都从这里取, + * 新增文件类型只需在 TABLE 加一行,全站文案与统计卡自动识别。 + */ +import { Image as ImageIcon, Video, FileText, File, Music, PenTool, HelpCircle } from 'lucide-react'; + +const TABLE = { + image: { label: '图片', unit: '张', icon: ImageIcon }, + video: { label: '视频', unit: '个', icon: Video }, + audio: { label: '音频', unit: '个', icon: Music }, + document: { label: '文档', unit: '个', icon: FileText }, + design: { label: '设计', unit: '个', icon: PenTool }, + other: { label: '其他', unit: '个', icon: HelpCircle }, +}; + +/** + * 按注册表顺序返回类型计数条目(图例等排序稳定展示用); + * 注册表之外的未知类型键附在末尾。 + * @param {Object} typeCounts - { image: 102, video: 181 } + * @returns {Array<[string, number]>} + */ +export function orderedTypeEntries(typeCounts) { + const c = typeCounts || {}; + const known = Object.keys(TABLE).filter((k) => (c[k] || 0) > 0).map((k) => [k, c[k]]); + const extra = Object.entries(c).filter(([k, n]) => n > 0 && !(k in TABLE)); + return [...known, ...extra]; +} + +/** 未知类型兜底:一律按"文件" */ +const FALLBACK = { label: '文件', unit: '个', icon: File }; + +/** + * 单个文件的类型元信息 + * @param {string} fileType - image | video | document | ... + * @returns {{label, unit, icon}} + */ +export function typeMeta(fileType) { + return TABLE[fileType] || FALLBACK; +} + +/** + * 从条目列表聚合类型计数 { image: 2, video: 1 } + * @param {Array<{fileType?: string}>} items + */ +export function typeCountsOf(items) { + const counts = {}; + for (const it of items || []) { + const t = it?.fileType || 'image'; + counts[t] = (counts[t] || 0) + 1; + } + return counts; +} + +/** + * 集合计数文案(按类型自动识别): + * - 单一已知类型:`102 张图片` / `181 个视频` + * - 多类型混合、未知类型、或没给计数:`356 个文件` + * + * @param {number} count - 总数 + * @param {Object} [typeCounts] - { image: 102, video: 181, document: 73 } + */ +export function countLabel(count, typeCounts) { + const entries = Object.entries(typeCounts || {}).filter(([, n]) => n > 0); + if (entries.length === 1) { + const { label, unit } = typeMeta(entries[0][0]); + return `${count} ${unit}${label}`; + } + return `${count} 个文件`; +} + +/** + * 集合的类型名词(用于"复制图片/导出视频"等动词文案): + * - 单一类型:'图片' / '视频' / '文档' + * - 多类型混合或未知:'文件' + */ +export function typeLabelOf(typeCounts) { + const entries = Object.entries(typeCounts || {}).filter(([, n]) => n > 0); + if (entries.length === 1) return typeMeta(entries[0][0]).label; + return FALLBACK.label; +}