feat(v1.3.0): 图片编辑器(裁剪/旋转/图像大小/调色) + 批量水印 + AI生图 + 收藏体系 + 图片新窗口打开按钮 + 合拼拼图 + 返回顶部

This commit is contained in:
jinghui committed 2026-11-17 23:36:32 +08:00
1 parent e345456abf
commit 94ac94436c
46 files changed
+6521 -114

No files matched your search

+105 -6
View File
@@ -1,5 +1,5 @@
import { useState, useEffect, useMemo, useRef } from 'react';
import { Sun, Moon, Search, Filter, Sliders, RefreshCw, Star, Bell, Github, Settings, ExternalLink } from 'lucide-react';
import { Sun, Moon, Search, Filter, Sliders, RefreshCw, ScanLine, Star, Bell, Github, Settings, ExternalLink, Wand2 } from 'lucide-react';
import { useLibraryStore } from '../stores/useLibraryStore';
import { useImageStore } from '../stores/useImageStore';
import { useUIStore } from '../stores/useUIStore';
@@ -8,6 +8,7 @@ import { useTheme } from '../hooks/useTheme';
import { useHub } from '../hooks/useHub';
import { libraryAPI, scanAPI, watchAPI } from '../api';
import SettingsModal from './SettingsModal';
import AIGenModal from './AIGenModal';
import { createLogger } from '../utils/logger';
const logger = createLogger('Header');
@@ -22,17 +23,22 @@ function Header() {
const [showFilters, setShowFilters] = useState(false);
const [isRefreshing, setIsRefreshing] = useState(false);
const [isRescanning, setIsRescanning] = useState(false);
// 扫描进行中时禁用"重新扫描"按钮
const scanProgress = useScanStore((s) => s.scanProgress);
const [isMobile, setIsMobile] = useState(false);
const [showMobileSettings, setShowMobileSettings] = useState(false);
const [localSearchValue, setLocalSearchValue] = useState(searchKeywords);
const [showNotices, setShowNotices] = useState(false);
const [showSettings, setShowSettings] = useState(false);
const [settingsTab, setSettingsTab] = useState('ocr');
const [showAIGen, setShowAIGen] = useState(false);
const searchDebounceRef = useRef(null);
// 授权系统 hub:版本 / 公告 / 在线人数
const hub = useHub();
const announcements = hub.announcements || [];
const appVersion = hub.version ? `v${String(hub.version).replace(/^v/, '')}` : 'v1.2.0';
const appVersion = hub.version ? `v${String(hub.version).replace(/^v/, '')}` : 'v1.3.0';
// 从全局 store 获取筛选状态
const selectedFormats = filters.formats || [];
@@ -40,6 +46,16 @@ function Header() {
const selectedOrientations = filters.orientations || [];
const selectedRatings = filters.ratings || [];
// 从 AI 生图弹窗跳设置(open:settings 事件,detail = 菜单 tab)
useEffect(() => {
const handler = (e) => {
setSettingsTab((e.detail && e.detail.tab) || 'ocr');
setShowSettings(true);
};
window.addEventListener('open:settings', handler);
return () => window.removeEventListener('open:settings', handler);
}, []);
// 检测移动端
useEffect(() => {
const checkMobile = () => {
@@ -262,9 +278,12 @@ function Header() {
setFilters({ ratings: newRatings });
};
const favoriteOnly = !!filters.favoriteOnly;
const toggleFavoriteOnly = () => setFilters({ favoriteOnly: !favoriteOnly });
// 清除筛选
const clearFilters = () => {
setFilters({ formats: [], sizes: [], orientations: [], ratings: [] });
setFilters({ formats: [], sizes: [], orientations: [], ratings: [], favoriteOnly: false });
};
const handleThumbnailHeightChange = async (height) => {
@@ -291,6 +310,26 @@ function Header() {
}
};
// 重新扫描:重新索引全部文件,并为缺少文字索引的旧图片补跑 OCR
const handleRescan = async () => {
if (!currentLibraryId || isRescanning || scanProgress) return;
if (!window.confirm('重新扫描将重新索引全部文件,并为缺少文字索引的图片补跑 OCR 识别。库越大耗时越长(进度会在页面上方显示),确认开始?')) {
return;
}
setIsRescanning(true);
try {
await scanAPI.fullScan(currentLibraryId);
// 扫描进度通过 Socket.IO 的 scanProgress 推送
} catch (error) {
console.error('Error rescan:', error);
alert('重新扫描失败: ' + error.message);
} finally {
setIsRescanning(false);
}
};
// 从 filterOptions 中提取可用选项
const availableFormats = filterOptions.formats;
const availableSizes = filterOptions.sizes.map(size => ({ label: size }));
@@ -371,6 +410,14 @@ function Header() {
)}
</div>
<button
onClick={() => setShowAIGen(true)}
title="AI 生图"
className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"
>
<Wand2 className="w-5 h-5 text-purple-600 dark:text-purple-400" />
</button>
<button
onClick={() => setShowSettings(true)}
title="设置"
@@ -383,7 +430,8 @@ function Header() {
{appVersion}
</span>
<SettingsModal open={showSettings} onClose={() => setShowSettings(false)} versionLabel={appVersion} />
<SettingsModal open={showSettings} onClose={() => setShowSettings(false)} versionLabel={appVersion} initialTab={settingsTab} />
<AIGenModal open={showAIGen} onClose={() => setShowAIGen(false)} />
</>
);
@@ -396,7 +444,7 @@ function Header() {
<header className="border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800">
{/* 顶部栏 */}
<div className="h-14 flex items-center justify-between px-4">
<h1 className="text-lg font-bold text-gray-900 dark:text-white">FlyPic</h1>
<h1 className="text-lg font-bold text-gray-900 dark:text-white">牛图</h1>
<div className="flex items-center gap-2">
<button
@@ -406,6 +454,15 @@ function Header() {
>
<RefreshCw className={`w-5 h-5 text-gray-700 dark:text-gray-300 ${isRefreshing ? 'animate-spin' : ''}`} />
</button>
<button
onClick={handleRescan}
disabled={!currentLibraryId || isRescanning || !!scanProgress}
className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors disabled:opacity-50"
title="重新扫描:重新索引全部文件并补跑 OCR 文字识别"
>
<ScanLine className={`w-5 h-5 text-gray-700 dark:text-gray-300 ${isRescanning || scanProgress ? 'animate-pulse' : ''}`} />
</button>
<button
onClick={() => setShowMobileSettings(!showMobileSettings)}
@@ -586,6 +643,22 @@ function Header() {
</div>
</div>
)}
{/* 收藏筛选 */}
<div>
<div className="text-xs text-gray-500 dark:text-gray-400 mb-2">收藏</div>
<div className="flex flex-wrap gap-2">
<button
onClick={toggleFavoriteOnly}
className={`px-2 py-1 text-xs rounded-full flex items-center gap-1 ${
favoriteOnly
? 'bg-amber-500 text-white'
: 'bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300'
}`}
>
<Star size={12} className={favoriteOnly ? 'fill-current' : ''} /> 只看收藏
</button>
</div>
</div>
</div>
)}
</header>
@@ -597,7 +670,7 @@ function Header() {
<header className="border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800">
<div className="h-14 flex items-center justify-between px-6">
<div className="flex-shrink-0">
<h1 className="text-xl font-bold text-gray-900 dark:text-white">FlyPic</h1>
<h1 className="text-xl font-bold text-gray-900 dark:text-white">牛图</h1>
<p className="text-xs text-gray-500 dark:text-gray-400">轻量快速的图片素材库管理</p>
</div>
@@ -661,6 +734,15 @@ function Header() {
>
<RefreshCw className={`w-5 h-5 text-gray-700 dark:text-gray-300 ${isRefreshing ? 'animate-spin' : ''}`} />
</button>
<button
onClick={handleRescan}
disabled={!currentLibraryId || isRescanning || !!scanProgress}
className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
title="重新扫描:重新索引全部文件并补跑 OCR 文字识别"
>
<ScanLine className={`w-5 h-5 text-gray-700 dark:text-gray-300 ${isRescanning || scanProgress ? 'animate-pulse' : ''}`} />
</button>
<button
onClick={toggleTheme}
@@ -798,6 +880,23 @@ function Header() {
)}
</div>
</div>
{/* 收藏筛选 */}
<div>
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-2">收藏</label>
<div className="flex flex-col gap-1.5">
<button
onClick={toggleFavoriteOnly}
className={`px-3 py-1.5 text-xs rounded transition-colors text-left flex items-center gap-1.5 ${
favoriteOnly
? 'bg-amber-500 text-white'
: 'bg-gray-200 dark:bg-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-300 dark:hover:bg-gray-500'
}`}
>
<Star size={14} className={favoriteOnly ? 'fill-current' : ''} /> 只看收藏
</button>
</div>
</div>
</div>
</div>
</div>