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

+43 -1
View File
@@ -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;
}
/**
+13 -1
View File
@@ -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);