feat: 提示词详细化 + 模型配置统一到设置 (v1.4.9)
- 40条图片预设扩写为完整出图提示词(主体+场景+光线+风格+质量, 平均200+字符) - 预设卡片显示两行详细描述预览, 点击填入完整提示词(修复原先只填名称) - 6条视频脚本提示词扩为含镜头语言与节奏的完整框架 - AI生图弹窗移除与设置重复的模型/通道下拉, 统一在设置-AI生图配置 - 设置-AI生图新增默认模型下拉, 存imagegen.newapi.model - 修复翻译调用早于effUrl/effKey声明的TDZ错误 - 弹窗全屏显示, 仅关闭按钮可关闭(遮罩点击不关闭) - 版本号4处同步升至1.4.9, CHANGELOG补齐v1.4.9条目
This commit is contained in:
1 parent
67f8a8f708
commit
4dcc908eaa
11 files changed
+126
-143
No files matched your search
@@ -12,7 +12,7 @@ import { PROMPT_CATEGORIES } from '../constants/promptPresets';
|
||||
/**
|
||||
* AI 生图弹窗
|
||||
* - 热门提示词分类(点击填入/追加)
|
||||
* - 内置模型(NewAPI:CF Workers AI / Pollinations)+ 自定义提供商
|
||||
* - 通道与模型统一在「设置 → AI 生图」配置,弹窗不再重复选择
|
||||
* - 生成 → 预览 → 保存到素材库 / 下载 / 重新生成
|
||||
*/
|
||||
|
||||
@@ -35,12 +35,9 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
|
||||
const [prompt, setPrompt] = useState('');
|
||||
const [cat, setCat] = useState('hot');
|
||||
const [groups, setGroups] = useState([]);
|
||||
const [sizes, setSizes] = useState([]);
|
||||
const [providerInfo, setProviderInfo] = useState(null);
|
||||
const [model, setModel] = useState('flux-schnell');
|
||||
const [size, setSize] = useState('1024x1024');
|
||||
const [useCustom, setUseCustom] = useState(false);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
@@ -52,7 +49,6 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
const [advanced, setAdvanced] = useState(false);
|
||||
|
||||
// 参考图(以图生图)
|
||||
const [editModels, setEditModels] = useState([]);
|
||||
const [refs, setRefs] = useState([]); // [{ path, filename, thumbnailPath }]
|
||||
const [showRefPicker, setShowRefPicker] = useState(false);
|
||||
const [refList, setRefList] = useState([]);
|
||||
@@ -71,19 +67,12 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
setRefQuery('');
|
||||
aigenAPI.getModels()
|
||||
.then((d) => {
|
||||
setGroups(d.groups || []);
|
||||
setEditModels(d.editModels || []);
|
||||
setSizes(d.sizes || []);
|
||||
setProviderInfo(d.provider || null);
|
||||
const first = (d.groups || [])[0];
|
||||
if (first && first.models && first.models[0]) setModel(first.models[0].id);
|
||||
if (d.provider && d.provider.type === 'custom') setUseCustom(true);
|
||||
})
|
||||
.catch((e) => setError('读取模型列表失败: ' + (e.data?.error || e.message)));
|
||||
}, [open]);
|
||||
|
||||
const currentModelId = useCustom ? (providerInfo?.customModel || '') : model;
|
||||
|
||||
/** 素材库缩略图地址 */
|
||||
const thumbUrl = (img) => {
|
||||
if (!img || !currentLibraryId) return '';
|
||||
@@ -123,10 +112,6 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
}
|
||||
if (refs.length >= 4) { setError('最多选 4 张参考图'); return; }
|
||||
setRefs((prev) => [...prev, img]);
|
||||
// 选了参考图就自动切到图生图模型,避免用户忘记换模型导致图片没被用上
|
||||
if (editModels.length && !String(model).startsWith('flux-2')) {
|
||||
setModel(editModels[0].id);
|
||||
}
|
||||
};
|
||||
const handleGenerate = async () => {
|
||||
if (!prompt.trim()) { setError('请先输入提示词,或点一个热门提示词'); return; }
|
||||
@@ -134,19 +119,11 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
setError('');
|
||||
setSaved(false);
|
||||
try {
|
||||
if (refs.length > 0 && !useCustom && !String(model).startsWith('flux-2')) {
|
||||
setError('已选参考图,请把模型切换为「FLUX.2 图生图」系列');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
const d = await aigenAPI.generate({
|
||||
prompt: prompt.trim(),
|
||||
model: useCustom ? undefined : model,
|
||||
size,
|
||||
provider: useCustom ? 'custom' : 'builtin',
|
||||
libraryId: currentLibraryId,
|
||||
refImages: refs.map((r) => ({ path: r.path, filename: r.filename })),
|
||||
...(refs.length ? {} : {})
|
||||
});
|
||||
const img = d.images && d.images[0];
|
||||
if (!img || !img.b64) throw new Error('未返回图片数据');
|
||||
@@ -211,7 +188,7 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
if (!open) return null;
|
||||
|
||||
const activeCat = PROMPT_CATEGORIES.find((c) => c.key === cat) || PROMPT_CATEGORIES[0];
|
||||
const noKey = providerInfo && !providerInfo.hasKey && !useCustom;
|
||||
const noKey = providerInfo && !providerInfo.hasKey && providerInfo.type !== 'custom';
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
||||
@@ -276,13 +253,16 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
{activeCat.prompts.map((p) => (
|
||||
<button
|
||||
key={p.name}
|
||||
onClick={() => appendPrompt(p.name)}
|
||||
title={p.name}
|
||||
onClick={() => appendPrompt(p.prompt)}
|
||||
title={p.prompt}
|
||||
className="text-left px-2.5 py-2 rounded-lg border border-gray-200 dark:border-gray-700 hover:border-purple-400 dark:hover:border-purple-500 hover:bg-purple-50 dark:hover:bg-purple-500/10 transition-colors group"
|
||||
>
|
||||
<div className="text-xs font-medium text-gray-800 dark:text-gray-200 truncate group-hover:text-purple-700 dark:group-hover:text-purple-300">
|
||||
{p.name}
|
||||
</div>
|
||||
<div className="mt-0.5 text-[10px] leading-4 text-gray-400 dark:text-gray-500 line-clamp-2 group-hover:text-gray-500 dark:group-hover:text-gray-400">
|
||||
{p.prompt}
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -291,66 +271,22 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
|
||||
{/* 右:参数 + 生成 */}
|
||||
<div className="lg:col-span-2 space-y-3.5">
|
||||
{/* 提供商 */}
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5">模型提供商</label>
|
||||
<select
|
||||
value={useCustom ? 'custom' : 'builtin'}
|
||||
onChange={(e) => setUseCustom(e.target.value === 'custom')}
|
||||
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 className="flex items-center justify-between px-3 py-2 rounded-lg bg-gray-50 dark:bg-gray-900/40 border border-gray-200 dark:border-gray-700">
|
||||
<span className="text-[11px] text-gray-500 dark:text-gray-400">
|
||||
通道与模型在右上角「设置 → AI 生图」配置
|
||||
</span>
|
||||
<button
|
||||
onClick={() => window.dispatchEvent(new CustomEvent('open:settings', { detail: { tab: 'aigen' } }))}
|
||||
className="text-[11px] text-purple-600 dark:text-purple-400 hover:underline flex-shrink-0 ml-2"
|
||||
>
|
||||
<option value="builtin">内置 NewAPI(Pollinations + CF Workers AI)</option>
|
||||
<option value="custom" disabled={!providerInfo?.customModel && !providerInfo?.customUrl}>
|
||||
自定义提供商{providerInfo?.customModel ? `(${providerInfo.customModel})` : '(未配置)'}
|
||||
</option>
|
||||
</select>
|
||||
{providerInfo && !providerInfo.hasKey && !useCustom && (
|
||||
<div className="mt-1.5 flex items-start gap-1.5 text-[11px] text-amber-600 dark:text-amber-400">
|
||||
<AlertTriangle className="w-3.5 h-3.5 flex-shrink-0 mt-px" />
|
||||
<span>
|
||||
未配置 API Key。到「设置 → AI 生图」填写,或由服务器环境变量注入。
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
去设置
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 模型 */}
|
||||
{!useCustom && (
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5">模型</label>
|
||||
<select
|
||||
value={model}
|
||||
onChange={(e) => setModel(e.target.value)}
|
||||
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"
|
||||
>
|
||||
{groups.map((g) => (
|
||||
<optgroup key={g.key} label={g.label}>
|
||||
{g.models.map((m) => (
|
||||
<option key={m.id} value={m.id}>{m.name}</option>
|
||||
))}
|
||||
</optgroup>
|
||||
))}
|
||||
{editModels.length > 0 && (
|
||||
<optgroup label="以图生图(需要参考图)">
|
||||
{editModels.map((m) => (
|
||||
<option key={m.id} value={m.id}>{m.name}</option>
|
||||
))}
|
||||
</optgroup>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{useCustom && (
|
||||
<div className="p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-200 dark:border-amber-500/30 rounded-lg text-xs text-amber-700 dark:text-amber-300">
|
||||
使用设置中配置的自定义提供商({providerInfo?.customUrl || '未配置地址'})。
|
||||
模型:{providerInfo?.customModel || '(未配置)'}
|
||||
<button
|
||||
onClick={() => window.dispatchEvent(new CustomEvent('open:settings', { detail: { tab: 'aigen' } }))}
|
||||
className="ml-1 underline hover:text-amber-900 dark:hover:text-amber-100"
|
||||
>
|
||||
去配置
|
||||
</button>
|
||||
{noKey && (
|
||||
<div className="flex items-start gap-1.5 text-[11px] text-amber-600 dark:text-amber-400">
|
||||
<AlertTriangle className="w-3.5 h-3.5 flex-shrink-0 mt-px" />
|
||||
<span>未配置 API Key。到「设置 → AI 生图」填写,或由服务器环境变量注入。</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -441,7 +377,7 @@ export default function AIGenModal({ open, onClose, onSaved }) {
|
||||
|
||||
{loading && (
|
||||
<div className="text-[11px] text-gray-400 dark:text-gray-500 text-center">
|
||||
正在调用 {useCustom ? '自定义提供商' : (model || '')}
|
||||
正在调用生图服务
|
||||
{refs.length > 0 ? '(以图生图,约 20-60 秒)' : ',超时上限 150 秒'}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user