1480 lines
80 KiB
TypeScript
1480 lines
80 KiB
TypeScript
/**
|
||
* 资产管理(图2 节点 ②③④ 的一致性底座)。
|
||
*
|
||
* - 人物 / 场景 / 声线三类可复用资产 + 项目级素材(配乐 / 音效 / 通用参考)
|
||
* - 每个资产都能单独调用模型生成新版本;绑定到分镜后自动进入视频参考素材与提示词
|
||
* - LB-1:AI 生成表单从每张卡片里抽出来,全页共用一个右侧抽屉
|
||
* - LB-4:跨字段搜索 / 缺素材 / 未被引用筛选 + Shift 连选批量上架、删除
|
||
*
|
||
* 旧站在 .cardrow / .tbl tr 上用 CSS 类 `picked` 表达勾选态,React 侧改成
|
||
* data-chosen + Table 的单元格选择器(与时间线版本表同一套写法)。
|
||
*/
|
||
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react'
|
||
import { Link, useSearchParams } from 'react-router-dom'
|
||
import * as api from '../../api/client'
|
||
import { canvasFor, fmtBytes, fmtTime, opt } from '../../lib/format'
|
||
import { fromAsset } from '../../lib/media'
|
||
import { defaultAssetName, existingNames, keepOrRestoreCurrent } from '../../lib/versions'
|
||
import { cn } from '../../lib/cn'
|
||
import { defaultFor, isMock, loadModels, modelsOf, useModelsStore, type ModelRow } from '../../stores/models'
|
||
import { Select } from '../../components/forms'
|
||
import { AudioPlay } from '../../components/media/AudioPlay'
|
||
import { MediaThumb } from '../../components/media/MediaThumb'
|
||
import { RecordAudio, type RecordPickMeta } from '../../components/media/RecordAudio'
|
||
import { Actions, BarRight, Between, Button, CARD_ROW, CardActions, Check, Chip, ChipBar, Ctlbar, Divider, Drawer, Empty, ErrorText, ExtLink, Field, FieldBlock, FilePick, FormGrid, FormRow, IconText, Input, LINK_CLS, LineHint, LinkButton, MONO, MUTED, MUTED_MONO, NumberInput, Panel, PanelHead, Row, SearchInput, SectionTitle, Spinner, PageStack, Table, TableBox, Tabs, Tag, TagGroup, TextArea, cellRight, cellWrap } from '../../components/ui'
|
||
import { useSystemStore } from '../../stores/system'
|
||
import { refresh, useProjectStore } from '../../stores/project'
|
||
import { notify } from '../../stores/notice'
|
||
import { Checkbox } from '../../components/ui'
|
||
import { IconBulb, IconDelete, IconImage, IconPass, IconReject, IconSync, IconUpload, IconVoice, IconWarn } from '../../components/icons'
|
||
|
||
type GenType = 'human' | 'scene' | 'voice'
|
||
type PanelKey = GenType | 'project'
|
||
type EditKind = '' | GenType
|
||
type SuggestType = 'character' | 'scene'
|
||
|
||
/** AI 生成台的一条草稿:按「类型:资产 id」存,切换卡片不丢已经填好的提示词 */
|
||
type GenDraft = {
|
||
kind: string
|
||
model_id: number | null
|
||
assist_model_id: number | null
|
||
prompt: string
|
||
sample_text: string
|
||
reference_asset_id: number | null
|
||
}
|
||
|
||
const PANEL_LABEL: Record<PanelKey, string> = { human: '人物', scene: '场景', voice: '声线', project: '项目素材' }
|
||
/** 批量删除 / 编辑走的 REST 路径段(项目素材面板不参与批量,所以没有这一项) */
|
||
const PANEL_PATH: Record<GenType, string> = { human: 'characters', scene: 'scenes', voice: 'voices' }
|
||
const PANEL_KEYS: PanelKey[] = ['human', 'scene', 'voice', 'project']
|
||
|
||
/* 新表单的键序就是保存时的字段序,空值也照发:后端按「字段在不在 body 里」判断是否更新 */
|
||
const EMPTY_CHAR = {
|
||
name: '', code: '', role: '主角', appearance: '', personality: '', persona_prompt: '',
|
||
voice_profile: '', default_voice_id: null as number | null, style_version: 'v1', tags: '', notes: ''
|
||
}
|
||
const EMPTY_SCENE = {
|
||
name: '', code: '', description: '', prompt: '', lighting: '', time_of_day: '', palette: '', tags: ''
|
||
}
|
||
const EMPTY_VOICE = {
|
||
name: '', provider: '', provider_voice_id: '', language: 'zh-CN', gender: 'male',
|
||
description: '', version: 'v1', is_default: false, tuning: {} as any
|
||
}
|
||
const GENDER_LABEL: Record<string, string> = { male: '男声', female: '女声', neutral: '中性' }
|
||
const GENDER_OPTIONS = [
|
||
{ value: 'male', label: '男声' }, { value: 'female', label: '女声' }, { value: 'neutral', label: '中性' }
|
||
]
|
||
const ROLE_OPTIONS = ['主角', '配角', '反派', '旁白', '群众']
|
||
/** 上传区里的项目级素材类型(配乐 / 音效是时间线合成页直接要吃的东西) */
|
||
const PROJECT_ASSET_KINDS = ['bgm', 'sfx', 'reference', 'reference_image', 'reference_video']
|
||
const SAY_VOICES = [
|
||
{ value: 'Tingting', label: 'Tingting · 中文女声' },
|
||
{ value: 'Meijia', label: 'Meijia · 中文女声' },
|
||
{ value: 'Sinji', label: 'Sinji · 粤语女声' },
|
||
{ value: 'Fred', label: 'Fred · 英文低男声' },
|
||
]
|
||
const EFFECT_OPTIONS = [
|
||
{ value: '', label: '真实人声' },
|
||
{ value: 'alien', label: '外星低吼(降调 + 金属共振)' },
|
||
]
|
||
const IMAGE_REF_ACCEPT = 'image/*'
|
||
|
||
const assetKindLabel = (kind: string) => opt('asset_kinds', kind)
|
||
const draftKey = (type: GenType, id: number | null | undefined) => `${type}:${id}`
|
||
|
||
function isImageAsset(asset: any) {
|
||
return /\.(png|jpe?g|webp|gif|bmp|tiff?)$/i.test(asset.path || '') || !!asset.width
|
||
}
|
||
function isAudioAsset(asset: any) {
|
||
return /\.(wav|mp3|m4a|aac|flac|ogg|opus)$/i.test(asset.path || '') || !!asset.duration_ms
|
||
}
|
||
function isVideoAsset(asset: any) {
|
||
return /\.(mp4|mov|m4v|webm|mkv)$/i.test(asset.path || '')
|
||
}
|
||
function assetsOf(owner: any): any[] { return (owner && owner.assets) || [] }
|
||
function imageReferenceOptions(owner: any) { return assetsOf(owner).filter(isImageAsset) }
|
||
function voiceReferenceOptions(owner: any) { return assetsOf(owner).filter(isAudioAsset) }
|
||
/** 场景参考优先用最新的场景图,一条都没有才退到任意图片 */
|
||
function latestSceneImage(owner: any) {
|
||
return [...imageReferenceOptions(owner)]
|
||
.filter((asset) => asset.kind === 'scene_image')
|
||
.sort((a, b) => Number(b.id) - Number(a.id))[0]
|
||
|| [...imageReferenceOptions(owner)].sort((a, b) => Number(b.id) - Number(a.id))[0]
|
||
|| null
|
||
}
|
||
/** 最近一次 AI 生成的来源(provider/model),卡片上用来回显「这张图是谁画的」 */
|
||
function generatedBy(owner: any) {
|
||
return assetsOf(owner).find((a: any) => a.metadata?.generated)?.metadata || null
|
||
}
|
||
/** 同一资产的多份素材 / 多版本拼成队列,预览器里可以 ←/→ 翻页并切版本 */
|
||
function mediaQueue(owner: any) {
|
||
return assetsOf(owner)
|
||
.map((a: any) => fromAsset(a, { group: owner.name }))
|
||
.filter(Boolean) as any[]
|
||
}
|
||
/** 标签输入框里的逗号(中英文都认)转成后端要的数组 */
|
||
function tagList(text: string) {
|
||
return text ? String(text).split(/[,,\s]+/).filter(Boolean) : []
|
||
}
|
||
|
||
/** 跨字段搜索:名称 / 设定 / 标签 / 素材文件名,空格分词后要求全部命中 */
|
||
function matchesKeyword(row: any, keyword: string) {
|
||
const kw = keyword.trim().toLowerCase()
|
||
if (!kw) return true
|
||
const hay = [row.name, row.code, row.role, row.appearance, row.persona_prompt, row.personality,
|
||
row.description, row.prompt, row.lighting, row.time_of_day, row.palette, row.provider,
|
||
row.provider_voice_id, row.notes, ...(row.tags || [])]
|
||
.filter(Boolean).join(' ').toLowerCase()
|
||
+ ' ' + (row.assets || []).map((a: any) => `${a.name} ${a.kind_label || a.kind || ''}`).join(' ').toLowerCase()
|
||
return kw.split(/\s+/).every((word) => hay.includes(word))
|
||
}
|
||
|
||
function blankDraft(type: GenType, owner: any): GenDraft {
|
||
const currentScene = type === 'scene' ? latestSceneImage(owner) : null
|
||
return {
|
||
kind: type === 'human' ? 'portrait' : type === 'scene' ? 'scene_image' : 'voice_sample',
|
||
model_id: defaultFor(type === 'voice' ? 'tts' : 'image', false)?.id || null,
|
||
assist_model_id: defaultFor('llm', false)?.id || null,
|
||
prompt: '',
|
||
// 试听文本是要念的台词;音色描述是设定,不能当默认台词塞进去
|
||
sample_text: '',
|
||
reference_asset_id: currentScene?.id || null,
|
||
}
|
||
}
|
||
|
||
export default function Library() {
|
||
const projectId = useProjectStore((s) => s.id)
|
||
const project = useProjectStore((s) => s.project)
|
||
const registryRows = useModelsStore((s) => s.rows)
|
||
const registryError = useModelsStore((s) => s.error)
|
||
/** 任务是不是在平台内即时执行由后端 /health 决定(外壳每 30 秒刷一次),页面只读不算 */
|
||
const health = useSystemStore((s) => s.health)
|
||
const [params, setParams] = useSearchParams()
|
||
|
||
const [error, setError] = useState('')
|
||
const [busy, setBusy] = useState('')
|
||
const [panel, setPanel] = useState<PanelKey>(() => {
|
||
const want = String(params.get('panel') || '')
|
||
return (PANEL_KEYS as string[]).includes(want) ? (want as PanelKey) : 'human'
|
||
})
|
||
const [showForm, setShowForm] = useState(false)
|
||
const [editing, setEditing] = useState<{ kind: EditKind; id: number | null }>({ kind: '', id: null })
|
||
|
||
const [projectAssets, setProjectAssets] = useState<any[]>([])
|
||
const [usage, setUsage] = useState<Record<string, any>>({})
|
||
const [generation, setGeneration] = useState<Record<string, GenDraft>>({})
|
||
const [suggestions, setSuggestions] = useState<Record<string, string>>({})
|
||
|
||
const [char, setChar] = useState({ ...EMPTY_CHAR })
|
||
const [scene, setScene] = useState({ ...EMPTY_SCENE })
|
||
const [voice, setVoice] = useState({ ...EMPTY_VOICE })
|
||
const [voiceSpeed, setVoiceSpeed] = useState(1)
|
||
const [voiceEffect, setVoiceEffect] = useState('')
|
||
|
||
const [keyword, setKeyword] = useState('')
|
||
const [onlyMissing, setOnlyMissing] = useState(false)
|
||
const [onlyUnused, setOnlyUnused] = useState(false)
|
||
const [picks, setPicks] = useState<Set<string>>(new Set())
|
||
/* checkbox 的 change 事件不带 shiftKey,只能用伴随的 click 记录修饰键 */
|
||
const [lastShift, setLastShift] = useState(false)
|
||
|
||
const [genPanel, setGenPanel] = useState<{ open: boolean; type: GenType; ownerId: number | null }>({
|
||
open: false, type: 'human', ownerId: null
|
||
})
|
||
/* 音色预告:参考音频才决定音色,所以开抽屉时先问后端「这次会拿到谁的嗓子」,
|
||
而不是拿声线性别去猜——性别对 zero-shot 克隆模型只是元数据。 */
|
||
const [voiceRefStatus, setVoiceRefStatus] = useState<any | null>(null)
|
||
|
||
const characters: any[] = project?.characters || []
|
||
const scenes: any[] = project?.scenes || []
|
||
const voices: any[] = project?.voices || []
|
||
|
||
/* ---------- 模型下拉一律取自「模型管理中心」注册表(stores/models 单例):
|
||
已启用 + 非 mock 演练通道,未启用的行不出现在业务表单里。 ---------- */
|
||
const imageProviders = useMemo(() => modelsOf('image', false), [registryRows])
|
||
/* 「AI 补全一致性提示词」走的是后端的 resolve_llm,只认大模型分类 */
|
||
const llmProviders = useMemo(() => modelsOf('llm', false), [registryRows])
|
||
const ttsProviders = useMemo(() => modelsOf('tts', false), [registryRows])
|
||
/** SAY_VOICES 是封闭清单,但旧数据里存过手填的系统声音名;
|
||
不加这一条,下拉会把已存值静默显示成清单第一项,保存时就把音色改没了 */
|
||
const sayVoiceOptions = voice.provider === 'macos-say' && voice.provider_voice_id
|
||
&& !SAY_VOICES.some((v) => v.value === voice.provider_voice_id)
|
||
? [...SAY_VOICES, { value: voice.provider_voice_id, label: `${voice.provider_voice_id} · 自定义` }]
|
||
: SAY_VOICES
|
||
|
||
/** 注册表在回调里也要读到最新值,但抽屉要显示「所选通道不可用」→ 统一走这份订阅 */
|
||
const providerById = useCallback((id: number | null | undefined) => {
|
||
const row = registryRows.find((p) => p.id === id) || null
|
||
return row && !isMock(row) ? row : null
|
||
}, [registryRows])
|
||
|
||
const usageFor = useCallback((type: string, id: number) => usage[`${type}:${id}`] || { count: 0, shots: [] }, [usage])
|
||
|
||
/* ---------- 生成草稿 ---------- */
|
||
/** 没有落 state 的行现算一份默认草稿:渲染期只读不写,写入由 patchDraft 负责 */
|
||
const draftOf = (type: GenType, owner: any): GenDraft =>
|
||
generation[draftKey(type, owner?.id)] || blankDraft(type, owner)
|
||
const patchDraft = (type: GenType, owner: any, patch: Partial<GenDraft>) => {
|
||
const key = draftKey(type, owner.id)
|
||
setGeneration((prev) => ({ ...prev, [key]: { ...(prev[key] || blankDraft(type, owner)), ...patch } }))
|
||
}
|
||
|
||
/** 模型被停用 / 删掉之后,草稿里残留的 id 会静默生成失败,这里退回当前默认值 */
|
||
const syncGenerationDefaults = useCallback(() => {
|
||
const state = useModelsStore.getState()
|
||
const live = (id: number | null | undefined) => {
|
||
const row = state.rows.find((p) => p.id === id) || null
|
||
return row && !isMock(row) ? row : null
|
||
}
|
||
const patch = (type: GenType, list: any[], mediaType: 'image' | 'tts') => {
|
||
for (const owner of list) {
|
||
const key = draftKey(type, owner.id)
|
||
const cur = generation[key] || blankDraft(type, owner)
|
||
const next: GenDraft = { ...cur }
|
||
if (!live(next.model_id)) next.model_id = defaultFor(mediaType, false)?.id || null
|
||
if (mediaType === 'image' && !live(next.assist_model_id)) {
|
||
next.assist_model_id = defaultFor('llm', false)?.id || null
|
||
}
|
||
if (JSON.stringify(next) !== JSON.stringify(cur)) {
|
||
setGeneration((prev) => ({ ...prev, [key]: next }))
|
||
}
|
||
}
|
||
}
|
||
patch('human', characters, 'image')
|
||
patch('scene', scenes, 'image')
|
||
patch('voice', voices, 'tts')
|
||
}, [generation, characters, scenes, voices])
|
||
|
||
/* ---------- 数据装载 ---------- */
|
||
const loadProjectAssets = useCallback(async () => {
|
||
if (!projectId) return
|
||
try {
|
||
const data = await api.get(`/api/projects/${projectId}/assets`, { owner_type: 'project' })
|
||
setProjectAssets(data.assets || [])
|
||
} catch (exc: any) { setError(exc?.message || String(exc)) }
|
||
}, [projectId])
|
||
|
||
const loadUsage = useCallback(async () => {
|
||
if (!projectId) return
|
||
try {
|
||
const data = await api.get(`/api/projects/${projectId}/assets/usage`)
|
||
const mapped: Record<string, any> = {}
|
||
for (const [type, rows] of Object.entries(data.usage || {})) {
|
||
for (const [id, item] of Object.entries(rows as any)) mapped[`${type}:${id}`] = item
|
||
}
|
||
setUsage(mapped)
|
||
} catch (exc: any) { setError(exc?.message || String(exc)) }
|
||
}, [projectId])
|
||
|
||
useEffect(() => {
|
||
void (async () => {
|
||
await Promise.all([loadProjectAssets(), loadUsage()])
|
||
await loadModels()
|
||
syncGenerationDefaults()
|
||
})()
|
||
// 只在挂载时拉一次;列表变化后新出现的行由 blankDraft 现取默认模型
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [])
|
||
|
||
useEffect(() => {
|
||
if (registryError) setError(`模型注册表读取失败:${registryError}`)
|
||
}, [registryError])
|
||
|
||
/* 预览器里做了版本操作(设为当前 / 删除某版)→ 重新拉一次,
|
||
项目卡片与引用区不会停在旧版本上。 */
|
||
useEffect(() => {
|
||
const onMediaChanged = () => { void loadProjectAssets(); void refresh() }
|
||
window.addEventListener('nex:media-changed', onMediaChanged)
|
||
return () => window.removeEventListener('nex:media-changed', onMediaChanged)
|
||
}, [loadProjectAssets])
|
||
|
||
async function run(label: string, fn: () => Promise<any>) {
|
||
setBusy(label)
|
||
setError('')
|
||
try {
|
||
await fn()
|
||
await refresh()
|
||
return true
|
||
} catch (exc: any) {
|
||
setError(exc?.message || String(exc))
|
||
return false
|
||
} finally {
|
||
setBusy('')
|
||
}
|
||
}
|
||
|
||
/* ---------- 工具栏:搜索 / 筛选 / 批量(与平台资产库同一套交互模型) ---------- */
|
||
const filterRows = (list: any[], type: GenType) => list.filter((row) => matchesKeyword(row, keyword)
|
||
&& (!onlyMissing || !(row.assets || []).length)
|
||
&& (!onlyUnused || !usageFor(type, row.id).count))
|
||
/** 项目素材面板只吃关键词搜索(缺素材 / 未被引用对它没有意义),复用同一套匹配语义 */
|
||
const shownProjectAssets = projectAssets.filter((a: any) => matchesKeyword({
|
||
name: a.name, notes: a.path, tags: [a.kind_label || a.kind || ''],
|
||
}, keyword))
|
||
const shownHumans = filterRows(characters, 'human')
|
||
const shownScenes = filterRows(scenes, 'scene')
|
||
const shownVoices = filterRows(voices, 'voice')
|
||
const panelRows: any[] = panel === 'human' ? shownHumans
|
||
: panel === 'scene' ? shownScenes : panel === 'voice' ? shownVoices : []
|
||
const panelTotal = panel === 'human' ? characters.length
|
||
: panel === 'scene' ? scenes.length
|
||
: panel === 'voice' ? voices.length : projectAssets.length
|
||
const shownCount = panel === 'project' ? shownProjectAssets.length : panelRows.length
|
||
/** 命中数只在真的有筛选条件时出现,且不能跨面板串数字 */
|
||
const filterActive = !!keyword.trim() || (panel !== 'project' && (onlyMissing || onlyUnused))
|
||
const pickedRows = panelRows.filter((row) => picks.has(`${panel}:${row.id}`))
|
||
const allPicked = !!panelRows.length && panelRows.every((row) => picks.has(`${panel}:${row.id}`))
|
||
const pickedUsed = pickedRows.filter((row) => usageFor(panel, row.id).count).length
|
||
|
||
function togglePick(row: any, ev?: { shiftKey?: boolean }) {
|
||
const key = `${panel}:${row.id}`
|
||
const shift = !!ev?.shiftKey || lastShift
|
||
setLastShift(false)
|
||
const next = new Set(picks)
|
||
if (shift && panelRows.length) {
|
||
const lastKey = [...next].pop()
|
||
const lastIndex = panelRows.findIndex((r) => `${panel}:${r.id}` === lastKey)
|
||
const index = panelRows.findIndex((r) => r.id === row.id)
|
||
if (lastIndex >= 0 && index >= 0) {
|
||
panelRows.slice(Math.min(lastIndex, index), Math.max(lastIndex, index) + 1)
|
||
.forEach((r) => next.add(`${panel}:${r.id}`))
|
||
setPicks(next)
|
||
return
|
||
}
|
||
}
|
||
if (next.has(key)) next.delete(key)
|
||
else next.add(key)
|
||
setPicks(next)
|
||
}
|
||
function checkAllRows() {
|
||
const next = new Set(picks)
|
||
if (allPicked) panelRows.forEach((row) => next.delete(`${panel}:${row.id}`))
|
||
else panelRows.forEach((row) => next.add(`${panel}:${row.id}`))
|
||
setPicks(next)
|
||
}
|
||
function clearPicks() { setPicks(new Set()) }
|
||
function resetFilters() { setKeyword(''); setOnlyMissing(false); setOnlyUnused(false) }
|
||
/** 切面板同时收起表单与勾选:批量动作是按面板解释的,留着跨面板的勾选会误删 */
|
||
function choosePanel(key: PanelKey) {
|
||
setPanel(key)
|
||
setShowForm(false)
|
||
clearPicks()
|
||
setParams((prev) => {
|
||
const next = new URLSearchParams(prev)
|
||
next.set('panel', key)
|
||
return next
|
||
}, { replace: true })
|
||
}
|
||
|
||
/** 批量上架:逐个调用既有 publish 接口,引用关系与单个上架完全一致 */
|
||
async function bulkPublish() {
|
||
const rows = pickedRows
|
||
if (!rows.length) return
|
||
if (!confirm(`将选中的 ${rows.length} 个${PANEL_LABEL[panel]}上架为平台母版?已上架过的会更新同一个母版。`)) return
|
||
setBusy(`批量上架 ${rows.length} 个${PANEL_LABEL[panel]}`)
|
||
setError('')
|
||
let done = 0
|
||
try {
|
||
for (const row of rows) {
|
||
await api.post('/api/platform/publish', { project_id: projectId, asset_type: panel, asset_id: row.id })
|
||
done += 1
|
||
}
|
||
await refresh()
|
||
notify(`已上架 ${done} 个${PANEL_LABEL[panel]}母版`)
|
||
} catch (exc: any) {
|
||
setError(`${exc?.message || exc}(已成功 ${done}/${rows.length} 个)`)
|
||
} finally { setBusy('') }
|
||
}
|
||
|
||
/** 批量删除:仍被镜头引用的自动跳过,避免把分镜绑成空指针 */
|
||
async function bulkDelete() {
|
||
const rows = pickedRows
|
||
if (!rows.length) return
|
||
const used = rows.filter((row) => usageFor(panel, row.id).count)
|
||
const free = rows.filter((row) => !usageFor(panel, row.id).count)
|
||
if (!free.length) {
|
||
setError(`选中的 ${rows.length} 个${PANEL_LABEL[panel]}都还被镜头引用,请先到分镜里解绑。`)
|
||
return
|
||
}
|
||
const skip = used.length ? `\n另有 ${used.length} 个仍被镜头引用,会自动跳过。` : ''
|
||
if (!confirm(`确认删除选中的 ${free.length} 个${PANEL_LABEL[panel]}?素材版本一并删除,已生成的镜头产物不受影响。${skip}`)) return
|
||
const path = PANEL_PATH[panel as GenType]
|
||
const ok = await run(`删除 ${free.length} 个${PANEL_LABEL[panel]}`, async () => {
|
||
for (const row of free) await api.del(`/api/projects/${projectId}/${path}/${row.id}`)
|
||
})
|
||
if (ok) {
|
||
clearPicks()
|
||
notify(`已删除 ${free.length} 个${PANEL_LABEL[panel]}${used.length ? `,跳过 ${used.length} 个被引用的` : ''}`)
|
||
}
|
||
}
|
||
|
||
/* ---------- 资产编辑表单 ---------- */
|
||
const patchChar = (p: Partial<typeof EMPTY_CHAR>) => setChar((s) => ({ ...s, ...p }))
|
||
const patchScene = (p: Partial<typeof EMPTY_SCENE>) => setScene((s) => ({ ...s, ...p }))
|
||
const patchVoice = (p: Partial<typeof EMPTY_VOICE>) => setVoice((s) => ({ ...s, ...p }))
|
||
|
||
async function saveCharacter() {
|
||
if (!char.name.trim()) { setError('请填写人物名称'); return }
|
||
const body: any = {
|
||
name: char.name, code: char.code, role: char.role, appearance: char.appearance,
|
||
personality: char.personality, persona_prompt: char.persona_prompt, voice_profile: char.voice_profile,
|
||
default_voice_id: char.default_voice_id || null, style_version: char.style_version,
|
||
tags: tagList(char.tags)
|
||
}
|
||
const ok = editing.kind === 'human' && editing.id
|
||
? await run('保存人物', () => api.patch(`/api/projects/${projectId}/characters/${editing.id}`, body))
|
||
: await run('创建人物', () => api.post(`/api/projects/${projectId}/characters`, body))
|
||
if (ok) {
|
||
setChar({ ...EMPTY_CHAR }); setEditing({ kind: '', id: null }); setShowForm(false)
|
||
notify('人物资产已保存')
|
||
}
|
||
}
|
||
|
||
async function saveScene() {
|
||
if (!scene.name.trim()) { setError('请填写场景名称'); return }
|
||
const body: any = {
|
||
name: scene.name, code: scene.code, description: scene.description, prompt: scene.prompt,
|
||
lighting: scene.lighting, time_of_day: scene.time_of_day, palette: scene.palette,
|
||
tags: tagList(scene.tags)
|
||
}
|
||
const ok = editing.kind === 'scene' && editing.id
|
||
? await run('保存场景', () => api.patch(`/api/projects/${projectId}/scenes/${editing.id}`, body))
|
||
: await run('创建场景', () => api.post(`/api/projects/${projectId}/scenes`, body))
|
||
if (ok) {
|
||
setScene({ ...EMPTY_SCENE }); setEditing({ kind: '', id: null }); setShowForm(false)
|
||
notify('场景资产已保存')
|
||
}
|
||
}
|
||
|
||
async function saveVoice() {
|
||
if (!voice.name.trim()) { setError('请填写声线名称'); return }
|
||
const params: Record<string, any> = { ...(voice.tuning?.params || {}) }
|
||
if (voiceEffect) params.effect = voiceEffect
|
||
else delete params.effect
|
||
const body = {
|
||
...voice,
|
||
provider_voice_id: voice.provider_voice_id || voice.name,
|
||
tuning: { ...(voice.tuning || {}), speed: Number(voiceSpeed) || 1, params },
|
||
}
|
||
const ok = editing.kind === 'voice' && editing.id
|
||
? await run('保存声线', () => api.patch(`/api/projects/${projectId}/voices/${editing.id}`, body))
|
||
: await run('创建声线', () => api.post(`/api/projects/${projectId}/voices`, body))
|
||
if (ok) {
|
||
setVoice({ ...EMPTY_VOICE }); setVoiceSpeed(1); setVoiceEffect('')
|
||
setEditing({ kind: '', id: null }); setShowForm(false)
|
||
notify('声线资产已保存')
|
||
}
|
||
}
|
||
|
||
function closeForm() {
|
||
setShowForm(false)
|
||
setEditing({ kind: '', id: null })
|
||
}
|
||
|
||
function edit(kind: GenType, row: any) {
|
||
setEditing({ kind, id: row.id })
|
||
if (kind === 'human') setChar({ ...EMPTY_CHAR, ...row, tags: (row.tags || []).join(' ') })
|
||
if (kind === 'scene') setScene({ ...EMPTY_SCENE, ...row, tags: (row.tags || []).join(' ') })
|
||
if (kind === 'voice') {
|
||
setVoice({ ...EMPTY_VOICE, ...row, tuning: { ...(row.tuning || {}) } })
|
||
setVoiceSpeed(Number(row.tuning?.speed || 1))
|
||
setVoiceEffect(row.tuning?.params?.effect || '')
|
||
}
|
||
setPanel(kind)
|
||
setShowForm(true)
|
||
}
|
||
|
||
/** 点候选模型 = 一次性把 provider 和它自带的 voice 填好,省得两边填歪 */
|
||
function chooseTts(p: ModelRow) {
|
||
patchVoice({
|
||
provider: p.provider,
|
||
...(p.adapter === 'macos_say'
|
||
? {
|
||
provider_voice_id: p.config?.voice || 'Tingting',
|
||
language: 'zh-CN',
|
||
gender: 'female',
|
||
name: voice.name || '系统中文女声',
|
||
}
|
||
: { provider_voice_id: p.config?.voice || p.model })
|
||
})
|
||
}
|
||
|
||
function clearVoiceForm() {
|
||
setVoice({ ...EMPTY_VOICE, tuning: {} })
|
||
setVoiceSpeed(1)
|
||
setVoiceEffect('')
|
||
setEditing({ kind: '', id: null })
|
||
}
|
||
|
||
async function drop(kind: string, row: any) {
|
||
if (!confirm(`确认删除「${row.name}」?已生成的镜头产物不会被删除。`)) return
|
||
await run('删除', () => api.del(`/api/projects/${projectId}/${kind}/${row.id}`))
|
||
}
|
||
|
||
async function publish(kind: GenType, row: any) {
|
||
if (!confirm(`将「${row.name}」上架为平台${PANEL_LABEL[kind]}母版?`)) return
|
||
setBusy('上架平台资产')
|
||
setError('')
|
||
try {
|
||
const res: any = await api.post('/api/platform/publish', {
|
||
project_id: projectId, asset_type: kind, asset_id: row.id,
|
||
})
|
||
await refresh()
|
||
notify(res?.reused
|
||
? `「${row.name}」库内已有同名母版 #${res.id},本次复用并升版至 v${res.media_version ?? ''}`
|
||
: `「${row.name}」已上架到平台资产库`)
|
||
} catch (exc: any) {
|
||
setError(exc?.message || String(exc))
|
||
} finally {
|
||
setBusy('')
|
||
}
|
||
}
|
||
|
||
/* ---------- 素材上传 / 录音 / 删除 ---------- */
|
||
const assetPath = (type: GenType, id: number) =>
|
||
`/api/projects/${projectId}/${PANEL_PATH[type]}/${id}/assets`
|
||
|
||
/** 上传与录音共用的落库通道:两条路必须登记出完全同构的版本 */
|
||
async function uploadFileTo(path: string, kind: string, file: File, name = '', note = '') {
|
||
setBusy(`上传${assetKindLabel(kind)}`)
|
||
setError('')
|
||
try {
|
||
const row: any = await api.upload(path, api.formData({ kind, name: name || file.name, note }, file))
|
||
notify(`${file.name} 已登记为${assetKindLabel(kind)}新版本`)
|
||
await Promise.all([refresh(), loadProjectAssets()])
|
||
return row || null // 素材行含 id / version / versions,供「设为当前版本」回退用
|
||
} catch (exc: any) {
|
||
setError(exc?.message || String(exc))
|
||
return null
|
||
} finally {
|
||
setBusy('')
|
||
}
|
||
}
|
||
|
||
function onUpload(path: string, kind: string, name = '') {
|
||
return async (files: File[]) => {
|
||
const file = files[0]
|
||
if (!file) return
|
||
await uploadFileTo(path, kind, file, name)
|
||
}
|
||
}
|
||
|
||
/** 项目声线卡上的「录一段」:录完直接当音色样本/参考的新版本入库 */
|
||
async function onRecord(path: string, kind: string, name: string, file: File, meta: RecordPickMeta) {
|
||
const row = await uploadFileTo(path, kind, file, (meta.name || '').trim() || name, '页面录制')
|
||
if (!row) return
|
||
await keepOrRestoreCurrent(row, meta.setCurrent !== false)
|
||
if (meta.warning) notify(`已录 ${(meta.durationMs / 1000).toFixed(1)} 秒:${meta.warning}`)
|
||
}
|
||
|
||
/** 生成台的参考素材上传(文件选择器与页面录音都走这里,上传完自动选中) */
|
||
async function sendGenerationReference(type: GenType, owner: any, file: File, note = '', name = '') {
|
||
setBusy(type === 'voice' ? '上传参考音色' : '上传参考图')
|
||
setError('')
|
||
try {
|
||
const asset: any = await api.upload(assetPath(type, owner.id),
|
||
api.formData({ kind: 'reference', name: (name || '').trim() || file.name, note }, file))
|
||
patchDraft(type, owner, { reference_asset_id: asset?.id || null })
|
||
notify(`${file.name} 已作为${type === 'voice' ? '参考音色' : '参考图'}并选中`)
|
||
await Promise.all([refresh(), loadProjectAssets()])
|
||
if (type === 'voice') await loadVoiceReferenceStatus(owner)
|
||
return asset || null
|
||
} catch (exc: any) {
|
||
setError(exc?.message || String(exc))
|
||
return null
|
||
} finally {
|
||
setBusy('')
|
||
}
|
||
}
|
||
|
||
async function recordGenerationReference(type: GenType, owner: any, file: File, meta: RecordPickMeta) {
|
||
const row = await sendGenerationReference(type, owner, file, '页面录制', meta.name)
|
||
if (row) await keepOrRestoreCurrent(row, meta.setCurrent !== false)
|
||
if (meta.warning) notify(meta.warning)
|
||
}
|
||
|
||
async function dropAsset(asset: any) {
|
||
if (!confirm(`删除素材「${asset.name}」?`)) return
|
||
await run('删除素材', () => api.del(`/api/assets/${asset.id}`))
|
||
await loadProjectAssets()
|
||
}
|
||
|
||
async function refreshAsset(asset: any) {
|
||
await run('刷新素材', () => api.post(`/api/assets/${asset.id}/refresh`))
|
||
await loadProjectAssets()
|
||
}
|
||
|
||
/* ---------- AI 生成 ---------- */
|
||
async function loadVoiceReferenceStatus(owner: any) {
|
||
try {
|
||
setVoiceRefStatus(await api.get(`/api/projects/${projectId}/voices/${owner.id}/reference-status`))
|
||
} catch {
|
||
setVoiceRefStatus(null) // 预告拿不到不挡生成,后端缺参考时仍会明确报错
|
||
}
|
||
}
|
||
|
||
function openGen(type: GenType, owner: any) {
|
||
const key = draftKey(type, owner.id)
|
||
// 先建草稿,抽屉里的受控控件才有落点
|
||
setGeneration((prev) => (prev[key] ? prev : { ...prev, [key]: blankDraft(type, owner) }))
|
||
setGenPanel({ open: true, type, ownerId: owner.id })
|
||
if (type === 'voice') void loadVoiceReferenceStatus(owner)
|
||
else setVoiceRefStatus(null)
|
||
}
|
||
function closeGen() { setGenPanel((s) => ({ ...s, open: false })) }
|
||
/** 按 id 实时解析:refresh() 会整体替换 store 里的列表,存对象引用会过期 */
|
||
const genOwner = useMemo(() => {
|
||
const list = genPanel.type === 'human' ? characters
|
||
: genPanel.type === 'scene' ? scenes : genPanel.type === 'voice' ? voices : []
|
||
return list.find((row: any) => row.id === genPanel.ownerId) || null
|
||
}, [genPanel.type, genPanel.ownerId, characters, scenes, voices])
|
||
const genType = genPanel.type
|
||
const genDraft = genOwner ? draftOf(genType, genOwner) : null
|
||
const genLabel = genType === 'voice' ? '声线' : genType === 'scene' ? '场景' : '人物'
|
||
const genProviders = genType === 'voice' ? ttsProviders : imageProviders
|
||
const genSuggestType: SuggestType = genType === 'scene' ? 'scene' : 'character'
|
||
/** 出图尺寸跟随项目画幅,抽屉里要明示,避免用户以为能单独选分辨率 */
|
||
const genCanvas = canvasFor(String(project?.resolution || '1080p'), String(project?.aspect_ratio || '16:9'), 1536)
|
||
const genProviderSpec = providerById(genDraft?.model_id)
|
||
const genProviderUnready = !!genProviderSpec && !genProviderSpec.available
|
||
/** 「能不能生成」看有没有可用模型;选中那台未就绪只出黄条——允许先填着,等服务回来直接点 */
|
||
const genProvidersReady = genProviders.length > 0
|
||
const genSuggestion = !genOwner || genType === 'voice'
|
||
? '' : suggestions[`${genSuggestType}:${genOwner.id}`] || ''
|
||
function dismissSuggestion() {
|
||
if (!genOwner) return
|
||
setSuggestions((prev) => {
|
||
const next = { ...prev }
|
||
delete next[`${genSuggestType}:${genOwner.id}`]
|
||
return next
|
||
})
|
||
}
|
||
|
||
async function generateAsset(type: GenType, owner: any) {
|
||
if (!owner) return false
|
||
const draft = draftOf(type, owner)
|
||
const mediaType = type === 'voice' ? 'tts' : 'image'
|
||
const spec = providerById(draft.model_id) || defaultFor(mediaType, false)
|
||
if (!spec) {
|
||
setError(`尚未启用${mediaType === 'tts' ? '声音' : '图像'}模型,请先到模型管理中心登记并启用。`)
|
||
return false
|
||
}
|
||
if (type === 'voice' && !String(draft.sample_text || '').trim()) {
|
||
setError('请先填写试听文本:它是模型要朗读的台词,「音色描述」不会被念出来')
|
||
return false
|
||
}
|
||
// 后端按性别挑参考,挑不到会直接失败;先在本地拦下,省一次无谓的任务往返
|
||
if (type === 'voice' && !draft.reference_asset_id && voiceRefStatus && !voiceRefStatus.ready) {
|
||
setError(voiceRefStatus.note)
|
||
return false
|
||
}
|
||
const [width, height] = genCanvas
|
||
const body = type === 'voice'
|
||
? {
|
||
target_type: type, target_id: owner.id, kind: 'voice_sample', provider: spec.provider,
|
||
model: spec.model, sample_text: draft.sample_text,
|
||
reference_asset_ids: draft.reference_asset_id ? [draft.reference_asset_id] : [], drain: true
|
||
}
|
||
: {
|
||
target_type: type, target_id: owner.id, kind: draft.kind, provider: spec.provider,
|
||
model: spec.model, prompt: draft.prompt, width, height,
|
||
reference_asset_ids: draft.reference_asset_id ? [draft.reference_asset_id] : [], drain: true
|
||
}
|
||
setBusy(`AI 生成${type === 'voice' ? '试听样本' : assetKindLabel(draft.kind)}`)
|
||
setError('')
|
||
try {
|
||
const result = await api.post(`/api/projects/${projectId}/assets/generate`, body)
|
||
if (result.task?.status !== 'succeeded') {
|
||
throw new Error(result.task?.error_message || result.task?.error_code || '资产生成失败')
|
||
}
|
||
notify(`${owner.name} · ${type === 'voice' ? '试听样本' : assetKindLabel(draft.kind)}已生成,并登记为新版本`)
|
||
await Promise.all([refresh(), loadProjectAssets(), loadUsage()])
|
||
return true
|
||
} catch (exc: any) {
|
||
setError(exc?.message || String(exc))
|
||
return false
|
||
} finally {
|
||
setBusy('')
|
||
}
|
||
}
|
||
|
||
/** 生成成功后关闭抽屉:新版本已在资产卡上可见,避免用户对着空表单等 */
|
||
async function genFromDrawer() {
|
||
const ok = await generateAsset(genType, genOwner)
|
||
if (ok) closeGen()
|
||
}
|
||
|
||
async function suggestText(type: SuggestType, owner: any) {
|
||
const imageDraft = draftOf(type === 'character' ? 'human' : 'scene', owner)
|
||
const spec = providerById(imageDraft.assist_model_id) || defaultFor('llm', false)
|
||
if (!spec) {
|
||
setError('尚未启用大模型,请先到模型管理中心配置。')
|
||
return
|
||
}
|
||
setBusy('AI 补全一致性提示词')
|
||
setError('')
|
||
try {
|
||
const result = await api.post(`/api/projects/${projectId}/assets/text-assist`, {
|
||
target_type: type, target_id: owner.id, provider: spec.provider, model: spec.model,
|
||
instruction: '强化外观、材质、光线和跨镜头一致性,避免空泛描述',
|
||
})
|
||
setSuggestions((prev) => ({ ...prev, [`${type}:${owner.id}`]: result.text || '' }))
|
||
notify(`${owner.name} 的一致性提示词已生成,可选择采用`)
|
||
} catch (exc: any) {
|
||
setError(exc?.message || String(exc))
|
||
} finally {
|
||
setBusy('')
|
||
}
|
||
}
|
||
|
||
async function applySuggestion(type: SuggestType, owner: any) {
|
||
const text = suggestions[`${type}:${owner.id}`]
|
||
if (!text) return
|
||
const ok = await run('采用提示词', () => api.patch(
|
||
`/api/projects/${projectId}/${type === 'character' ? 'characters' : 'scenes'}/${owner.id}`,
|
||
type === 'character' ? { persona_prompt: text } : { prompt: text },
|
||
))
|
||
if (ok) {
|
||
setSuggestions((prev) => {
|
||
const next = { ...prev }
|
||
delete next[`${type}:${owner.id}`]
|
||
return next
|
||
})
|
||
notify('一致性提示词已写入资产设定')
|
||
}
|
||
}
|
||
|
||
const projectMediaQueue = projectAssets
|
||
.map((a: any) => fromAsset(a, { group: '项目素材' }))
|
||
.filter(Boolean) as any[]
|
||
const linkCls = { size: 'sm' as const }
|
||
|
||
return (
|
||
<PageStack>
|
||
<Between className="max-lg:flex-col max-lg:items-start">
|
||
<div className="min-w-0">
|
||
<h2 className="mt-0 mb-0 text-lg font-bold"
|
||
title="集中维护人物、声音与场景。资产可单独调用模型生成,绑定到分镜后会自动进入视频参考素材与提示词。">
|
||
资产管理
|
||
</h2>
|
||
</div>
|
||
<Row tight>
|
||
<LinkButton to="/assets" {...linkCls}>平台资产库</LinkButton>
|
||
<LinkButton to="/models" {...linkCls}>配置生成模型</LinkButton>
|
||
</Row>
|
||
</Between>
|
||
|
||
{/* 四个人物 / 场景 / 声线 / 项目素材面板是四个内部页面 → Tabs(UI规范 §6.4)。
|
||
右侧动作走 antd 的 tabBarExtraContent,不再另起一行把页签和按钮分开。 */}
|
||
<Tabs
|
||
className="mb-3"
|
||
activeKey={panel}
|
||
onChange={(k) => choosePanel(k as PanelKey)}
|
||
tabBarExtraContent={{
|
||
right: (
|
||
<Row tight>
|
||
{busy ? <span className={MUTED}><Spinner /> {busy}…</span> : null}
|
||
{panel !== 'project' && (
|
||
<Button type="primary" onClick={() => setShowForm(!showForm)}>
|
||
{showForm ? '收起' : `+ 新建${panel === 'human' ? '人物' : panel === 'scene' ? '场景' : '声线'}`}
|
||
</Button>
|
||
)}
|
||
</Row>
|
||
)
|
||
}}
|
||
items={PANEL_KEYS.map((key) => ({
|
||
key,
|
||
label: PANEL_LABEL[key],
|
||
count: key === 'human' ? characters.length
|
||
: key === 'scene' ? scenes.length
|
||
: key === 'voice' ? voices.length : projectAssets.length
|
||
}))}
|
||
/>
|
||
|
||
{/* 工具栏:跨字段搜索 + 筛选 + 批量,和平台资产库一套动作 */}
|
||
<Ctlbar className="px-3 py-2 border border-fill rounded-lg bg-bg-container">
|
||
<Field label="搜索" width="grow">
|
||
<SearchInput aria-label="搜索当前面板" value={keyword} placeholder={panel === 'project' ? '搜索项目素材名称 / 类型 / 文件名…' : '搜索名称 / 代号 / 设定 / 标签 / 素材文件名…'} onChange={(e) => setKeyword(e.target.value)} />
|
||
</Field>
|
||
<Chip active={onlyMissing} disabled={panel === 'project'}
|
||
title={panel === 'project' ? '项目素材面板暂不支持该筛选' : '只看还没有任何素材的资产'}
|
||
onClick={() => setOnlyMissing(!onlyMissing)}>缺素材</Chip>
|
||
<Chip active={onlyUnused} disabled={panel === 'project'}
|
||
title="只看还没被任何镜头引用的资产,便于清理"
|
||
onClick={() => setOnlyUnused(!onlyUnused)}>未被镜头使用</Chip>
|
||
<BarRight>
|
||
{filterActive
|
||
? <span className={cn(MUTED, 'text-xs')}>命中 {shownCount} / {panelTotal}
|
||
<Button type="link" size="sm" className="ml-[5px] pb-0" onClick={resetFilters}>清除筛选</Button>
|
||
</span>
|
||
: panelTotal ? <span className={cn(MUTED, 'text-xs')}>共 {panelTotal} 项</span> : null}
|
||
</BarRight>
|
||
</Ctlbar>
|
||
|
||
{pickedRows.length > 0 && (
|
||
<div className="flex flex-wrap items-center gap-2 mb-3 px-3 py-2 border border-primary-border rounded-lg bg-primary-bg text-xs ">
|
||
<b className="text-xs">已选 {pickedRows.length} 个{PANEL_LABEL[panel]}</b>
|
||
<span className={cn(MUTED, 'text-xs')}>其中 {pickedUsed} 个仍被镜头引用</span>
|
||
<Button size="sm" disabled={!!busy} onClick={bulkPublish} icon={<IconUpload />}>批量上架平台</Button>
|
||
<Button type="text" danger disabled={!!busy} onClick={bulkDelete} icon={<IconDelete />}>批量删除</Button>
|
||
<Button size="sm" onClick={clearPicks}>取消选择</Button>
|
||
</div>
|
||
)}
|
||
|
||
<ErrorText className="mb-3">{error}</ErrorText>
|
||
|
||
{/* ===== 人物与定妆资产 ===== */}
|
||
{panel === 'human' && (
|
||
<Panel>
|
||
<PanelHead
|
||
title={<span title="定妆图 / 三视图 / 服装 / 表情 → 自动拼接到镜头提示词">角色与一致性素材</span>} />
|
||
{!characters.length
|
||
? <Empty>还没有人物。建立人物并上传定妆图,导入分镜时就能按名称自动绑定。</Empty>
|
||
: !shownHumans.length
|
||
? <Empty>当前筛选下没有人物。<Button size="sm" className="ml-2" onClick={resetFilters}>清除筛选</Button></Empty>
|
||
: <>
|
||
<SelectAll checked={allPicked} onChange={checkAllRows}
|
||
label={`全选当前 ${shownHumans.length} 个人物`} />
|
||
{shownHumans.map((c) => {
|
||
const picked = picks.has(`human:${c.id}`)
|
||
const use = usageFor('human', c.id)
|
||
const gens = generatedBy(c)
|
||
return (
|
||
<div key={c.id} className={cn(CARD_ROW, picked && PICKED)}>
|
||
<PickBox checked={picked} label={`选择人物 ${c.name}`} className="mt-1"
|
||
onToggle={(ev) => togglePick(c, ev)} />
|
||
<Avatar name={c.name}>{String(c.name || '').slice(0, 1)}</Avatar>
|
||
<div className="flex-1 min-w-0">
|
||
<h4>{c.name} <Tag>{c.role || '角色'}</Tag>{!c.is_active && <Tag tone="bad">已停用</Tag>}</h4>
|
||
<p>{c.appearance || c.persona_prompt || '未填写外观与一致性提示词'}</p>
|
||
<p>造型版本 {c.style_version || 'v1'} · 默认声线 {c.default_voice_name || '未绑定'}
|
||
{c.tags?.length ? ` · ${c.tags.join(' / ')}` : ''}</p>
|
||
<UsageLine type="human" id={c.id} usage={use} projectId={projectId} />
|
||
{/* 素材行 = 卡片动作行:容器下发 antd 紧凑档(componentSize=small),
|
||
于是两颗按钮是同一档、同一圆角,标签走只读标签的 sm 档,
|
||
一行里不再出现「一种按钮两档高、圆角一个 6 一个 8」。 */}
|
||
<CardActions className="mt-2 gap-2">
|
||
{assetsOf(c).map((a: any, ai: number) => (
|
||
<div key={a.id} className="flex items-center gap-2 min-w-0 flex-wrap">
|
||
<MediaThumb width="34px" src={a.url} kind={a.kind} size="xs" inlineAudio={false}
|
||
queue={mediaQueue(c)} index={ai}
|
||
title={`${assetKindLabel(a.kind)} · ${a.name} · v${a.version}`} />
|
||
<Tag size="sm">{assetKindLabel(a.kind)} v{a.version}</Tag>
|
||
{a.metadata?.model && <Tag size="sm" tone="info">{a.metadata.provider}/{a.metadata.model}</Tag>}
|
||
<Button size="sm" title="登记新版本" aria-label="登记新版本"
|
||
onClick={() => refreshAsset(a)} icon={<IconSync />} />
|
||
<Button type="text" danger size="sm" title="删除素材" aria-label="删除素材" onClick={() => dropAsset(a)} icon={<IconDelete />} />
|
||
</div>
|
||
))}
|
||
</CardActions>
|
||
<AiBar title="定妆图 / 三视图 / 服装 / 表情 → 自动登记新版本并作为镜头参考图"
|
||
icon={<IconImage />} label="AI 资产生成"
|
||
last={gens && <Tag tone="ok">最近:{gens.provider}/{gens.model}</Tag>}
|
||
disabled={!imageProviders.length}
|
||
disabledHint="模型管理中心还没有可用的图像模型"
|
||
onOpen={() => openGen('human', c)} />
|
||
<Actions>
|
||
<FilePick label="定妆图" accept={IMAGE_REF_ACCEPT}
|
||
onFiles={onUpload(assetPath('human', c.id), 'portrait', '定妆图')} />
|
||
<FilePick label="三视图" accept={IMAGE_REF_ACCEPT}
|
||
onFiles={onUpload(assetPath('human', c.id), 'turnaround', '三视图')} />
|
||
<FilePick label="服装" accept={IMAGE_REF_ACCEPT}
|
||
onFiles={onUpload(assetPath('human', c.id), 'costume', '服装参考')} />
|
||
<FilePick label="表情" accept={IMAGE_REF_ACCEPT}
|
||
onFiles={onUpload(assetPath('human', c.id), 'expression', '表情参考')} />
|
||
<Button size="sm" onClick={() => edit('human', c)}>编辑</Button>
|
||
<Button size="sm" onClick={() => publish('human', c)}>上架平台</Button>
|
||
<Button type="text" danger title="删除这个人物" onClick={() => drop('characters', c)}>删除</Button>
|
||
</Actions>
|
||
</div>
|
||
</div>
|
||
)
|
||
})}
|
||
</>}
|
||
</Panel>
|
||
)}
|
||
|
||
{/* ===== 场景资产 ===== */}
|
||
{panel === 'scene' && (
|
||
<Panel>
|
||
<PanelHead title="场景与美术参考" />
|
||
{!scenes.length
|
||
? <Empty>还没有场景。导入分镜时脚本里的「场景:」字段会按名称匹配这里登记的内容。</Empty>
|
||
: !shownScenes.length
|
||
? <Empty>当前筛选下没有场景。<Button size="sm" className="ml-2" onClick={resetFilters}>清除筛选</Button></Empty>
|
||
: <>
|
||
<SelectAll checked={allPicked} onChange={checkAllRows}
|
||
label={`全选当前 ${shownScenes.length} 个场景`} />
|
||
<TableBox maxHeight={false}>
|
||
<Table minWidth={900} className="[&_tbody_tr[data-chosen]>td]:bg-primary-bg">
|
||
<thead>
|
||
<tr><th>场景</th><th>提示词</th><th>光线 / 时间 / 色调</th><th>参考图</th><th className={cellRight}>操作</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
{shownScenes.map((s) => {
|
||
const picked = picks.has(`scene:${s.id}`)
|
||
const use = usageFor('scene', s.id)
|
||
return (
|
||
<tr key={s.id} data-chosen={picked || undefined}>
|
||
<td>
|
||
<div className="flex items-start gap-2 min-w-0">
|
||
<PickBox checked={picked} label={`选择场景 ${s.name}`} className="mt-1"
|
||
onToggle={(ev) => togglePick(s, ev)} />
|
||
<div className="min-w-0">
|
||
<b>{s.name}</b>
|
||
<div className={MUTED_MONO}>{s.code || '—'}</div>
|
||
<UsageLine type="scene" id={s.id} usage={use} projectId={projectId} limit={3} />
|
||
</div>
|
||
</div>
|
||
</td>
|
||
<td className={cellWrap}>{s.prompt || s.description || '—'}</td>
|
||
<td className={cn(cellWrap, MUTED)}>{[s.lighting, s.time_of_day, s.palette].filter(Boolean).join(' · ') || '—'}</td>
|
||
<td>
|
||
<div className="flex items-center gap-2 flex-wrap min-w-0">
|
||
{assetsOf(s).map((a: any, ai: number) => (
|
||
<MediaThumb key={a.id} width="34px" src={a.url} kind={a.kind}
|
||
size="xs" inlineAudio={false} queue={mediaQueue(s)} index={ai} title={a.name} />
|
||
))}
|
||
{!assetsOf(s).length && <span className={MUTED}>未上传</span>}
|
||
</div>
|
||
</td>
|
||
<td className={cellRight}>
|
||
<div className="flex items-center justify-end gap-2 flex-wrap min-w-0 ">
|
||
<FilePick label="场景图" accept={IMAGE_REF_ACCEPT}
|
||
onFiles={onUpload(assetPath('scene', s.id), 'scene_image', s.name)} />
|
||
<Button size="sm" disabled={!imageProviders.length}
|
||
title="打开生成台(模型 / 参考图 / 提示词)"
|
||
onClick={() => openGen('scene', s)} icon={<IconImage />}>AI 生成</Button>
|
||
<Button size="sm" onClick={() => edit('scene', s)}>编辑</Button>
|
||
<Button size="sm" onClick={() => publish('scene', s)}>上架平台</Button>
|
||
<Button type="text" danger title="删除这个场景" onClick={() => drop('scenes', s)}>删除</Button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
)
|
||
})}
|
||
</tbody>
|
||
</Table>
|
||
</TableBox>
|
||
</>}
|
||
</Panel>
|
||
)}
|
||
|
||
{/* ===== 声线资产 ===== */}
|
||
{panel === 'voice' && (
|
||
<Panel>
|
||
<PanelHead
|
||
title={<span title="镜头绑定声线后,台词会自动生成配音并参与混音">声线与配音模型</span>} />
|
||
{!voices.length
|
||
? <Empty>还没有声线。先登记声线基础设定,再到生成区选择真实 TTS 模型。</Empty>
|
||
: !shownVoices.length
|
||
? <Empty>当前筛选下没有声线。<Button size="sm" className="ml-2" onClick={resetFilters}>清除筛选</Button></Empty>
|
||
: <>
|
||
<SelectAll checked={allPicked} onChange={checkAllRows}
|
||
label={`全选当前 ${shownVoices.length} 条声线`} />
|
||
{shownVoices.map((v) => {
|
||
const picked = picks.has(`voice:${v.id}`)
|
||
const use = usageFor('voice', v.id)
|
||
const gens = generatedBy(v)
|
||
return (
|
||
<div key={v.id} className={cn(CARD_ROW, picked && PICKED)}>
|
||
<PickBox checked={picked} label={`选择声线 ${v.name}`} className="mt-1"
|
||
onToggle={(ev) => togglePick(v, ev)} />
|
||
<div className="flex-1 min-w-0">
|
||
<h4>{v.name} <Tag>{v.provider}</Tag>{v.is_default && <Tag tone="ok">默认</Tag>}</h4>
|
||
<p>{v.description || '未填写音色描述'}</p>
|
||
<p>voice_id <span className={MONO}>{v.provider_voice_id}</span> · {v.language} · {GENDER_LABEL[v.gender] || v.gender || '中性'} · 版本 {v.version}</p>
|
||
<UsageLine type="voice" id={v.id} usage={use} projectId={projectId} />
|
||
<AiBar title="调用声音模型生成并登记为音色样本版本(IndexTTS2 支持参考音频克隆)"
|
||
icon={<IconVoice />} label="AI 试听样本"
|
||
last={gens && <Tag tone="ok">{gens.provider}/{gens.model}</Tag>}
|
||
disabled={!ttsProviders.length}
|
||
disabledHint="模型管理中心还没有可用的声音模型"
|
||
onOpen={() => openGen('voice', v)} />
|
||
<Actions>
|
||
<FilePick label="音色样本" accept="audio/*"
|
||
onFiles={onUpload(assetPath('voice', v.id), 'voice_sample', v.name)} />
|
||
<RecordAudio label="录音色样本" target="音色样本"
|
||
defaultName={defaultAssetName(v.assets, v.name, 'voice_sample')}
|
||
names={existingNames(v.assets)}
|
||
hint="弹出小面板:录 → 试听 → 再决定存成哪条素材的哪个版本"
|
||
onPick={(file, meta) => void onRecord(assetPath('voice', v.id), 'voice_sample', v.name, file, meta)} />
|
||
{assetsOf(v).map((a: any) => (
|
||
<AudioPlay key={a.id} src={a.url} label={`${v.name} · ${a.name}`}
|
||
durationMs={a.duration_ms} size="sm" />
|
||
))}
|
||
<Button size="sm" onClick={() => edit('voice', v)}>编辑</Button>
|
||
<Button size="sm" onClick={() => publish('voice', v)}>上架平台</Button>
|
||
<Button type="text" danger title="删除这条声线" onClick={() => drop('voices', v)}>删除</Button>
|
||
</Actions>
|
||
</div>
|
||
</div>
|
||
)
|
||
})}
|
||
</>}
|
||
</Panel>
|
||
)}
|
||
|
||
{/* ===== 项目级素材 ===== */}
|
||
{panel === 'project' && (
|
||
<Panel>
|
||
<PanelHead
|
||
title={<span title="配乐可在「时间线合成」页直接挂到音轨">配乐 / 音效 / 通用参考</span>} />
|
||
<Row className="mb-4">
|
||
{PROJECT_ASSET_KINDS.map((k) => (
|
||
<FilePick key={k} label={`上传${assetKindLabel(k)}`}
|
||
onFiles={onUpload(`/api/projects/${projectId}/assets`, k, assetKindLabel(k))} />
|
||
))}
|
||
</Row>
|
||
{!projectAssets.length
|
||
? <Empty>还没有项目级素材。</Empty>
|
||
: !shownProjectAssets.length
|
||
? <Empty>当前搜索下没有素材。<Button size="sm" className="ml-2" onClick={resetFilters}>清除筛选</Button></Empty>
|
||
: (
|
||
<TableBox maxHeight={false}>
|
||
<Table minWidth={820}>
|
||
<thead>
|
||
<tr><th>名称</th><th>类型</th><th>大小</th><th>版本</th><th>上传时间</th><th>预览</th><th className={cellRight}>操作</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
{shownProjectAssets.map((a: any, ai: number) => (
|
||
<tr key={a.id}>
|
||
<td><b>{a.name}</b><div className={MUTED_MONO}>{a.path}</div></td>
|
||
<td><Tag>{assetKindLabel(a.kind)}</Tag></td>
|
||
<td className={MONO}>{fmtBytes(a.size_bytes)}</td>
|
||
<td className={MONO}>v{a.version}</td>
|
||
<td className={MUTED}>{fmtTime(a.created_at || a.versions?.[0]?.created_at)}</td>
|
||
<td>
|
||
{isAudioAsset(a)
|
||
? <AudioPlay src={a.url} label={a.name} durationMs={a.duration_ms} size="sm" />
|
||
: isImageAsset(a) || isVideoAsset(a)
|
||
? (
|
||
<MediaThumb width="34px" src={a.url} kind={a.kind}
|
||
size="xs" inlineAudio={false} queue={projectMediaQueue} index={ai} title={a.name} />
|
||
)
|
||
: <ExtLink href={a.url}>打开</ExtLink>}
|
||
</td>
|
||
<td className={cellRight}>
|
||
<div className="flex items-center justify-end gap-2 flex-wrap min-w-0 ">
|
||
<Button size="sm" onClick={() => refreshAsset(a)} icon={<IconSync />}>新版本</Button>
|
||
<Button type="text" danger title="删除这个素材" onClick={() => dropAsset(a)}>删除</Button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
))}
|
||
</tbody>
|
||
</Table>
|
||
</TableBox>
|
||
)}
|
||
{health?.executor === 'inline' && (
|
||
<LineHint className="mt-3">当前任务在平台内即时执行,提交配音或生成后会很快完成,进度自动刷新。</LineHint>
|
||
)}
|
||
</Panel>
|
||
)}
|
||
|
||
{/* ===== 编辑抽屉:人物 ===== */}
|
||
<Drawer open={showForm && panel === 'human'} onClose={closeForm} label="人物资产编辑"
|
||
title={<span title="编辑区已展开为全宽抽屉,长文本可直接拖拽调整高度">{editing.kind === 'human' ? '编辑人物' : '新建人物'}</span>}
|
||
actions={<>
|
||
{/* 浮层底部口径:辅助动作(mr-auto) → 取消 → 主行动。见 Overlay.DRAWER_ACTIONS 注释。 */}
|
||
<Button className="mr-auto" onClick={() => { setChar({ ...EMPTY_CHAR }); setEditing({ kind: '', id: null }) }}>清空</Button>
|
||
<Button onClick={closeForm}>取消</Button>
|
||
<Button type="primary" disabled={!!busy} onClick={saveCharacter}>{busy ? '处理中…' : '保存人物'}</Button>
|
||
</>}>
|
||
<FormGrid>
|
||
<FormRow>
|
||
<Field label="名称" required><Input value={char.name} placeholder="例如:林澈" onChange={(e) => patchChar({ name: e.target.value })} /></Field>
|
||
<Field label="代号"><Input value={char.code} placeholder="linche" onChange={(e) => patchChar({ code: e.target.value })} /></Field>
|
||
<Field label="定位">
|
||
<Select value={char.role} onChange={(v) => patchChar({ role: String(v) })} options={ROLE_OPTIONS} />
|
||
</Field>
|
||
<Field label="造型版本"><Input value={char.style_version} onChange={(e) => patchChar({ style_version: e.target.value })} /></Field>
|
||
</FormRow>
|
||
<FieldBlock label="外观描述(定妆图 + 镜头提示词)">
|
||
<TextArea rows={2} value={char.appearance} placeholder="黑色短发,深蓝战术服,左眼下方有疤——只写看得见的特征,气质/妆容类抽象词不会进入视频提示词" onChange={(e) => patchChar({ appearance: e.target.value })} />
|
||
</FieldBlock>
|
||
<FieldBlock label="性格设定">
|
||
<TextArea rows={2} value={char.personality} onChange={(e) => patchChar({ personality: e.target.value })} />
|
||
</FieldBlock>
|
||
<FieldBlock label="一致性提示词(仅用于生成定妆图/关键帧)">
|
||
<TextArea rows={2} value={char.persona_prompt} placeholder="同一张脸,五官比例保持一致——音画一体模型会把这段话当台词念出来,已不再注入镜头提示词" onChange={(e) => patchChar({ persona_prompt: e.target.value })} />
|
||
</FieldBlock>
|
||
<FormRow>
|
||
<Field label="声音描述"><Input value={char.voice_profile} placeholder="低沉、克制的青年男声" onChange={(e) => patchChar({ voice_profile: e.target.value })} /></Field>
|
||
<Field label="默认声线">
|
||
<Select value={char.default_voice_id} onChange={(v) => patchChar({ default_voice_id: v === null ? null : Number(v) })}
|
||
options={[{ value: null, label: '不绑定' }, ...voices.map((v) => ({ value: v.id, label: `${v.name} · ${v.provider}` }))]} />
|
||
</Field>
|
||
<Field label="标签(逗号分隔)"><Input value={char.tags} placeholder="人类, 一号角色" onChange={(e) => patchChar({ tags: e.target.value })} /></Field>
|
||
</FormRow>
|
||
</FormGrid>
|
||
</Drawer>
|
||
|
||
{/* ===== 编辑抽屉:场景 ===== */}
|
||
<Drawer open={showForm && panel === 'scene'} onClose={closeForm} label="场景资产编辑"
|
||
title={<span title="编辑区已展开为全宽抽屉,长文本可直接拖拽调整高度">{editing.kind === 'scene' ? '编辑场景' : '新建场景'}</span>}
|
||
actions={<>
|
||
{/* 浮层底部口径:辅助动作(mr-auto) → 取消 → 主行动。见 Overlay.DRAWER_ACTIONS 注释。 */}
|
||
<Button className="mr-auto" onClick={() => { setScene({ ...EMPTY_SCENE }); setEditing({ kind: '', id: null }) }}>清空</Button>
|
||
<Button onClick={closeForm}>取消</Button>
|
||
<Button type="primary" disabled={!!busy} onClick={saveScene}>{busy ? '处理中…' : '保存场景'}</Button>
|
||
</>}>
|
||
<FormGrid>
|
||
<FormRow>
|
||
<Field label="名称" required><Input value={scene.name} placeholder="例如:雨夜巷口" onChange={(e) => patchScene({ name: e.target.value })} /></Field>
|
||
<Field label="代号"><Input value={scene.code} placeholder="alley-rain" onChange={(e) => patchScene({ code: e.target.value })} /></Field>
|
||
</FormRow>
|
||
<FieldBlock label="场景描述">
|
||
<TextArea rows={2} value={scene.description} onChange={(e) => patchScene({ description: e.target.value })} />
|
||
</FieldBlock>
|
||
<FieldBlock label="提示词">
|
||
<TextArea rows={2} value={scene.prompt} onChange={(e) => patchScene({ prompt: e.target.value })} />
|
||
</FieldBlock>
|
||
<FormRow cols={3}>
|
||
<Field label="光线"><Input value={scene.lighting} onChange={(e) => patchScene({ lighting: e.target.value })} /></Field>
|
||
<Field label="时间"><Input value={scene.time_of_day} onChange={(e) => patchScene({ time_of_day: e.target.value })} /></Field>
|
||
<Field label="色调"><Input value={scene.palette} onChange={(e) => patchScene({ palette: e.target.value })} /></Field>
|
||
</FormRow>
|
||
<FieldBlock label="标签(逗号分隔)">
|
||
<Input value={scene.tags} onChange={(e) => patchScene({ tags: e.target.value })} />
|
||
</FieldBlock>
|
||
</FormGrid>
|
||
</Drawer>
|
||
|
||
{/* ===== 编辑抽屉:声线 ===== */}
|
||
<Drawer open={showForm && panel === 'voice'} onClose={closeForm} label="声线资产编辑"
|
||
title={<span title="编辑区已展开为全宽抽屉,长文本可直接拖拽调整高度">{editing.kind === 'voice' ? '编辑声线' : '新建声线'}</span>}
|
||
actions={<>
|
||
{/* 浮层底部口径:辅助动作(mr-auto) → 取消 → 主行动。见 Overlay.DRAWER_ACTIONS 注释。 */}
|
||
<Button className="mr-auto" onClick={clearVoiceForm}>清空</Button>
|
||
<Button onClick={closeForm}>取消</Button>
|
||
<Button type="primary" disabled={!!busy} onClick={saveVoice}>{busy ? '处理中…' : '保存声线'}</Button>
|
||
</>}>
|
||
<FormGrid>
|
||
<FormRow>
|
||
<Field label="名称" required><Input value={voice.name} placeholder="例如:低沉男声" onChange={(e) => patchVoice({ name: e.target.value })} /></Field>
|
||
<Field label="Provider"><Input value={voice.provider} placeholder="从下方选择真实模型" onChange={(e) => patchVoice({ provider: e.target.value })} /></Field>
|
||
{voice.provider === 'macos-say'
|
||
? <Field label="macOS 系统声音">
|
||
<Select value={voice.provider_voice_id} onChange={(v) => patchVoice({ provider_voice_id: String(v) })} options={sayVoiceOptions} />
|
||
</Field>
|
||
: <Field label="Provider voice_id"><Input value={voice.provider_voice_id} placeholder="填写供应商 voice_id" onChange={(e) => patchVoice({ provider_voice_id: e.target.value })} /></Field>}
|
||
<Field label="语言"><Input value={voice.language} onChange={(e) => patchVoice({ language: e.target.value })} /></Field>
|
||
<Field label="性别">
|
||
<Select value={voice.gender} onChange={(v) => patchVoice({ gender: String(v) })} options={GENDER_OPTIONS} />
|
||
</Field>
|
||
<Field label="版本"><Input value={voice.version} onChange={(e) => patchVoice({ version: e.target.value })} /></Field>
|
||
<Field label="语速">
|
||
<NumberInput min={0.5} max={2} step={0.05} value={voiceSpeed} onChange={ (v) => setVoiceSpeed(v)} />
|
||
</Field>
|
||
{voice.provider === 'macos-say' && (
|
||
<Field label="声音效果">
|
||
<Select value={voiceEffect} onChange={(v) => setVoiceEffect(String(v))} options={EFFECT_OPTIONS} placeholder="真实人声" />
|
||
</Field>
|
||
)}
|
||
</FormRow>
|
||
<FieldBlock label="音色描述">
|
||
<TextArea rows={2} value={voice.description} onChange={(e) => patchVoice({ description: e.target.value })} />
|
||
</FieldBlock>
|
||
<Check checked={!!voice.is_default} onChange={(v) => patchVoice({ is_default: v })}>设为项目默认声线</Check>
|
||
<Divider />
|
||
<SectionTitle className="mt-0" title="候选来自模型管理中心登记的 TTS 模型">可用声音模型</SectionTitle>
|
||
<ChipBar>
|
||
{ttsProviders.map((p) => (
|
||
<Chip key={p.id} active={p.provider === voice.provider} onClick={() => chooseTts(p)}>{p.display_name || p.model}</Chip>
|
||
))}
|
||
{!ttsProviders.length && <span className={MUTED}>未登记可用 TTS 模型</span>}
|
||
</ChipBar>
|
||
{voice.provider === 'macos-say' && (
|
||
<ChipBar top>
|
||
{SAY_VOICES.map((v) => (
|
||
<Chip key={v.value} active={voice.provider_voice_id === v.value} onClick={() => patchVoice({ provider_voice_id: v.value })}>{v.label}</Chip>
|
||
))}
|
||
</ChipBar>
|
||
)}
|
||
</FormGrid>
|
||
</Drawer>
|
||
|
||
{/* ===== LB-1:AI 生成台(全页共用一个右侧抽屉,卡片里只留一个入口) =====
|
||
旧版每张卡片内联一整套生成表单,五个人物就是五份模型下拉;
|
||
表单收进抽屉后卡片只剩 AiBar 一条入口,草稿仍按「类型:资产 id」分开存,切卡片不丢已填内容。
|
||
旧版这里还挂了全局 keydown 监听按 Esc 关抽屉(onLibKey),现在由 Drawer 统一处理。 */}
|
||
{genOwner && genDraft && (
|
||
<Drawer open={genPanel.open} onClose={closeGen}
|
||
label={`AI 生成${genLabel}素材`}
|
||
title={`${genLabel}「${genOwner.name}」`}
|
||
sub={<span className={MONO}>现有 {assetsOf(genOwner).length} 个版本 · {genType === 'voice'
|
||
? '试听样本会登记为新的音色版本'
|
||
: `出图 ${genCanvas[0]}×${genCanvas[1]}(跟随项目 ${project?.resolution || '1080p'} · ${project?.aspect_ratio || '16:9'})`}</span>}
|
||
actions={<>
|
||
{/* 浮层底部口径:辅助动作(mr-auto) → 取消 → 主行动。见 Overlay.DRAWER_ACTIONS 注释。 */}
|
||
{genType !== 'voice' && (
|
||
<Button className="mr-auto" disabled={!!busy || !llmProviders.length}
|
||
title="用大模型把资产设定改写成一段可复用的一致性提示词,先预览再决定采用"
|
||
onClick={() => suggestText(genSuggestType, genOwner)} icon={<IconBulb />}>AI 补全一致性提示词</Button>
|
||
)}
|
||
<Button onClick={closeGen}>取消</Button>
|
||
<Button type="primary" loading={!!busy} disabled={!genProvidersReady} onClick={genFromDrawer}
|
||
icon={genType === 'voice' ? <IconVoice /> : <IconImage />}>
|
||
{genType === 'voice' ? '生成试听样本' : `生成${assetKindLabel(genDraft.kind)}`}
|
||
</Button>
|
||
</>}>
|
||
<FormGrid>
|
||
{/* 纵向节奏由 Form.Item 自己给(24);提示词是长句,TextArea 按内容长高 */}
|
||
<div className="min-w-0">
|
||
{genType === 'voice' ? (
|
||
<>
|
||
<FormRow className="mb-0">
|
||
<Field label="声音模型" width="wide">
|
||
<Select value={genDraft.model_id} size="sm"
|
||
onChange={(v) => patchDraft(genType, genOwner, { model_id: v === null ? null : Number(v) })}
|
||
options={genProviders.map((p) => ({
|
||
value: p.id, label: `${p.display_name || p.model}${p.available ? '' : '(未就绪)'}` }))} />
|
||
</Field>
|
||
</FormRow>
|
||
<FieldBlock label="试听文本" required className="mb-0">
|
||
<TextArea rows={2} title="这是要念出来的台词,不是声线设定。" value={genDraft.sample_text} placeholder="输入一句要让模型朗读的台词,例如:在下郭靖,初次见面,请多指教。" onChange={(e) => patchDraft(genType, genOwner, { sample_text: e.target.value })} />
|
||
</FieldBlock>
|
||
<GenerationReference>
|
||
<Field label="参考音色" width="wide">
|
||
<Select value={genDraft.reference_asset_id} size="sm"
|
||
onChange={(v) => patchDraft(genType, genOwner, { reference_asset_id: v === null ? null : Number(v) })}
|
||
options={[
|
||
/* 「自动」到底自动成什么,必须写在这个选项上:留空时后端按性别借嗓子,
|
||
用户若以为会用本声线的参考,出来的音色就完全对不上。 */
|
||
{ value: null, label: `自动(${voiceRefStatus?.borrowed
|
||
? `本次借「${voiceRefStatus.voice_name || '同性别声线'}』的嗓子`
|
||
: voiceRefStatus && !voiceRefStatus.ready
|
||
? '库里没有同性别参考 · 会拦下'
|
||
: '用本声线已绑定的参考音频'})` },
|
||
...voiceReferenceOptions(genOwner).map((a: any) => ({
|
||
value: a.id, label: `${a.name} · ${assetKindLabel(a.kind)} v${a.version}` }))]} />
|
||
</Field>
|
||
<FilePick label="上传参考音色" accept="audio/*" className="flex-none border-primary-border text-primary"
|
||
onFiles={(files) => { const f = files[0]; if (f) void sendGenerationReference('voice', genOwner, f) }} />
|
||
<RecordAudio label="录参考音色" target="参考音色"
|
||
defaultName={defaultAssetName(genOwner.assets, `${genOwner.name}参考音色`, 'reference')}
|
||
names={existingNames(genOwner.assets)}
|
||
hint="弹出小面板:念几句话当作 IndexTTS2 的克隆参考,录完自动转成 WAV 并选中"
|
||
onPick={(file, meta) => void recordGenerationReference('voice', genOwner, file, meta)} />
|
||
<small className="flex-1 basis-[240px] text-xs leading-normal text-text-quaternary">
|
||
IndexTTS2 通过参考音频做 zero-shot 音色克隆;上传后会自动选中。
|
||
音色由参考音频决定,「性别 / 音色描述」对模型只是标注,所以留空时会拿到谁的嗓子必须实测告诉你:
|
||
</small>
|
||
{voiceRefStatus && (
|
||
<RefStatus ready={!!voiceRefStatus.ready} borrowed={!!voiceRefStatus.borrowed}
|
||
note={voiceRefStatus.note} />
|
||
)}
|
||
</GenerationReference>
|
||
</>
|
||
) : (
|
||
<>
|
||
<FormRow>
|
||
<Field label="图像模型">
|
||
<Select value={genDraft.model_id} size="sm"
|
||
onChange={(v) => patchDraft(genType, genOwner, { model_id: v === null ? null : Number(v) })}
|
||
options={genProviders.map((p) => ({
|
||
value: p.id, label: `${p.display_name || p.model}${p.available ? '' : '(未就绪)'}` }))} />
|
||
</Field>
|
||
{genType === 'human' && (
|
||
<Field label="生成类型">
|
||
<Select value={genDraft.kind} size="sm"
|
||
onChange={(v) => patchDraft(genType, genOwner, { kind: String(v) })}
|
||
options={[{ value: 'portrait', label: '定妆图' }, { value: 'turnaround', label: '三视图' },
|
||
{ value: 'costume', label: '服装设定' }, { value: 'expression', label: '表情参考' }]} />
|
||
</Field>
|
||
)}
|
||
<Field label="大模型(提示词补全)" title="只给下面「AI 补全一致性提示词」用,不参与出图">
|
||
<Select value={genDraft.assist_model_id} size="sm"
|
||
onChange={(v) => patchDraft(genType, genOwner, { assist_model_id: v === null ? null : Number(v) })}
|
||
options={llmProviders.map((p) => ({
|
||
value: p.id, label: `${p.display_name || p.model}${p.available ? '' : '(未就绪)'}` }))} />
|
||
</Field>
|
||
</FormRow>
|
||
<FieldBlock label={`生成描述(留空自动使用${genLabel}设定)`} className="mb-0">
|
||
<TextArea rows={3} value={genDraft.prompt} placeholder={genType === 'human' ? '电影级角色定妆照,冷色侧光,正面清晰' : '广角场景概念图,晨雾,冷色调,强透视'} onChange={(e) => patchDraft(genType, genOwner, { prompt: e.target.value })} />
|
||
</FieldBlock>
|
||
<GenerationReference>
|
||
<Field label="参考图" width="wide">
|
||
<Select value={genDraft.reference_asset_id} size="sm"
|
||
onChange={(v) => patchDraft(genType, genOwner, { reference_asset_id: v === null ? null : Number(v) })}
|
||
options={[{ value: null, label: '不使用参考图(纯文生图)' },
|
||
...imageReferenceOptions(genOwner).map((a: any) => ({
|
||
value: a.id, label: `${a.name} · ${assetKindLabel(a.kind)} v${a.version}` }))]} />
|
||
</Field>
|
||
<FilePick label="上传参考图" accept={IMAGE_REF_ACCEPT}
|
||
title="选择已有定妆 / 三视图 / 场景素材,或临时上传一张图作为本次生成锚点,可显著提升跨镜头一致性。"
|
||
className="flex-none border-primary-border text-primary"
|
||
onFiles={(files) => { const f = files[0]; if (f) void sendGenerationReference(genType, genOwner, f) }} />
|
||
</GenerationReference>
|
||
{genSuggestion && (
|
||
<SuggestionBox text={genSuggestion} busy={!!busy}
|
||
onApply={() => void applySuggestion(genSuggestType, genOwner)}
|
||
onDismiss={dismissSuggestion} />
|
||
)}
|
||
</>
|
||
)}
|
||
|
||
{/* 两条提示分开:选中那台未就绪只是黄条提醒,一台可用模型都没有才真正点不动生成 */}
|
||
{genProviderUnready && (
|
||
<ProviderWarning>当前模型未就绪,仍可选择;生成时会返回具体缺失节点或服务错误。</ProviderWarning>
|
||
)}
|
||
{!genProvidersReady && (
|
||
<ProviderWarning>
|
||
模型管理中心还没有可用的{genType === 'voice' ? '声音' : '图像'}模型,请先到
|
||
<Link to="/models" className={cn('mx-1', LINK_CLS)}>模型管理</Link>
|
||
登记并启用。
|
||
</ProviderWarning>
|
||
)}
|
||
</div>
|
||
</FormGrid>
|
||
</Drawer>
|
||
)}
|
||
</PageStack>
|
||
)
|
||
}
|
||
|
||
/* ============================================================================
|
||
* 页面局部组件:只有资产管理用得到,放进 components/ui 会让别处误以为是通用件。
|
||
* 类名逐条对着旧版 scoped CSS 搬(.lib-pick / .avatar / .usage-line / .ai-bar…),
|
||
* 改动请连同注释里的旧类名一起改,否则下次对不上号。
|
||
* ========================================================================== */
|
||
|
||
/** 勾选态(.cardrow.picked):左沿压一道强调色竖条 + 整块淡底,行首不再靠背景色单独说话 */
|
||
const PICKED = 'border-l-2 border-l-primary-border -ml-3 pl-2 rounded-md bg-primary-bg'
|
||
|
||
/**
|
||
* 卡片 / 表格行首的勾选框(.lib-pick):kit 的 Checkbox(antd 5 封装)。
|
||
*
|
||
* 不放可见文字,选的是谁由 aria-label 说明。Shift 连选要读 shiftKey,而它只在
|
||
* **事件**上:kit 的 onChange 给的是已经翻好的布尔值(键盘 Space 也走它,拿不到事件),
|
||
* 所以判定挂在 onClick 上——antd 的 onClick 落在 label 外壳,先于 input 的 change 触发,
|
||
* 中间 stopPropagation 只挡住往卡片冒泡(否则会连带选中镜头),不影响勾选本身翻转。
|
||
* 尺寸/圆角/深色底来自 theme/antd.ts 的 Checkbox token,不再是 accent-color 染出来的系统绿块。
|
||
*/
|
||
function PickBox({ checked, label, className, onToggle }: {
|
||
checked: boolean; label: string; className?: string; onToggle: (ev?: { shiftKey?: boolean }) => void
|
||
}) {
|
||
return (
|
||
<Checkbox checked={checked} aria-label={label}
|
||
onClick={(e) => onToggle(e)}
|
||
className={cn('cursor-pointer', className)} />
|
||
)
|
||
}
|
||
|
||
/** 人物头像位(.avatar):只有名字首字母,真定妆图在下方缩略图里 */
|
||
function Avatar({ name, children }: { name?: string; children: ReactNode }) {
|
||
return (
|
||
<div title={name} className="grid place-items-center w-8 h-8 shrink-0 rounded-lg bg-primary-bg-hover text-primary">
|
||
{children}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 引用情况一行(.usage-line + .shot-link)。
|
||
*
|
||
* 改设定前先看会不会影响成片:计数 + 最多 limit 个镜头锚点,
|
||
* 点进去由分镜页按 ?shot= 选中对应镜头。
|
||
*/
|
||
function UsageLine({ type, id, usage, projectId, limit = 5 }: {
|
||
type: string; id: number; projectId: number | null; limit?: number
|
||
usage: { count: number; shots: any[] }
|
||
}) {
|
||
return (
|
||
<TagGroup size="sm" className="mb-0 mt-2">
|
||
<Tag tone={usage.count ? 'ok' : 'default'}>被 {usage.count} 个镜头使用</Tag>
|
||
{(usage.shots || []).slice(0, limit).map((shot: any) => (
|
||
<Link key={shot.id} to={`/projects/${projectId}/storyboard?shot=${shot.id}`}
|
||
title={`跳转到分镜 #${shot.order_index}`}
|
||
className="no-underline hover:[&_span]:border-primary-active hover:[&_span]:text-primary-hover">
|
||
<Tag>#{shot.order_index} {shot.title}</Tag>
|
||
</Link>
|
||
))}
|
||
</TagGroup>
|
||
)
|
||
}
|
||
|
||
/** 全选条(.lib-selectall):虚线框贴在列表头上,右侧将来留给本面板计数/动作 */
|
||
function SelectAll({ checked, onChange, label }: {
|
||
checked: boolean; onChange: () => void; label: ReactNode
|
||
}) {
|
||
return (
|
||
<div className={cn('flex items-center justify-between gap-3 mb-2 px-3 py-2', 'border border-dashed border-border rounded-lg bg-bg-container')}>
|
||
<Check checked={checked} onChange={onChange} title="勾选后可批量上架 / 删除;按住 Shift 连选">{label}</Check>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 卡片上的生成入口(.ai-bar)。
|
||
*
|
||
* 「上次用的哪台模型」留在卡片上,抽屉只负责填参数:
|
||
* 用户回到列表想知道的是这张图有没有生成过,而不是再读一遍表单。
|
||
*/
|
||
function AiBar({ icon, label, title, last, disabled, disabledHint, onOpen }: {
|
||
icon: ReactNode; label: string; title?: string; last?: ReactNode
|
||
disabled?: boolean; disabledHint?: string; onOpen: () => void
|
||
}) {
|
||
return (
|
||
<div className={cn(' flex items-center flex-wrap gap-2 mt-3 px-3 py-2', 'border border-border rounded-lg bg-bg-container')}>
|
||
<b className="text-xs text-text-secondary"><IconText icon={icon}>{label}</IconText></b>
|
||
{last}
|
||
<Button type="primary" size="sm" className="ml-auto" disabled={disabled}
|
||
title={disabled ? disabledHint : '打开生成台(模型 / 类型 / 参考图 / 提示词)'}
|
||
onClick={onOpen}>打开生成台</Button>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
/** 参考素材行(.generation-reference):抽屉里唯一一处「选择 + 上传 + 录制」并排 */
|
||
function GenerationReference({ children }: { children: ReactNode }) {
|
||
return (
|
||
<Ctlbar className="m-0 py-2 px-3 border border-border rounded-md bg-bg-container">{children}</Ctlbar>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 音色预告(.ref-status)。
|
||
*
|
||
* IndexTTS2 的音色由参考音频决定,留空时后端会按性别「借」一条嗓子,
|
||
* 必须把借了谁写在生成按钮够得着的地方,而不是等失败才知道。
|
||
*/
|
||
function RefStatus({ ready, borrowed, note }: { ready: boolean; borrowed: boolean; note?: string }) {
|
||
return (
|
||
<p className={cn('flex-[1_1_100%] mt-0.5 mb-0 px-2 py-2 rounded-lg border '
|
||
+ 'text-xs leading-normal text-text',
|
||
!ready ? 'border-error-border bg-error-bg'
|
||
: borrowed ? 'border-warning-border bg-warning-bg'
|
||
: 'border-success-border bg-success-bg')}>
|
||
<b className="mr-1"><IconText icon={ready ? (borrowed ? <IconWarn /> : <IconPass />)
|
||
: <IconReject />}>{ready ? '本次音色' : '现在还不能生成'}</IconText></b>
|
||
{note}
|
||
</p>
|
||
)
|
||
}
|
||
|
||
/** 模型未就绪 / 完全没模型的提醒(.provider-warning):说清楚是「还能选」还是「点不动」 */
|
||
function ProviderWarning({ children }: { children: ReactNode }) {
|
||
return (
|
||
<small className="block mt-2 px-2 py-2 border border-warning-border rounded-sm bg-warning-bg text-warning text-xs leading-normal">
|
||
{children}
|
||
</small>
|
||
)
|
||
}
|
||
|
||
/** AI 补全结果的预览框(.suggestion-box):先预览再采用,避免一句话直接盖掉已写好的提示词 */
|
||
function SuggestionBox({ text, busy, onApply, onDismiss }: {
|
||
text: string; busy: boolean; onApply: () => void; onDismiss: () => void
|
||
}) {
|
||
return (
|
||
<div className="p-2 bg-primary-bg border border-primary-border rounded-md">
|
||
<p className="m-0 mb-2 text-xs leading-relaxed text-text-secondary">{text}</p>
|
||
<Actions className="mt-0">
|
||
<Button type="primary" size="sm" disabled={busy} onClick={onApply}>采用为一致性提示词</Button>
|
||
<Button size="sm" onClick={onDismiss}>放弃</Button>
|
||
</Actions>
|
||
</div>
|
||
)
|
||
}
|