修复 筛选不生效的问题

This commit is contained in:
Chen committed 2025-12-04 18:11:27 +08:00
1 parent 9b258e4abd
commit 9e26770e96
16 files changed
+159 -125

No files matched your search

+1 -1
View File
@@ -47,7 +47,7 @@
---
## [0.1.0] - 2024-11-XX
## [1.0.0] - 2024-11-XX
### 初始版本
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "flypic-backend",
"version": "0.1.0",
"version": "1.0.0",
"description": "FlyPic backend server",
"main": "server.js",
"scripts": {
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "flypic-backend",
"version": "0.1.0",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "flypic-backend",
"version": "0.1.0",
"version": "1.0.0",
"dependencies": {
"better-sqlite3": "^9.2.2",
"chokidar": "^3.6.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "flypic-backend",
"version": "0.1.0",
"version": "1.0.0",
"description": "FlyPic backend server",
"main": "server.js",
"scripts": {
@@ -61,7 +61,7 @@ class LibraryService {
} catch (writeError) {
console.log(`[LibraryService] No write permission: ${normalizedPath}`);
throw new ValidationError(
'无法访问该文件夹。请在飞牛 fnOS 的"数据共享"中将此文件夹添加到 FlyPic 应用的访问权限。',
'无法访问该文件夹。将此文件夹添加到 FlyPic 应用的访问权限。',
'permission'
);
}
@@ -69,7 +69,7 @@ class LibraryService {
if (readError.code === 'EACCES' || readError.code === 'EPERM') {
console.log(`[LibraryService] No access permission: ${normalizedPath}`);
throw new ValidationError(
'无法访问该文件夹。请在飞牛 fnOS 的"数据共享"中将此文件夹添加到 FlyPic 应用的访问权限。',
'无法访问该文件夹。将此文件夹添加到 FlyPic 应用的访问权限。',
'permission'
);
}
+1 -1
View File
@@ -1,5 +1,5 @@
appname=flypic
version=0.1.0
version=1.0.0
desc=飞图 - 专为飞牛 fnOS 设计的轻量、快速、稳定的图像素材检索浏览应用,支持数十万级别图片流畅浏览,非侵入式设计,100% 开源免费
arch=x86_64
display_name=FlyPic
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "flypic-frontend",
"version": "0.1.0",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
+24 -72
View File
@@ -8,18 +8,20 @@ import { libraryAPI, scanAPI, watchAPI } from '../api';
function Header() {
const { currentLibraryId } = useLibraryStore();
const { searchKeywords, images, selectedFolder, setSearchKeywords } = useImageStore();
const { searchKeywords, originalImages, selectedFolder, setSearchKeywords, filters, setFilters, resetFilters } = useImageStore();
const { theme, toggleTheme, thumbnailHeight, setThumbnailHeight, mobileView } = useUIStore();
const [showFilters, setShowFilters] = useState(false);
const [selectedFormats, setSelectedFormats] = useState([]);
const [selectedSizes, setSelectedSizes] = useState([]);
const [selectedOrientation, setSelectedOrientation] = useState('');
const [isRefreshing, setIsRefreshing] = useState(false);
const [isMobile, setIsMobile] = useState(false);
const [showMobileSettings, setShowMobileSettings] = useState(false);
const [localSearchValue, setLocalSearchValue] = useState(searchKeywords);
const searchDebounceRef = useRef(null);
// 从全局 store 获取筛选状态
const selectedFormats = filters.formats || [];
const selectedSizes = filters.sizes || [];
const selectedOrientation = filters.orientation || '';
// 检测移动端
useEffect(() => {
@@ -33,10 +35,8 @@ function Header() {
// 监听文件夹变化,自动清空筛选
useEffect(() => {
setSelectedFormats([]);
setSelectedSizes([]);
setSelectedOrientation('');
}, [selectedFolder]);
resetFilters();
}, [selectedFolder, resetFilters]);
// 🎯 内存优化:禁用前端启动 chokidar 文件监控
// 后端已经使用轻量级监控器(智能轮询),不需要前端启动
@@ -167,9 +167,9 @@ function Header() {
return false;
};
// 分析当前文件夹的所有图片,生成可选项(只在images变化时计算一次)
// 分析原始图片列表,生成可选项(基于 originalImages,不受筛选影响)
const filterOptions = useMemo(() => {
if (images.length === 0) {
if (originalImages.length === 0) {
return { formats: [], sizes: [], hasHorizontal: false, hasVertical: false };
}
@@ -178,7 +178,7 @@ function Header() {
let hasHorizontal = false;
let hasVertical = false;
images.forEach(img => {
originalImages.forEach(img => {
// 格式
if (img.format) {
formats.add(img.format.toLowerCase());
@@ -199,79 +199,31 @@ function Header() {
hasHorizontal,
hasVertical
};
}, [images]);
}, [originalImages]);
// 使用 useMemo 缓存筛选结果,避免重复计算
const filteredResult = useMemo(() => {
// 如果没有任何筛选条件,直接返回原始图片
if (selectedFormats.length === 0 &&
selectedSizes.length === 0 &&
!selectedOrientation) {
return images;
}
// 预先转换为 Set 以提高查找性能
const formatSet = new Set(selectedFormats);
const sizeSet = new Set(selectedSizes);
return images.filter(img => {
// 格式筛选
if (formatSet.size > 0) {
if (!formatSet.has(img.format?.toLowerCase())) {
return false;
}
}
// 文件大小筛选
if (sizeSet.size > 0) {
const sizeKB = img.size / 1024;
let matchesSize = false;
for (const range of sizeSet) {
if (matchSizeRange(sizeKB, range)) {
matchesSize = true;
break;
}
}
if (!matchesSize) return false;
}
// 横竖图筛选
if (selectedOrientation === 'horizontal') {
if (img.width <= img.height) return false;
} else if (selectedOrientation === 'vertical') {
if (img.height <= img.width) return false;
}
return true;
});
}, [images, selectedFormats, selectedSizes, selectedOrientation]);
// 注意:过滤逻辑已移至后端,这里的 filteredResult 仅用于显示统计
// 切换选项
// 切换选项 - 同步到全局 store
const toggleFormat = (format) => {
setSelectedFormats(prev =>
prev.includes(format) ? prev.filter(f => f !== format) : [...prev, format]
);
const newFormats = selectedFormats.includes(format)
? selectedFormats.filter(f => f !== format)
: [...selectedFormats, format];
setFilters({ formats: newFormats });
};
const toggleSize = (size) => {
setSelectedSizes(prev =>
prev.includes(size) ? prev.filter(s => s !== size) : [...prev, size]
);
const newSizes = selectedSizes.includes(size)
? selectedSizes.filter(s => s !== size)
: [...selectedSizes, size];
setFilters({ sizes: newSizes });
};
const toggleOrientation = (orientation) => {
setSelectedOrientation(prev => prev === orientation ? '' : orientation);
const newOrientation = selectedOrientation === orientation ? '' : orientation;
setFilters({ orientation: newOrientation });
};
// 清除筛选
const clearFilters = () => {
setSelectedFormats([]);
setSelectedSizes([]);
setSelectedOrientation('');
setFilters({ formats: [], sizes: [], orientation: '' });
};
const handleThemeToggle = async () => {
+75 -1
View File
@@ -14,6 +14,36 @@ import FileViewer from './FileViewer';
// 虚拟滚动阈值:超过此数量启用虚拟滚动
const VIRTUAL_SCROLL_THRESHOLD = 100;
// 解析大小字符串为 KB
const parseSizeToKB = (sizeStr) => {
const match = sizeStr.match(/^(\d+(?:\.\d+)?)(B|KB|MB|GB)$/);
if (!match) return 0;
const value = parseFloat(match[1]);
const unit = match[2];
switch (unit) {
case 'B': return value / 1024;
case 'KB': return value;
case 'MB': return value * 1024;
case 'GB': return value * 1024 * 1024;
default: return 0;
}
};
// 匹配大小范围
const matchSizeRange = (sizeKB, range) => {
if (range.startsWith('>')) {
const minStr = range.substring(1).trim();
const minKB = parseSizeToKB(minStr);
return sizeKB >= minKB;
} else if (range.includes(' - ')) {
const [minStr, maxStr] = range.split(' - ').map(s => s.trim());
const minKB = parseSizeToKB(minStr);
const maxKB = parseSizeToKB(maxStr);
return sizeKB >= minKB && sizeKB < maxKB;
}
return false;
};
// 加载配置
const LOAD_CONFIG = {
pageSize: 100, // 每次加载 100 张(更轻量)
@@ -29,8 +59,52 @@ function ImageWaterfall() {
searchKeywords, filters, appendImages, setImageLoadingState
} = useImageStore();
const filteredImages = images;
const { thumbnailHeight, isResizingPanels } = useUIStore();
// 前端筛选逻辑:基于 filters 过滤图片
const filteredImages = useMemo(() => {
const { formats, sizes, orientation } = filters;
// 如果没有任何筛选条件,直接返回原始图片
if ((!formats || formats.length === 0) &&
(!sizes || sizes.length === 0) &&
!orientation) {
return images;
}
return images.filter(img => {
// 格式筛选
if (formats && formats.length > 0) {
if (!formats.includes(img.format?.toLowerCase())) {
return false;
}
}
// 文件大小筛选
if (sizes && sizes.length > 0) {
const sizeKB = img.size / 1024;
let matchesSize = false;
for (const range of sizes) {
if (matchSizeRange(sizeKB, range)) {
matchesSize = true;
break;
}
}
if (!matchesSize) return false;
}
// 横竖图筛选
if (orientation === 'horizontal') {
if (img.width <= img.height) return false;
} else if (orientation === 'vertical') {
if (img.height <= img.width) return false;
}
return true;
});
}, [images, filters]);
const containerRef = useRef(null);
const listRef = useRef(null);
const [containerWidth, setContainerWidth] = useState(0);
+5 -4
View File
@@ -13,7 +13,7 @@ import Dashboard from './Dashboard';
function MainContent() {
const { currentLibraryId } = useLibraryStore();
const { searchKeywords, filters, selectedFolder, setImages, imageLoadingState, images } = useImageStore();
const { searchKeywords, filters, selectedFolder, setImages, setOriginalImages, imageLoadingState, images } = useImageStore();
const { scanProgress } = useScanStore();
// 使用 ref 跟踪最新的请求上下文
@@ -100,9 +100,10 @@ function MainContent() {
// 标记请求完成
requestManager.complete(requestContext.id);
// 初次加载:设置图片数据
// 初次加载:设置图片数据和原始图片(用于筛选选项)
if (isInitialLoad) {
setImages(images);
setOriginalImages(images);
}
useImageStore.getState().setImageLoadingState({
@@ -130,7 +131,7 @@ function MainContent() {
currentRequestContextRef.current = null;
}
}
}, [currentLibraryId, searchKeywords, filters, selectedFolder, setImages, cancelCurrentRequest]);
}, [currentLibraryId, searchKeywords, selectedFolder, setImages, setOriginalImages, cancelCurrentRequest]);
// 监听文件夹/搜索/筛选变化
useEffect(() => {
@@ -166,7 +167,7 @@ function MainContent() {
clearTimeout(debounceTimerRef.current);
}
};
}, [currentLibraryId, searchKeywords, filters, selectedFolder, loadImages, cancelCurrentRequest, setImages]);
}, [currentLibraryId, searchKeywords, selectedFolder, loadImages, cancelCurrentRequest, setImages]);
// 组件卸载时清理
useEffect(() => {
+13 -10
View File
@@ -20,12 +20,13 @@ export const useImageStore = create((set, get) => ({
searchKeywords: '',
filters: {
formats: [],
minSize: null,
maxSize: null,
startDate: null,
endDate: null
sizes: [], // 文件大小范围筛选
orientation: '', // 横竖图筛选: 'horizontal' | 'vertical' | ''
},
// 原始图片列表(用于生成筛选选项,不受筛选影响)
originalImages: [],
// 加载状态
imageLoadingState: {
isLoading: false,
@@ -37,12 +38,16 @@ export const useImageStore = create((set, get) => ({
// 图片操作
setImages: (images) => set({ images }),
// 设置原始图片(用于筛选选项)
setOriginalImages: (images) => set({ originalImages: images }),
// 追加图片(向下滚动时)
appendImages: (newImages) => set((state) => ({
images: [...state.images, ...newImages]
images: [...state.images, ...newImages],
originalImages: [...state.originalImages, ...newImages]
})),
clearImages: () => set({ images: [] }),
clearImages: () => set({ images: [], originalImages: [] }),
// 选择操作
setSelectedImage: (image) => set({ selectedImage: image }),
@@ -76,10 +81,8 @@ export const useImageStore = create((set, get) => ({
searchKeywords: '',
filters: {
formats: [],
minSize: null,
maxSize: null,
startDate: null,
endDate: null
sizes: [],
orientation: ''
}
}),
+4 -4
View File
@@ -1,12 +1,12 @@
{
"name": "flypic-monorepo",
"version": "0.1.0",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "flypic-monorepo",
"version": "0.1.0",
"version": "1.0.0",
"workspaces": [
"frontend",
"backend"
@@ -17,7 +17,7 @@
},
"backend": {
"name": "flypic-backend",
"version": "0.1.0",
"version": "1.0.0",
"dependencies": {
"better-sqlite3": "^9.2.2",
"chokidar": "^3.6.0",
@@ -35,7 +35,7 @@
},
"frontend": {
"name": "flypic-frontend",
"version": "0.1.0",
"version": "1.0.0",
"dependencies": {
"axios": "^1.6.2",
"jszip": "^3.10.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "flypic-monorepo",
"version": "0.1.0",
"version": "1.0.0",
"private": true,
"description": "FlyPic - A lightweight and fast image library manager for fnOS",
"workspaces": [
+25 -21
View File
@@ -101,34 +101,38 @@ console.log(' ⏳ 首次构建需要编译原生模块,约需 1-3 分钟...\
const dockerPath = toDockerPath(packServerDir);
// 使用 node:22-slim (Debian) 确保 glibc 兼容性
const dockerCmd = [
'docker run --rm',
`-v "${dockerPath}:/app"`,
'-w /app',
'node:22-slim',
'sh -c "' + [
// 安装编译工具
'apt-get update',
'apt-get install -y python3 make g++ --no-install-recommends',
// 配置 npm 镜像
'npm config set registry https://registry.npmmirror.com',
// 清理旧依赖并安装
'rm -rf node_modules package-lock.json',
'npm install --production',
// 显示结果
'echo ""',
'echo "=== 依赖安装完成 ==="',
'du -sh node_modules/'
].join(' && ') + '"'
].join(' ');
// 创建临时安装脚本
const installScript = `#!/bin/sh
set -e
apt-get update
apt-get install -y python3 make g++ --no-install-recommends
npm config set registry https://registry.npmmirror.com
rm -rf node_modules package-lock.json
npm install --production
echo
echo "=== 依赖安装完成 ==="
du -sh node_modules/
`;
const installScriptPath = path.join(packServerDir, 'install.sh');
fs.writeFileSync(installScriptPath, installScript.replace(/\r\n/g, '\n'), 'utf8');
const dockerCmd = `docker run --rm -v "${dockerPath}:/app" -w /app node:22-slim sh /app/install.sh`;
try {
run(dockerCmd, { cwd: root });
// 删除临时安装脚本
if (fs.existsSync(installScriptPath)) {
fs.unlinkSync(installScriptPath);
}
console.log('\n ✅ Linux 依赖安装成功');
console.log(' ✅ 包含 sharp-linux-x64 (glibc 版本)');
console.log(' ✅ 包含 better-sqlite3 (Linux 编译版本)\n');
} catch (error) {
// 删除临时安装脚本
if (fs.existsSync(installScriptPath)) {
fs.unlinkSync(installScriptPath);
}
console.error('\n ❌ Docker 构建失败');
console.error(' 错误:', error.message);
console.log('\n 请检查:');
+3 -3
View File
@@ -53,7 +53,7 @@ cd /vol1/1000/flypic
fnpack build
```
成功后会生成 `flypic_0.1.0_all.fpk` 文件。
成功后会生成 `flypic_1.0.0_all.fpk` 文件。
## 四、安装应用
@@ -65,7 +65,7 @@ fnpack build
### 方法二:命令行安装
```bash
appcenter-cli install-fpk flypic_0.1.0_all.fpk
appcenter-cli install-fpk flypic_1.0.0_all.fpk
```
## 五、配置应用
@@ -125,7 +125,7 @@ flypic/
### manifest (应用清单)
```
appname=flypic
version=0.1.0
version=1.0.0
desc=飞图 - 专为飞牛 fnOS 设计的轻量、快速、稳定的图像素材检索浏览应用
arch=x86_64
display_name=FlyPic