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

+174 -9
View File
@@ -1,8 +1,8 @@
import { useState, useEffect } from 'react';
import { X, ScanText, Info, Save, FlaskConical, Github, ExternalLink } from 'lucide-react';
import { X, ScanText, Info, Save, FlaskConical, Github, ExternalLink, Wand2 } from 'lucide-react';
import { settingsAPI } from '../api';
const APP_VERSION = 'v1.2.0';
const APP_VERSION = 'v1.3.0';
const REPO_URL = 'https://gitea.88531.cn/jinghui/flypic';
/**
@@ -10,20 +10,26 @@ const REPO_URL = 'https://gitea.88531.cn/jinghui/flypic';
* - OCR 识别:本地 tesseract / 线上接口切换、线上参数、测试
* - 关于:版本号 / 开源地址
*/
export default function SettingsModal({ open, onClose, versionLabel }) {
export default function SettingsModal({ open, onClose, versionLabel, initialTab }) {
const [active, setActive] = useState('ocr');
const [cfg, setCfg] = useState(null); // { provider, online:{url,model,apiKeyMasked} }
const [apiKeyInput, setApiKeyInput] = useState(''); // 新密钥(留空=保持原密钥)
const [ig, setIg] = useState(null); // imagegen 配置
const [igNewKey, setIgNewKey] = useState(''); // NewAPI 新密钥
const [igCustomKey, setIgCustomKey] = useState(''); // 自定义提供商新密钥
const [saving, setSaving] = useState(false);
const [testing, setTesting] = useState(false);
const [msg, setMsg] = useState(null); // { type, text }
useEffect(() => {
if (!open) return;
if (initialTab) setActive(initialTab);
setMsg(null);
setApiKeyInput('');
setIgNewKey('');
setIgCustomKey('');
settingsAPI.getSettings()
.then((d) => setCfg({
.then((d) => { setCfg({
provider: d?.provider || 'local',
online: {
url: d?.online?.url || 'https://ai.88531.cn/v1',
@@ -31,7 +37,21 @@ export default function SettingsModal({ open, onClose, versionLabel }) {
apiKeyMasked: d?.online?.apiKeyMasked || ''
},
telemetry: d?.telemetry !== false
}))
});
setIg({
provider: d?.imagegen?.provider || 'newapi',
newapi: {
url: d?.imagegen?.newapi?.url || 'http://192.168.68.19:3099/v1',
apiKeyMasked: d?.imagegen?.newapi?.apiKeyMasked || '',
hasKey: !!d?.imagegen?.newapi?.hasKey
},
custom: {
url: d?.imagegen?.custom?.url || '',
model: d?.imagegen?.custom?.model || '',
apiKeyMasked: d?.imagegen?.custom?.apiKeyMasked || ''
}
});
})
.catch((e) => setMsg({ type: 'error', text: '读取设置失败: ' + (e.data?.message || e.message) }));
}, [open]);
@@ -51,11 +71,42 @@ export default function SettingsModal({ open, onClose, versionLabel }) {
model: cfg.online.model,
apiKey: apiKeyInput // 空字符串 = 保留原密钥
}
}
},
...(ig ? {
imagegen: {
provider: ig.provider,
newapi: {
url: ig.newapi.url,
apiKey: igNewKey || '' // 空 = 保持原密钥
},
custom: {
url: ig.custom.url,
model: ig.custom.model,
apiKey: igCustomKey || ''
}
}
} : {})
};
const data = await settingsAPI.updateSettings(payload);
setCfg((c) => ({ ...(c || {}), ...data, online: { ...(c?.online || {}), ...(data?.online || {}) } }));
if (data?.imagegen) {
setIg({
provider: data.imagegen.provider || 'newapi',
newapi: {
url: data.imagegen.newapi?.url || '',
apiKeyMasked: data.imagegen.newapi?.apiKeyMasked || '',
hasKey: !!data.imagegen.newapi?.hasKey
},
custom: {
url: data.imagegen.custom?.url || '',
model: data.imagegen.custom?.model || '',
apiKeyMasked: data.imagegen.custom?.apiKeyMasked || ''
}
});
}
setApiKeyInput('');
setIgNewKey('');
setIgCustomKey('');
setMsg({ type: 'ok', text: '已保存,新配置立即生效' });
} catch (e) {
setMsg({ type: 'error', text: '保存失败: ' + (e.data?.message || e.message) });
@@ -90,6 +141,7 @@ export default function SettingsModal({ open, onClose, versionLabel }) {
const menus = [
{ key: 'ocr', label: 'OCR 识别', icon: ScanText },
{ key: 'aigen', label: 'AI 生图', icon: Wand2 },
{ key: 'about', label: '关于', icon: Info }
];
@@ -122,7 +174,7 @@ export default function SettingsModal({ open, onClose, versionLabel }) {
<div className="flex-1 p-6 overflow-y-auto">
<div className="flex items-center justify-between mb-4">
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">
{active === 'ocr' ? 'OCR 识别设置' : '关于'}
{active === 'ocr' ? 'OCR 识别设置' : active === 'aigen' ? 'AI 生图设置' : '关于'}
</h2>
<button onClick={onClose} className="p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700">
<X className="w-5 h-5 text-gray-500" />
@@ -230,6 +282,119 @@ export default function SettingsModal({ open, onClose, versionLabel }) {
</div>
)}
{active === 'aigen' && cfg && ig && (
<div className="space-y-5">
<p className="text-xs text-gray-500 dark:text-gray-400">
AI 生图默认走内置 NewAPI(Pollinations + CF Workers AI 两个生图渠道);也可以切换到自己的 OpenAI 兼容提供商。密钥只保存在本机,不出服务器。
</p>
<div>
<div className="text-xs font-medium text-gray-600 dark:text-gray-400 mb-2">生图通道</div>
<div className="space-y-2">
<label className="flex items-start gap-2.5 p-3 border border-gray-200 dark:border-gray-700 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50">
<input
type="radio"
className="mt-0.5"
checked={ig.provider === 'newapi'}
onChange={() => setIg((v) => ({ ...v, provider: 'newapi' }))}
/>
<span>
<span className="block text-sm font-medium text-gray-900 dark:text-white">内置 NewAPI(推荐)</span>
<span className="block text-xs text-gray-500 dark:text-gray-400 mt-0.5">
Pollinations / CF Workers AI 两大生图模型,开箱即用
{ig.newapi.hasKey ? ',Key 已配置' : ',未配置 Key'}
</span>
</span>
</label>
<label className="flex items-start gap-2.5 p-3 border border-gray-200 dark:border-gray-700 rounded-lg cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50">
<input
type="radio"
className="mt-0.5"
checked={ig.provider === 'custom'}
onChange={() => setIg((v) => ({ ...v, provider: 'custom' }))}
/>
<span>
<span className="block text-sm font-medium text-gray-900 dark:text-white">自定义提供商</span>
<span className="block text-xs text-gray-500 dark:text-gray-400 mt-0.5">任意 OpenAI 兼容 /v1/images/generations 接口(OpenAI、Stability、中转站等)</span>
</span>
</label>
</div>
</div>
{ig.provider === 'newapi' && (
<div className="space-y-3 p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700">
<div>
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">接口地址</label>
<input
type="text"
value={ig.newapi.url}
onChange={(e) => setIg((v) => ({ ...v, newapi: { ...v.newapi, url: e.target.value } }))}
placeholder="http://192.168.68.19:3099/v1(默认)"
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
/>
</div>
<div>
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">API Key</label>
<input
type="password"
value={igNewKey}
onChange={(e) => setIgNewKey(e.target.value)}
placeholder={ig.newapi.apiKeyMasked ? `已配置(${ig.newapi.apiKeyMasked}),留空保持不变` : 'NewAPI 令牌(留空则用服务器环境变量)'}
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
/>
</div>
</div>
)}
{ig.provider === 'custom' && (
<div className="space-y-3 p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700">
<div>
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">接口地址</label>
<input
type="text"
value={ig.custom.url}
onChange={(e) => setIg((v) => ({ ...v, custom: { ...v.custom, url: e.target.value } }))}
placeholder="https://api.openai.com/v1"
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
/>
</div>
<div>
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">模型名称</label>
<input
type="text"
value={ig.custom.model}
onChange={(e) => setIg((v) => ({ ...v, custom: { ...v.custom, model: e.target.value } }))}
placeholder="gpt-image-1 / flux-dev / stable-diffusion-xl ..."
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
/>
</div>
<div>
<label className="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">API Key</label>
<input
type="password"
value={igCustomKey}
onChange={(e) => setIgCustomKey(e.target.value)}
placeholder={ig.custom.apiKeyMasked ? `已配置(${ig.custom.apiKeyMasked}),留空保持不变` : 'sk-...'}
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
/>
</div>
</div>
)}
<div className="flex items-center gap-3">
<button
onClick={handleSave}
disabled={saving}
className="flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-lg disabled:opacity-50"
>
<Save className="w-4 h-4" />
{saving ? '保存中...' : '保存'}
</button>
<span className="text-xs text-gray-400 dark:text-gray-500">保存后立即生效,无需重启</span>
</div>
</div>
)}
{active === 'about' && (
<div className="space-y-4 text-sm">
<div className="flex items-center justify-between py-2 border-b border-gray-100 dark:border-gray-700">
@@ -238,7 +403,7 @@ export default function SettingsModal({ open, onClose, versionLabel }) {
</div>
<div className="flex items-center justify-between py-2 border-b border-gray-100 dark:border-gray-700">
<span className="text-gray-500 dark:text-gray-400">项目名称</span>
<span className="font-medium text-gray-900 dark:text-white">FlyPic 素材库</span>
<span className="font-medium text-gray-900 dark:text-white">牛图 素材库</span>
</div>
<div className="flex items-center justify-between py-2">
<span className="text-gray-500 dark:text-gray-400">开源地址</span>
@@ -254,7 +419,7 @@ export default function SettingsModal({ open, onClose, versionLabel }) {
</a>
</div>
<p className="text-xs text-gray-400 dark:text-gray-500 pt-2">
FlyPic 基于 ZangXincz/FlyPic 二次开发,修复多项问题并新增 OCR 图内文字搜索、线上 OCR、授权系统接入等能力。
牛图(FlyPic)基于 ZangXincz/FlyPic 二次开发,修复多项问题并新增 OCR 图内文字搜索、线上 OCR、授权系统接入等能力。
</p>
</div>
)}