v1.4.7: 类型文案全面去「张」——注册表驱动 countLabel/typeCountsOf,补 design/other 类型行,统计图例按注册表顺序展示

This commit is contained in:
jinghui committed 2026-11-18 22:30:57 +08:00
1 parent 58900d0d45
commit c59791f994
16 files changed
+215 -40

No files matched your search

+2
View File
@@ -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);
}
@@ -216,7 +216,7 @@ function BatchWatermarkModal({ isOpen, mode, folder, libraryId, onClose, onFinis
<span className="text-xs px-2 py-0.5 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 truncate max-w-[240px]">
{folder}
</span>
<span className="text-xs text-gray-400">{imageCount} 张图片</span>
<span className="text-xs text-gray-400">{imageCount} 个文件</span>
</div>
<button onClick={handleClose} className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700">
<X className="w-5 h-5 text-gray-500" />
@@ -517,7 +517,7 @@ function BatchWatermarkModal({ isOpen, mode, folder, libraryId, onClose, onFinis
className={`flex items-center gap-2 px-5 py-2.5 rounded-lg text-white text-sm disabled:opacity-50 disabled:cursor-not-allowed transition-colors ${accentBtn}`}
>
{starting ? <Loader2 className="w-4 h-4 animate-spin" /> : <Play className="w-4 h-4" />}
{imageCount === 0 ? '该文件夹没有图片' : `开始处理 ${imageCount} 张`}
{imageCount === 0 ? '该文件夹没有可处理的文件' : `开始处理 ${imageCount} 个文件`}
</button>
</>
)}
+18 -6
View File
@@ -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() {
<div className="bg-secondary rounded-xl p-6 shadow-sm border">
<div className="flex items-center gap-4">
<div className="p-3 bg-blue-100 rounded-lg text-accent">
<ImageIcon className="w-6 h-6" />
{(() => {
const types = orderedTypeEntries(typeCounts);
const StatIcon = types.length === 1 ? typeMeta(types[0][0]).icon : FileIcon;
return <StatIcon className="w-6 h-6" />;
})()}
</div>
<div>
<div className="text-2xl font-bold text-primary">{totalImageCount.toLocaleString()}</div>
<div className="text-sm text-tertiary">图片总数</div>
<div className="text-sm text-tertiary">{typeLabelOf(typeCounts)}总数</div>
{/* 分类型图例:由类型注册表自动渲染,新类型无需改代码 */}
<div className="text-xs text-tertiary mt-0.5 flex gap-2 flex-wrap">
{orderedTypeEntries(typeCounts)
.map(([t, n]) => (
<span key={t}>{typeMeta(t).label} {n.toLocaleString()}</span>
))}
</div>
</div>
</div>
</div>
@@ -87,7 +99,7 @@ function Dashboard() {
</div>
</div>
</div>
<div className="text-xs text-tertiary">{folder.imageCount || 0} 张图片</div>
<div className="text-xs text-tertiary">{countLabel(folder.imageCount || 0, folder.typeCounts)}</div>
</div>
))}
</div>
@@ -100,7 +112,7 @@ function Dashboard() {
<h3 className="text-lg font-medium text-primary mb-2">暂无文件夹</h3>
<p className="text-tertiary max-w-sm mx-auto">
{totalImageCount > 0
? `此素材库的 ${totalImageCount} 张图片没有子文件夹,已在下方瀑布视图中直接显示。`
? `此素材库的 ${countLabel(totalImageCount, typeCounts)} 没有子文件夹,已在下方瀑布视图中直接显示。`
: '您的素材库似乎是空的。请将图片添加到素材库目录中,系统会自动扫描。'}
</p>
</div>
+3 -3
View File
@@ -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() {
<Search className="absolute left-3 top-2.5 w-5 h-5 text-gray-400" />
<input
type="text"
placeholder="搜索图片...(支持 OCR 图内文字)"
placeholder="搜索文件...(支持 OCR 图内文字)"
value={searchKeywords}
onChange={(e) => 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() {
<Search className="absolute left-3 top-2.5 w-5 h-5 text-gray-400" />
<input
type="text"
placeholder="搜索图片...(支持 OCR 图内文字,多个关键词用空格分隔)"
placeholder="搜索文件...(支持 OCR 图内文字,多个关键词用空格分隔)"
value={localSearchValue}
onChange={(e) => 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"
+7 -3
View File
@@ -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 (
<div className="absolute bottom-4 left-1/2 -translate-x-1/2 z-30 flex items-center gap-3 bg-gray-900/90 dark:bg-gray-800/90 backdrop-blur text-white rounded-full pl-5 pr-2 py-2 shadow-2xl">
<span className="text-sm whitespace-nowrap">已选 {unionCount} 张图片</span>
<span className="text-sm whitespace-nowrap">已选 {countLabel(unionCount, unionTypeCounts)}</span>
<button
onClick={() => {
setMergeImages(union);
setEditingImage(union[0]);
// 合拼是图片功能:过滤出图片(与 AI 生成视频入口一致),视频/文档不进画布
const imgOnly = union.filter((img) => (img.fileType || 'image') === 'image');
setMergeImages(imgOnly);
setEditingImage(imgOnly[0] || union[0]);
clearSelection();
}}
className="flex items-center gap-1.5 px-4 py-1.5 rounded-full bg-blue-600 hover:bg-blue-700 text-sm font-medium transition-colors"
+2 -2
View File
@@ -208,7 +208,7 @@ function MainContent() {
/>
</div>
<div className="text-xs text-blue-600 dark:text-blue-400">
已处理 {scanProgress?.current || 0} / {scanProgress?.total || 0} 张图片
已处理 {scanProgress.processed} / {scanProgress.total} 个文件
{getEstimatedTime() && ` · ${getEstimatedTime()}`}
</div>
</div>
@@ -219,7 +219,7 @@ function MainContent() {
<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">
已加载 {images.length} / {imageLoadingState.totalCount} 张
已加载 {images.length} / {imageLoadingState.totalCount} 个文件
</span>
<div className="w-32 h-1.5 bg-gray-200 rounded-full overflow-hidden">
<div
+1 -1
View File
@@ -40,7 +40,7 @@ function RatingToast({ isVisible, rating, count, onClose, duration = 2000 }) {
</div>
<span className="text-sm font-medium">
{rating === 0 ? '已取消评分' : `已评 ${rating} 星`}
{count > 1 ? ` (${count} 张)` : ''}
{count > 1 ? ` (${count} 个)` : ''}
</span>
</div>
</div>
+19 -18
View File
@@ -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() {
)}
</div>
<div>
<span className="text-gray-500 dark:text-gray-400">包含图片:</span>
<p className="text-gray-900 dark:text-gray-100">{totalCount} 张(含子文件夹)</p>
<span className="text-gray-500 dark:text-gray-400">包含:</span>
<p className="text-gray-900 dark:text-gray-100">{countLabel(totalCount, folderTypeCounts)}(含子文件夹)</p>
</div>
<div>
<span className="text-gray-500 dark:text-gray-400">总大小:</span>
@@ -1212,7 +1215,7 @@ function RightPanel() {
<span>
{isExportingFolder
? `打包中... ${folderExportProgress}%`
: `导出文件夹 (${totalCount} 张)`
: `导出文件夹 (${countLabel(totalCount, folderTypeCounts)})`
}
</span>
</div>
@@ -1263,7 +1266,7 @@ function RightPanel() {
}
}
}}
title="双击查看第一张图片"
title="双击查看原文件"
>
{(() => {
const imagesToShow = getImagesToProcess().slice(0, 5);
@@ -1367,7 +1370,7 @@ function RightPanel() {
<div className="flex-1 overflow-y-auto p-4 space-y-4 min-h-0">
<div>
<h3 className="text-xs font-semibold text-gray-700 dark:text-gray-300 mb-2">
{isMultiSelect ? `已选择 ${actualSelectedCount} ${selectionHasVideo ? '个文件' : '张图片'}` : '基本信息'}
{isMultiSelect ? `已选择 ${countLabel(actualSelectedCount, selectionTypeCounts)}` : '基本信息'}
</h3>
<div className="space-y-2 text-xs">
{isMultiSelect ? (
@@ -1380,7 +1383,7 @@ function RightPanel() {
<>
<div>
<span className="text-gray-500 dark:text-gray-400">数量:</span>
<p className="text-gray-900 dark:text-gray-100 text-xs">{stats.count} {selectionHasVideo ? '个文件' : '张图片'}</p>
<p className="text-gray-900 dark:text-gray-100 text-xs">{countLabel(stats.count, selectionTypeCounts)}</p>
</div>
<div>
<span className="text-gray-500 dark:text-gray-400">评分:</span>
@@ -1581,7 +1584,7 @@ function RightPanel() {
</div>
{isMultiSelect && (
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1">
已选择 {actualSelectedCount} {selectionHasVideo ? '个文件' : '张图片'}的共同父路径
已选择 {countLabel(actualSelectedCount, selectionTypeCounts)}的共同父路径
</p>
)}
</div>
@@ -1623,15 +1626,13 @@ function RightPanel() {
{imageCopied ? (
<>
<Check className="w-4 h-4" />
<span>已复制{isMultiSelect ? ` ${actualSelectedCount} ${selectionHasVideo ? '个' : '张'}` : ''}</span>
<span>已复制{isMultiSelect ? ` ${countLabel(actualSelectedCount, selectionTypeCounts)}` : ''}</span>
</>
) : (
<>
<Copy className="w-4 h-4" />
<span>
{singleIsVideo
? '复制视频'
: `${selectionHasVideo ? '复制文件' : '复制图片'}${isMultiSelect ? ` (${actualSelectedCount})` : ''}`}
{`复制${singleIsVideo ? '视频' : selectionTypeLabel}${isMultiSelect ? ` (${actualSelectedCount})` : ''}`}
</span>
</>
)}
@@ -1648,7 +1649,7 @@ function RightPanel() {
<span>
{isExporting
? `打包中... ${exportProgress}%`
: `${singleIsVideo ? '导出视频' : selectionHasVideo ? '导出文件' : '导出图片'}${isMultiSelect ? ` (${actualSelectedCount})` : ''}`
: `导出${singleIsVideo ? '视频' : selectionTypeLabel}${isMultiSelect ? ` (${actualSelectedCount})` : ''}`
}
</span>
</div>
+1 -1
View File
@@ -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';
/**
+2
View File
@@ -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 }),
// 加载状态
+82
View File
@@ -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;
}