1724 lines
100 KiB
TypeScript
1724 lines
100 KiB
TypeScript
/**
|
||
* 资产管理(图2 节点 ②③④ 的一致性底座)。
|
||
*
|
||
* - 人物 / 场景 / 声线三类可复用资产 + 项目级素材(配乐 / 音效 / 通用参考)
|
||
* - 每个资产都能单独调用模型生成新版本;绑定到分镜后自动进入视频参考素材与提示词
|
||
* - LB-1:AI 生成表单从每张卡片里抽出来,全页共用一个右侧抽屉
|
||
* - LB-4:跨字段搜索 / 素材情况 / 镜头引用筛选 + Shift 连选批量上架、删除
|
||
*
|
||
* **呈现层与平台资产库(`pages/AssetLibrary.tsx`)同构**(2026-11-11 · 用户第 1 条):
|
||
* 同一族统计卡(`StatGrid` 四张可点)、页签在 `Panel` 外、一张卡装下
|
||
* 「卡头 + `Ctlbar` + `ChipBar` + 批量 `Block` + 网格/列表」、卡片走 `Tile variant="pick"`
|
||
* + `MediaPick` + 右上角那一对 `size="sm"`(§5.1.2.1 唯一档位,实底只给「编辑」)、
|
||
* 摘要行用 `TILE_SUMMARY`(尺子在 `ui/Tile.tsx`,两页共用一把)。
|
||
* 同构的是**呈现层**,不是数据层:本页四类面板的数据整份在前端,
|
||
* 没有 `page` / `page_size` 可传,因此**不渲染 `Pager`**,命中回显写在 `<BarRight>`
|
||
* (口径见 `UI规范.md` §12.3,例外登记在 `NEX-对照与例外.md` §3 E11)。
|
||
*
|
||
* 勾选态在 React 侧走 `picks`(`Set<面板:id>`)+ `MediaPick` / `Checkbox` 的受控 `checked`,
|
||
* 不再依赖旧站 `.cardrow.picked` 那套 CSS 类。
|
||
*/
|
||
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 { MediaPick, MediaThumb } from '../../components/media/MediaThumb'
|
||
import { RecordAudio, type RecordPickMeta } from '../../components/media/RecordAudio'
|
||
import { ActionGroup, BarRight, Block, Button, CardActions, Check, Checkbox, Chip, ChipBar, Ctlbar, Divider, Drawer, Empty, ExtLink, Field, FieldBlock, FilePick, FormGrid, FormRow, Grid, Input, LINK_CLS, LineHint, LinkButton, MONO, MUTED, MUTED_MONO, Notice, NumberInput, PageHead, PageStack, Panel, PanelHead, SearchInput, SectionTitle, Spinner, Stat, StatGrid, Tabs, Tag, TagGroup, TextArea, Tile, TILE_SUMMARY, Value, ViewSwitch } from '../../components/ui'
|
||
import { useSystemStore } from '../../stores/system'
|
||
import { refresh, useProjectStore } from '../../stores/project'
|
||
import { notify } from '../../stores/notice'
|
||
import { confirmAction } from '../../stores/confirm'
|
||
import { IconAdd, IconBolt, IconCaution, IconCheck, IconChevronUp, IconClose, IconDelete, IconGrid, IconImage, IconLibrary, IconSync, IconTracks, IconUser } from '../../components/icons'
|
||
import { IconBlocks, IconBulb, IconEdit, IconList, IconParams, IconUpload, IconVoice } from '../../components/icons/extra'
|
||
|
||
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: '项目素材' }
|
||
/** 全选框里的量词跟面板走:中文里「个人物 / 条声线」读起来才对,统一成「个」会像机器话 */
|
||
const SELECT_UNIT: 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 IMAGE_REF_ACCEPT = 'image/*'
|
||
|
||
/** 页签的识别图形与一句话说明(与平台资产库的 TYPE_META 同一族:新增一类只改这张表) */
|
||
const PANEL_META: Record<PanelKey, { icon: ReactNode; hint: string }> = {
|
||
human: { icon: <IconUser />, hint: '定妆、造型与角色一致性' },
|
||
scene: { icon: <IconImage />, hint: '空间、光线与美术基调' },
|
||
voice: { icon: <IconVoice />, hint: '音色样本与配音参数' },
|
||
project: { icon: <IconBlocks />, hint: '配乐、音效与通用参考' }
|
||
}
|
||
/** 视图切换:切完看的还是这批数据 → Segmented,不是 Tabs(kit Tabs 注释里的判据) */
|
||
const VIEW_ITEMS: { value: 'grid' | 'list'; label: ReactNode; hint: string }[] = [
|
||
{ value: 'grid', label: <><IconGrid />网格</>, hint: '网格视图:卡片信息最全' },
|
||
{ value: 'list', label: <><IconList />列表</>, hint: '列表视图:一屏看更多,便于批量勾选' }
|
||
]
|
||
/** 每个面板允许登记的素材类型:既是卡上「上传」下拉的选项,也是项目素材的类型筛选 */
|
||
const UPLOAD_KINDS: Record<PanelKey, string[]> = {
|
||
human: ['portrait', 'turnaround', 'costume', 'expression', 'reference'],
|
||
scene: ['scene_image', 'reference'],
|
||
voice: ['voice_sample', 'reference'],
|
||
project: PROJECT_ASSET_KINDS
|
||
}
|
||
/** 上传接受的文件类型:声线收音频,其余收图片(与既有各颗 FilePick 的 accept 一致) */
|
||
const UPLOAD_ACCEPT: Record<PanelKey, string> = {
|
||
human: IMAGE_REF_ACCEPT, scene: IMAGE_REF_ACCEPT, voice: 'audio/*', project: ''
|
||
}
|
||
/** 卡片摘要行:与平台资产库共用 Tile 里那一把尺子 */
|
||
const SUMMARY = TILE_SUMMARY
|
||
|
||
/**
|
||
* 卡片摘要行取哪一句设定:三类母版的「主设定」字段名不同,
|
||
* 但卡片上永远只有一句人话(与平台资产库的取值顺序一致)。
|
||
*/
|
||
function summaryOf(type: GenType, row: any) {
|
||
return type === 'human' ? row.persona_prompt || row.appearance || row.personality
|
||
: type === 'scene' ? row.prompt || row.description
|
||
: row.description || row.persona_prompt || ''
|
||
}
|
||
/** 标签行之后的「这一类的关键属性」,一格一枚(长句由 kit 的 ellipsis 收尾) */
|
||
function metaTagsOf(type: GenType, row: any): ReactNode {
|
||
if (type === 'human') {
|
||
return <>
|
||
<Tag>{row.role || '角色'}</Tag>
|
||
{!!row.default_voice_name && <Tag title={`默认声线:${row.default_voice_name}`}>声线 · {row.default_voice_name}</Tag>}
|
||
<Tag>{row.style_version || 'v1'}</Tag>
|
||
</>
|
||
}
|
||
if (type === 'scene') {
|
||
const look = [{ k: '光线', v: row.lighting }, { k: '时段', v: row.time_of_day }, { k: '色板', v: row.palette }]
|
||
.filter((entry) => entry.v)
|
||
return look.length
|
||
? <>{look.map((entry) => <Tag key={entry.k} title={`${entry.k}:${entry.v}`}>{entry.v}</Tag>)}</>
|
||
: <Tag tone="warn">未设定光线</Tag>
|
||
}
|
||
return <>
|
||
<Tag title="配音通道与语言">{row.provider || '生成时选模型'} · {row.language || 'zh-CN'}</Tag>
|
||
<Tag>{GENDER_LABEL[row.gender] || '中性'}</Tag>
|
||
<Tag>v{row.version || 'v1'}</Tag>
|
||
</>
|
||
}
|
||
/** 空态里「下一步做什么」的一句话:三类各说自己的,不写通用套话 */
|
||
const EMPTY_HINT: Record<GenType, string> = {
|
||
human: ',建立人物并上传定妆图,导入分镜时就能按名称自动绑定。',
|
||
scene: ',导入分镜时脚本里的「场景:」字段会按名称匹配这里登记的内容。',
|
||
voice: ',先登记声线基础设定,再到生成台选择真实 TTS 模型。'
|
||
}
|
||
/** AI 生成按钮禁用的原因:图像与声音两条通道各有各的注册表分类 */
|
||
const GEN_DISABLED_HINT: Record<GenType, string> = {
|
||
human: '模型管理中心还没有可用的图像模型',
|
||
scene: '模型管理中心还没有可用的图像模型',
|
||
voice: '模型管理中心还没有可用的声音模型'
|
||
}
|
||
|
||
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 [keyword, setKeyword] = useState('')
|
||
/* 筛选口径与平台资产库同构(2026-11-11 · 用户第 1 条):
|
||
以前是两颗 Chip(缺素材 / 未被镜头使用),只能「看没有的」、看不到「有的」,
|
||
也没有标签入口;现在换成与平台同一族的三个下拉 + 一排标签胶囊。 */
|
||
const [mediaFilter, setMediaFilter] = useState('') // '' | with | without
|
||
const [usageFilter, setUsageFilter] = useState('') // '' | used | unused
|
||
const [tagFilter, setTagFilter] = useState('')
|
||
/** 项目素材面板的素材类型筛选(对应平台「素材类型」下拉) */
|
||
const [kindFilter, setKindFilter] = useState('')
|
||
/** 母版视图:网格=信息最全;列表=一屏更多、便于批量勾选(与平台同一族 ViewSwitch) */
|
||
const [view, setView] = useState<'grid' | 'list'>('grid')
|
||
/** 每张卡「上传」走哪个素材类型,按 面板:资产 id 存,切卡不丢已选类型 */
|
||
const [uploadKinds, setUploadKinds] = useState<Record<string, string>>({})
|
||
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])
|
||
/** 注册表在回调里也要读到最新值,但抽屉要显示「所选通道不可用」→ 统一走这份订阅 */
|
||
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)
|
||
&& (!mediaFilter || (mediaFilter === 'without' ? !(row.assets || []).length : !!(row.assets || []).length))
|
||
&& (!usageFilter || (usageFilter === 'unused' ? !usageFor(type, row.id).count : !!usageFor(type, row.id).count))
|
||
&& (!tagFilter || (row.tags || []).includes(tagFilter)))
|
||
/** 项目素材面板没有「缺素材」与「镜头引用」两问,但类型与搜索同构(复用同一套匹配语义) */
|
||
const shownProjectAssets = projectAssets.filter((a: any) => (!kindFilter || a.kind === kindFilter)
|
||
&& 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 : shownProjectAssets
|
||
/** 这一屏的总数与命中数:没有 <Pager>(数据整份在前端),命中回显只能住在筛选条右端 */
|
||
const panelTotal = panel === 'human' ? characters.length
|
||
: panel === 'scene' ? scenes.length
|
||
: panel === 'voice' ? voices.length : projectAssets.length
|
||
const shownCount = panelRows.length
|
||
/** 命中数只在真的有筛选条件时出现,且不能跨面板串数字 */
|
||
const filterActive = !!keyword.trim()
|
||
|| (panel === 'project' ? !!kindFilter : !!mediaFilter || !!usageFilter || !!tagFilter)
|
||
/* 标签胶囊:只数当前面板(未过标签这一道,否则点下去之后计数会自己塌成 0) */
|
||
const tagOptions = useMemo(() => {
|
||
const tally = new Map<string, number>()
|
||
for (const row of panel === 'project' ? [] : panel === 'human' ? characters
|
||
: panel === 'scene' ? scenes : voices) {
|
||
for (const tag of (row.tags || []) as string[]) tally.set(tag, (tally.get(tag) || 0) + 1)
|
||
}
|
||
return [...tally.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
||
.map(([tag, count]) => ({ tag, count }))
|
||
}, [panel, characters, scenes, voices])
|
||
/** 可批量的行:项目素材面板里是素材而不是母版,批量上架 / 批量删除对它没有意义 */
|
||
const pickRows = panel === 'project' ? [] : panelRows
|
||
const pickedRows = pickRows.filter((row) => picks.has(`${panel}:${row.id}`))
|
||
const allPicked = !!pickRows.length && pickRows.every((row) => picks.has(`${panel}:${row.id}`))
|
||
const pickedUsed = pickedRows.filter((row) => usageFor(panel, row.id).count).length
|
||
|
||
/* ---------- 统计卡:四张卡本身就是筛选入口(与平台资产库 AS-7 同一族) ---------- */
|
||
const masterRows = useMemo(() => [
|
||
...characters.map((row: any) => ({ row, type: 'human' as GenType })),
|
||
...scenes.map((row: any) => ({ row, type: 'scene' as GenType })),
|
||
...voices.map((row: any) => ({ row, type: 'voice' as GenType })),
|
||
], [characters, scenes, voices])
|
||
const totals = {
|
||
masters: masterRows.length,
|
||
media: masterRows.reduce((n: number, it: any) => n + assetsOf(it.row).length, 0) + projectAssets.length,
|
||
without: masterRows.filter((it: any) => !assetsOf(it.row).length).length,
|
||
unused: masterRows.filter((it: any) => !usageFor(it.type, it.row.id).count).length
|
||
}
|
||
/** 卡上「上传」默认走哪个类型:没选过就用这一类的第一个(与平台 uploadKindFor 同构) */
|
||
const uploadKindOf = (id: number) => uploadKinds[`${panel}:${id}`] || UPLOAD_KINDS[panel][0]
|
||
/** 当前面板的 AI 生成走哪条通道:卡上的「AI 生成 / 生成试听」按它禁用(与抽屉同源) */
|
||
const genKindProviders = panel === 'voice' ? ttsProviders : imageProviders
|
||
|
||
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 && pickRows.length) {
|
||
const lastKey = [...next].pop()
|
||
const lastIndex = pickRows.findIndex((r) => `${panel}:${r.id}` === lastKey)
|
||
const index = pickRows.findIndex((r) => r.id === row.id)
|
||
if (lastIndex >= 0 && index >= 0) {
|
||
pickRows.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) pickRows.forEach((row) => next.delete(`${panel}:${row.id}`))
|
||
else pickRows.forEach((row) => next.add(`${panel}:${row.id}`))
|
||
setPicks(next)
|
||
}
|
||
function clearPicks() { setPicks(new Set()) }
|
||
/* 症状:全选条原本是列表上方一整个虚线盒,只装了一颗勾选框,白占一行。
|
||
做法:做成卡头右端的一个节点,和面板标题共用同一行;空面板不渲染,
|
||
免得写出「全选当前 0 个人物」。批量条仍按当前面板解释勾选。 */
|
||
const selAll = () => (pickRows.length
|
||
? <SelectAll checked={allPicked} onChange={checkAllRows}
|
||
label={`全选当前 ${pickRows.length} ${SELECT_UNIT[panel]}`} />
|
||
: undefined)
|
||
function resetFilters() {
|
||
setKeyword(''); setMediaFilter(''); setUsageFilter(''); setTagFilter(''); setKindFilter('')
|
||
}
|
||
/* ---------- 统计卡的四条落点:数字点下去就到对应视角,不用先翻筛选下拉 ---------- */
|
||
/** 回到母版视角:清空筛选、离开项目素材面板、回到网格 */
|
||
function focusMasters() {
|
||
resetFilters(); setView('grid')
|
||
if (panel === 'project') choosePanel('human')
|
||
}
|
||
function focusWall() {
|
||
resetFilters(); setView('grid'); choosePanel('project')
|
||
}
|
||
function focusWithout() {
|
||
resetFilters(); setView('grid'); setMediaFilter('without')
|
||
if (panel === 'project') choosePanel('human')
|
||
}
|
||
function focusUnused() {
|
||
resetFilters(); setView('grid'); setUsageFilter('unused')
|
||
if (panel === 'project') choosePanel('human')
|
||
}
|
||
/** 切面板同时收起表单与勾选:批量动作是按面板解释的,留着跨面板的勾选会误删 */
|
||
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
|
||
/* R19 ④:这一句原来是不带 window. 的**裸调用原生对话框**,和 window.confirm 同一个东西
|
||
(classaudit 第 6 闸放宽正则后才抓到)——问话与后果挤成一行、字体与按钮全归操作系统。
|
||
现在拆成 title(问话)/ desc(后果)两层。tone=info:上架不删东西、可逆,不该亮红。
|
||
(注释里刻意不写那个函数名的字面量形式:本闸按字面量匹配,块注释它剥不掉。)*/
|
||
if (!(await confirmAction({
|
||
title: `将选中的 ${rows.length} 个${PANEL_LABEL[panel]}上架为平台母版?`,
|
||
desc: '上架后平台资产库会出现对应的母版;库里已有同名的不新增条目,只更新同一个母版。',
|
||
tone: 'info', confirmText: '上架', confirmIcon: <IconLibrary />
|
||
}))) 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
|
||
}
|
||
/* 原生框里的 `\n` 只是某些浏览器才认的运气(R19 ④);换行交给 desc 的 JSX 自己排。 */
|
||
if (!(await confirmAction({
|
||
title: `删除选中的 ${free.length} 个${PANEL_LABEL[panel]}?`,
|
||
desc: (<>素材的版本一并删除,已生成的镜头产物不受影响。
|
||
{used.length ? <>另有 {used.length} 个仍被镜头引用,会自动跳过。</> : null}</>),
|
||
tone: 'danger', confirmText: '删除', confirmIcon: <IconDelete />
|
||
}))) 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 }
|
||
/* 只保留还活着的那几个音色参数:speed 是 ffmpeg 后期调的,
|
||
params 里原来的 effect(外星低吼)只有 macOS say 认,随适配器一起退役。 */
|
||
const body = {
|
||
...voice,
|
||
provider_voice_id: voice.provider_voice_id || voice.name,
|
||
tuning: { ...(voice.tuning || {}), speed: Number(voiceSpeed) || 1 },
|
||
}
|
||
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)
|
||
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))
|
||
}
|
||
setPanel(kind)
|
||
setShowForm(true)
|
||
}
|
||
|
||
/** 点候选模型 = 一次性把 provider 和它自带的 voice 填好,省得两边填歪 */
|
||
function chooseTts(p: ModelRow) {
|
||
patchVoice({ provider: p.provider, provider_voice_id: p.config?.voice || p.model })
|
||
}
|
||
|
||
function clearVoiceForm() {
|
||
setVoice({ ...EMPTY_VOICE, tuning: {} })
|
||
setVoiceSpeed(1)
|
||
setEditing({ kind: '', id: null })
|
||
}
|
||
|
||
async function drop(kind: string, row: any) {
|
||
if (!(await confirmAction({
|
||
title: `删除「${row.name}」?`,
|
||
desc: '这条素材的资产版本一并删除;已经生成的镜头产物不会被删除。',
|
||
tone: 'danger', confirmText: '删除', confirmIcon: <IconDelete />
|
||
}))) return
|
||
await run('删除', () => api.del(`/api/projects/${projectId}/${kind}/${row.id}`))
|
||
}
|
||
|
||
async function publish(kind: GenType, row: any) {
|
||
if (!(await confirmAction({
|
||
title: `将「${row.name}」上架为平台${PANEL_LABEL[kind]}母版?`,
|
||
desc: '平台资产库里已有同名的不新增条目,只给那个母版追加一个版本。',
|
||
tone: 'info', confirmText: '上架', confirmIcon: <IconLibrary />
|
||
}))) 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`
|
||
|
||
/* 一次操作链只播一句吐司的两个零件(§13.3 ⑤ · N10):speak 决定「这一步的话是自己弹还是交出去」,
|
||
joinLines 把交出来的话并成一句,中间用「;」——都是给人读的话,不是日志。 */
|
||
const speak = (into: string[] | undefined, msg: string) => { if (into) into.push(msg); else notify(msg) }
|
||
const joinLines = (lines: string[]) => lines.filter(Boolean).join(';') || '已完成'
|
||
|
||
/** 上传与录音共用的落库通道:两条路必须登记出完全同构的版本。
|
||
`into`(§13.3 ⑤ N10):录音链一次会说话三回(登记版本 / 版本指针 / 时长警告),
|
||
传收集器时这一步把话交出去、自己不弹,由调用方合成**一颗**吐司。不传 = 原样弹。 */
|
||
async function uploadFileTo(path: string, kind: string, file: File, name = '', note = '', into?: string[]) {
|
||
setBusy(`上传${assetKindLabel(kind)}`)
|
||
setError('')
|
||
try {
|
||
const row: any = await api.upload(path, api.formData({ kind, name: name || file.name, note }, file))
|
||
speak(into, `${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)
|
||
}
|
||
}
|
||
|
||
/** 项目声线卡上的「录一段」:录完直接当音色样本/参考的新版本入库。
|
||
一次录音 = 一句反馈(§13.3 ⑤):三句话收进 lines,最后合成一颗吐司。 */
|
||
async function onRecord(path: string, kind: string, name: string, file: File, meta: RecordPickMeta) {
|
||
const lines: string[] = []
|
||
const row = await uploadFileTo(path, kind, file, (meta.name || '').trim() || name, '页面录制', lines)
|
||
if (!row) return
|
||
await keepOrRestoreCurrent(row, meta.setCurrent !== false, (m) => lines.push(m))
|
||
if (meta.warning) lines.push(`已录 ${(meta.durationMs / 1000).toFixed(1)} 秒:${meta.warning}`)
|
||
notify(joinLines(lines))
|
||
}
|
||
|
||
/** 生成台的参考素材上传(文件选择器与页面录音都走这里,上传完自动选中) */
|
||
async function sendGenerationReference(type: GenType, owner: any, file: File, note = '', name = '', into?: string[]) {
|
||
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 })
|
||
speak(into, `${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 lines: string[] = []
|
||
const row = await sendGenerationReference(type, owner, file, '页面录制', meta.name, lines)
|
||
if (!row) {
|
||
/* 上传就失败了:错误走页内 ErrorText,这里不补吐司——空 lines 走 joinLines 会吐出
|
||
「已完成」,那是**假成功**(§13.3 ⑤ 判据反例)。时长警告照旧留一颗,和改前一致。 */
|
||
if (meta.warning) notify(meta.warning)
|
||
return
|
||
}
|
||
await keepOrRestoreCurrent(row, meta.setCurrent !== false, (m) => lines.push(m))
|
||
if (meta.warning) lines.push(meta.warning)
|
||
notify(joinLines(lines))
|
||
}
|
||
|
||
async function dropAsset(asset: any) {
|
||
if (!(await confirmAction({
|
||
title: `删除素材「${asset.name}」?`,
|
||
desc: '这个素材文件从项目里删掉,不再出现在素材列表中;已经生成的镜头产物不受影响。',
|
||
tone: 'danger', confirmText: '删除', confirmIcon: <IconDelete />
|
||
}))) 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[]
|
||
|
||
return (
|
||
<PageStack>
|
||
{/* 页头(第 1 条):环节名 + 职责说明 + 这一页的主操作。
|
||
主操作是「新建当前面板的资产」——它整页成立,所以进 PageHead;
|
||
两个跨页跳转是另一层意思,自成一组并排放左边。 */}
|
||
<PageHead
|
||
title="资产管理"
|
||
sub="集中维护人物、声音与场景。资产可单独调用模型生成,绑定到分镜后会自动进入视频参考素材与提示词。"
|
||
actions={<>
|
||
<ActionGroup>
|
||
<LinkButton icon={<IconLibrary />} to="/assets">平台资产库</LinkButton>
|
||
<LinkButton icon={<IconParams />} to="/models">配置生成模型</LinkButton>
|
||
</ActionGroup>
|
||
{panel !== 'project' && (
|
||
<Button icon={showForm ? <IconChevronUp /> : <IconAdd />} type="primary"
|
||
onClick={() => setShowForm(!showForm)}>
|
||
{showForm ? `收起${PANEL_LABEL[panel]}表单` : `新建${PANEL_LABEL[panel]}`}
|
||
</Button>
|
||
)}
|
||
</>}
|
||
/>
|
||
|
||
<Notice danger>{error}</Notice>
|
||
|
||
{/* 四张卡本身就是筛选入口(与平台资产库 AS-7 同一族):数字点下去就到对应视角,
|
||
不用先去翻筛选下拉;命中态与下方筛选条件同源,所以筛选变了卡也会跟着亮。 */}
|
||
<StatGrid>
|
||
<Stat tone="lead" icon={<IconGrid />} label="项目资产" value={totals.masters}
|
||
title="清空筛选,回到人物 / 场景 / 声线的网格视图"
|
||
active={panel !== 'project' && !filterActive} onClick={focusMasters}
|
||
hint={`人物 ${characters.length} · 场景 ${scenes.length} · 声线 ${voices.length}`} />
|
||
<Stat icon={<IconBlocks />} label="已登记素材" value={totals.media}
|
||
title="切到「项目素材」面板,直接翻找配乐 / 音效 / 通用参考"
|
||
active={panel === 'project'} onClick={focusWall}
|
||
hint={`其中项目级素材 ${projectAssets.length} 个`} />
|
||
<Stat icon={<IconCaution />} label="待补素材" value={totals.without}
|
||
title="只看还没有任何素材的人物 / 场景 / 声线(补齐定妆图 / 试听样本)"
|
||
active={panel !== 'project' && mediaFilter === 'without'} onClick={focusWithout}
|
||
hint="档案已建,但一张图 / 一段音都没有" />
|
||
<Stat tone="warn" icon={<IconTracks />} label="未被镜头使用" value={totals.unused}
|
||
title="只看还没被任何镜头引用的资产,便于清理"
|
||
active={panel !== 'project' && usageFilter === 'unused'} onClick={focusUnused}
|
||
hint="绑进分镜后才会进入提示词与参考素材" />
|
||
</StatGrid>
|
||
|
||
{/* 大分类 = 页面内部页签,坐在 Panel 之外(与平台资产库同一层级):
|
||
页签回答「看哪一份」,卡头的切换器回答「这一份怎么排」,两层各说各的。
|
||
图形与 hint 走 PANEL_META,新增一个面板只改那张表。 */}
|
||
<Tabs activeKey={panel} onChange={(k) => choosePanel(k as PanelKey)}
|
||
items={PANEL_KEYS.map((key) => ({
|
||
key,
|
||
label: PANEL_LABEL[key],
|
||
icon: PANEL_META[key].icon,
|
||
count: key === 'human' ? characters.length
|
||
: key === 'scene' ? scenes.length
|
||
: key === 'voice' ? voices.length : projectAssets.length,
|
||
hint: `${PANEL_META[key].hint}。资产在本项目内独立维护,上架后才进入平台母版`
|
||
}))} />
|
||
|
||
{/* 一张卡装下「卡头 + 筛选 + 标签 + 列表」:
|
||
以前页签 / 搜索 / 批量条 / 内容各是一张卡,卡里套盒子、盒子里再套盒子。 */}
|
||
<Panel>
|
||
{/* 卡头不写标题:上方页签与右端切换器已经各说了一遍「看哪一份 / 怎么排」,
|
||
卡头第三次复述就是三级重复标题(§13.6)。全选与数量交给批量条和卡头右端。 */}
|
||
<PanelHead right={<>
|
||
{selAll()}
|
||
<ViewSwitch value={view} onChange={setView} items={VIEW_ITEMS} className="shrink-0" />
|
||
</>} />
|
||
|
||
{/* 筛选栏:坐在卡正文里,不再自己描边(站内有边框的横块只有 Card 一种)。
|
||
字段口径与平台资产库一致:搜索 / 素材情况 / 镜头引用(项目素材换成素材类型)。
|
||
⚠ cols 取 5 而这一条只有四个块,是刻意的:`cols` 真正决定的是**降列节奏**
|
||
(`grid.tsx::ROW_STEPS`),而栅格断点读的是**视口**、正文却只有 512
|
||
(侧栏 224 + 内边距 32)。四等分那一档在 768 视口给三列,每格 162,
|
||
「素材情况」这种四字标签之后只剩 106 给下拉,当前值「全部情况」78 被裁成 51
|
||
(visualcheck 768 档两条红灯);平台资产库那一侧走 5 等分这一档,768 折两列、
|
||
每格 250,所以同一句标签它量得下。要「与平台一致」就得连这一档一起一致。 */}
|
||
<Ctlbar className="mb-1" cols={5}>
|
||
<Field inline label="搜索" width="grow" title="跨字段匹配名称、代号、设定、提示词、标签与素材文件名">
|
||
<SearchInput aria-label="搜索当前面板" value={keyword}
|
||
placeholder={panel === 'project' ? '名称 / 类型 / 文件名…' : '名称 / 代号 / 设定 / 标签 / 素材文件名…'}
|
||
onChange={(e) => setKeyword(e.target.value)} />
|
||
</Field>
|
||
{panel === 'project' ? (
|
||
<Field inline label="素材类型" title="选项只列项目级素材实际能收下的类型">
|
||
<Select value={kindFilter} ariaLabel="按素材类型筛选"
|
||
onChange={(next) => setKindFilter(String(next))}
|
||
options={[{ value: '', label: '全部类型' },
|
||
...UPLOAD_KINDS.project.map((kind) => ({ value: kind, label: assetKindLabel(kind) }))]} />
|
||
</Field>
|
||
) : (
|
||
<>
|
||
<Field inline label="素材情况">
|
||
<Select value={mediaFilter} ariaLabel="按素材情况筛选"
|
||
onChange={(next) => setMediaFilter(String(next))}
|
||
options={[{ value: '', label: '全部情况' },
|
||
{ value: 'with', label: '已有素材' }, { value: 'without', label: '待补素材' }]} />
|
||
</Field>
|
||
<Field inline label="镜头引用">
|
||
<Select value={usageFilter} ariaLabel="按镜头引用情况筛选"
|
||
onChange={(next) => setUsageFilter(String(next))}
|
||
options={[{ value: '', label: '全部引用' },
|
||
{ value: 'used', label: '已被使用' }, { value: 'unused', label: '未被使用' }]} />
|
||
</Field>
|
||
</>
|
||
)}
|
||
<BarRight>
|
||
{/* 只在真的有筛选时报命中数:没筛选时这个数已经写在页签角标上,
|
||
卡头/筛选条再念一遍就是 §13.6 的同一句话复读。
|
||
平台资产库把数量交给卡底 <Pager>,本页数据整份在前端、不分页,
|
||
所以命中回显留在筛选条右端(例外已登记在 NEX-对照与例外 §3)。 */}
|
||
{filterActive && (
|
||
<span className={cn(MUTED_MONO, 'text-xs')}
|
||
title={`当前筛选命中 ${shownCount} 个,这一类共 ${panelTotal} 个`}>
|
||
命中 {shownCount} / {panelTotal}
|
||
</span>
|
||
)}
|
||
{busy && <span className={cn(MUTED, 'text-xs')}><Spinner /> {busy}…</span>}
|
||
</BarRight>
|
||
</Ctlbar>
|
||
|
||
{/* 标签胶囊:平台资产库同一族。项目素材没有标签,这一行只出现在三类母版面板。 */}
|
||
{tagOptions.length > 0 && (
|
||
<ChipBar label="标签">
|
||
<Chip active={!tagFilter} onClick={() => setTagFilter('')}>全部</Chip>
|
||
{tagOptions.map((entry) => {
|
||
const on = tagFilter === entry.tag
|
||
return (
|
||
<Chip key={entry.tag} active={on}
|
||
title={`只看带「${entry.tag}」标签的${PANEL_LABEL[panel]}(${entry.count} 个)`}
|
||
onClick={() => setTagFilter(on ? '' : entry.tag)}>
|
||
{entry.tag}
|
||
<em className={cn('not-italic text-xs', on ? 'text-on-primary opacity-70' : 'text-text-quaternary')}>
|
||
{entry.count}
|
||
</em>
|
||
</Chip>
|
||
)
|
||
})}
|
||
{filterActive && (
|
||
<Chip className="border-dashed text-warning" onClick={resetFilters}><IconClose />清除全部筛选</Chip>
|
||
)}
|
||
</ChipBar>
|
||
)}
|
||
|
||
{/* 勾选之后才出现的批量条:卡内的语义块,而不是页面里第二张卡 */}
|
||
{pickedRows.length > 0 && (
|
||
<Block tone="info" className="mt-3 w-full">
|
||
<b className="text-xs">已选 {pickedRows.length} 个{PANEL_LABEL[panel]}</b>
|
||
<Value>{pickedUsed ? `其中 ${pickedUsed} 个仍被镜头引用,删除时会自动跳过` : '都还没有被镜头引用'}</Value>
|
||
<Button icon={<IconCheck />} className="ml-auto" onClick={checkAllRows}>
|
||
{allPicked ? '取消全选' : `全选当前 ${pickRows.length} ${SELECT_UNIT[panel]}`}
|
||
</Button>
|
||
<Button icon={<IconLibrary />} disabled={!!busy} onClick={bulkPublish}>批量上架平台</Button>
|
||
<Button icon={<IconDelete />} type="text" danger disabled={!!busy} onClick={bulkDelete}>批量删除</Button>
|
||
<Button icon={<IconClose />} type="text" onClick={clearPicks}>取消选择</Button>
|
||
</Block>
|
||
)}
|
||
{/* 空态三分类(没数据 / 没匹配 / 引导下一步):三类母版各说各的出口,
|
||
项目素材面板没有「新建表单」,它的出口在下面的分支里。 */}
|
||
{panel !== 'project' && !panelRows.length && (
|
||
<Empty>
|
||
{filterActive ? (
|
||
<>当前筛选下没有{PANEL_LABEL[panel]}。
|
||
<Button icon={<IconClose />} type="link" onClick={resetFilters}>清除全部筛选</Button>
|
||
</>
|
||
) : (
|
||
<>还没有{PANEL_LABEL[panel]}。
|
||
<Button icon={<IconAdd />} type="link" onClick={() => setShowForm(true)}>新建{PANEL_LABEL[panel]}</Button>
|
||
{EMPTY_HINT[panel]}
|
||
</>
|
||
)}
|
||
</Empty>
|
||
)}
|
||
|
||
{/* ===== 三类母版:网格 / 列表(与平台资产库同一套卡片皮肤、同一套动作分区) ===== */}
|
||
{panel !== 'project' && !!panelRows.length && (view === 'list' ? (
|
||
/* 列表视图:一屏看更多,专为巡检与批量勾选设计。
|
||
皮肤交给 Tile(描边 / 圆角 / 底色 / 命中态都在 kit 里),分区交给会折行的 Flex:
|
||
窄屏时勾选框与素材条自己隐藏,不需要再改一套私有轨道。 */
|
||
<div className="flex flex-col gap-1.5 min-w-0">
|
||
{panelRows.map((row: any) => {
|
||
const kind = panel as GenType
|
||
const picked = picks.has(`${panel}:${row.id}`)
|
||
const use = usageFor(panel, row.id)
|
||
const assets = assetsOf(row)
|
||
return (
|
||
<Tile key={row.id} as="div" variant="pick" active={picked}
|
||
className="flex-wrap items-center gap-3 p-3"
|
||
title={picked ? '取消选择' : '勾选后可批量上架 / 删除(Shift 范围选择)'}>
|
||
<Checkbox checked={picked} className="cursor-pointer max-lg:hidden"
|
||
aria-label={`选择${PANEL_LABEL[panel]} ${row.name}`}
|
||
onClick={(e) => { e.stopPropagation(); togglePick(row, e) }} />
|
||
<div className="min-w-0">
|
||
<div className="flex items-center gap-1 flex-wrap">
|
||
<b className="text-xs">{row.name}</b>
|
||
<span className={MUTED_MONO}>{row.code || `#${row.id}`}</span>
|
||
{!!row.is_default && <Tag tone="accent">默认</Tag>}
|
||
{row.is_active === false && <Tag tone="bad">已停用</Tag>}
|
||
{!assets.length && <Tag tone="warn">待补素材</Tag>}
|
||
{!!use.count && <Tag title={`被 ${use.count} 个镜头引用,改设定会影响这些镜头`}>镜头 {use.count}</Tag>}
|
||
</div>
|
||
<p className="mt-1 mb-1 line-clamp-1 text-xs leading-normal text-text-tertiary">
|
||
{summaryOf(kind, row) || '尚未填写设定。'}
|
||
</p>
|
||
<TagGroup size="sm" className="mb-0 flex-nowrap overflow-hidden">
|
||
{(row.tags || []).slice(0, 4).map((tag: string) => (
|
||
<Chip key={tag} size="sm" title={`只看标签「${tag}」`}
|
||
onClick={() => setTagFilter(tag)}>{tag}</Chip>
|
||
))}
|
||
{metaTagsOf(kind, row)}
|
||
</TagGroup>
|
||
</div>
|
||
{/* 素材条:图片走灯箱队列,音频走单行紧凑播放条(列表里不撑行高) */}
|
||
<div className="flex items-center gap-1 shrink-0 max-lg:hidden">
|
||
{assets.slice(0, 4).map((asset: any, ai: number) => (
|
||
isAudioAsset(asset)
|
||
? <div key={asset.id} className="w-[160px] flex-none min-w-0">
|
||
<AudioPlay src={asset.url} size="sm" compact label={asset.name}
|
||
durationMs={asset.duration_ms} />
|
||
</div>
|
||
: <MediaThumb key={asset.id} src={asset.url} kind={asset.kind} size="xs" width="58px"
|
||
inlineAudio={false} queue={mediaQueue(row)} index={ai}
|
||
title={`${assetKindLabel(asset.kind)} · ${asset.name} · v${asset.version}`} />
|
||
))}
|
||
{!assets.length && <span className={cn(MUTED, 'text-xs')}>暂无素材</span>}
|
||
</div>
|
||
{/* 右侧动作列三段:编辑 / 删除(与网格卡角同档)→ AI 生成 → 自己动手那一组。
|
||
列宽与平台列表同一把尺子(图标 + 两个汉字要装得下)。
|
||
整列一律 sm(24 高),实底只有「编辑」一颗(§5.1.2.1 v2)。 */}
|
||
<div className="flex w-[176px] flex-none flex-col items-stretch gap-1.5">
|
||
<div className="flex gap-1.5 [&>*]:flex-1">
|
||
<Button size="sm" type="primary" icon={<IconEdit />} title={`编辑这个${PANEL_LABEL[panel]}`}
|
||
onClick={() => edit(kind, row)}>编辑</Button>
|
||
<Button size="sm" danger icon={<IconDelete />} title={`删除这个${PANEL_LABEL[panel]}`}
|
||
onClick={() => drop(PANEL_PATH[kind], row)}>删除</Button>
|
||
</div>
|
||
<Button size="sm" block disabled={!genKindProviders.length}
|
||
icon={<IconBolt />} onClick={() => openGen(kind, row)}
|
||
title={genKindProviders.length ? '打开生成台(模型 / 类型 / 参考图 / 提示词)' : GEN_DISABLED_HINT[kind]}>
|
||
{kind === 'voice' ? '生成试听' : 'AI 生成'}
|
||
</Button>
|
||
<div className="flex gap-1.5 border-t border-fill-secondary pt-1.5 [&>*]:flex-1">
|
||
<FilePick size="sm" icon={<IconUpload />} label="上传" accept={UPLOAD_ACCEPT[panel]}
|
||
title="选完即作为新版本登记到这个资产下"
|
||
onFiles={onUpload(assetPath(kind, row.id), uploadKindOf(row.id), row.name)} />
|
||
<Button size="sm" icon={<IconLibrary />} title="上架为平台母版"
|
||
onClick={() => publish(kind, row)}>上架</Button>
|
||
</div>
|
||
</div>
|
||
</Tile>
|
||
)
|
||
})}
|
||
</div>
|
||
) : (
|
||
/* 网格视图:卡片信息最全,一屏两张。
|
||
[&>.ant-col>*]:h-full 把同一行两张卡拉到同一高度——Col 会被 Row 拉伸,
|
||
差的是卡自己没有 height:100%。不拉平的话两张卡的标签行与素材条各排在不同高度。 */
|
||
<Grid cols={2} gap={10} oneAt="xl" className="[&>.ant-col>*]:h-full">
|
||
{panelRows.map((row: any) => {
|
||
const kind = panel as GenType
|
||
const picked = picks.has(`${panel}:${row.id}`)
|
||
const use = usageFor(panel, row.id)
|
||
const assets = assetsOf(row)
|
||
const gens = generatedBy(row)
|
||
return (
|
||
<Tile key={row.id} as="div" variant="pick" active={picked}
|
||
className="relative flex-col items-stretch gap-3 p-4">
|
||
<MediaPick title={picked ? '取消选择' : '勾选后可批量上架 / 删除(Shift 范围选择)'}>
|
||
{/* 名称必须自给:MediaPick 是外套的一层空 label,读屏走到这颗只念「复选框」 */}
|
||
<Checkbox checked={picked}
|
||
aria-label={`选择${PANEL_LABEL[panel]} ${row.name}`}
|
||
onClick={(e) => { e.stopPropagation(); togglePick(row, e) }} />
|
||
</MediaPick>
|
||
<div className="flex items-start gap-2.5 pl-[22px] min-w-0">
|
||
<div className="grow min-w-0">
|
||
<div className="flex items-center gap-1 flex-wrap">
|
||
<b className="truncate text-sm">{row.name}</b>
|
||
{!!row.is_default && <Tag tone="accent">默认</Tag>}
|
||
{row.is_active === false && <Tag tone="bad">已停用</Tag>}
|
||
{!assets.length && <Tag tone="warn">待补素材</Tag>}
|
||
</div>
|
||
<div className={MUTED_MONO}>{row.code || `#${row.id}`}</div>
|
||
</div>
|
||
{/* 编辑 / 删除在卡片右上角,卡片主按钮档(sm 24 / 圆角 6 / 图标 + 文字):
|
||
与平台资产库、模型管理卡同一把尺子(§5.1.2.1),卡底不再挂这两颗;
|
||
实底只有「编辑」,「删除」退 danger 描边(2026-11-11 用户「只是主按钮有底色」)。 */}
|
||
<div className="flex flex-none items-center gap-1.5">
|
||
<Button size="sm" type="primary" icon={<IconEdit />} title={`编辑这个${PANEL_LABEL[panel]}`}
|
||
onClick={() => edit(kind, row)}>编辑</Button>
|
||
<Button size="sm" danger icon={<IconDelete />} title={`删除这个${PANEL_LABEL[panel]}`}
|
||
onClick={() => drop(PANEL_PATH[kind], row)}>删除</Button>
|
||
</div>
|
||
</div>
|
||
|
||
<p className={SUMMARY}>{summaryOf(kind, row) || '尚未填写设定。'}</p>
|
||
|
||
<TagGroup size="sm" className="!mb-0">
|
||
{(row.tags || []).slice(0, 5).map((tag: string) => (
|
||
<Chip key={tag} size="sm" title={`只看标签「${tag}」`}
|
||
onClick={() => setTagFilter(tag)}>{tag}</Chip>
|
||
))}
|
||
{metaTagsOf(kind, row)}
|
||
{!!gens && (
|
||
<Tag title={`最近一次由 ${gens.provider}/${gens.model} 生成`}>{gens.provider}/{gens.model}</Tag>
|
||
)}
|
||
</TagGroup>
|
||
|
||
{/* 引用情况留在卡上:改设定前先看会不会影响成片,镜头锚点可跳分镜 */}
|
||
<UsageLine type={panel} id={row.id} usage={use} projectId={projectId} limit={3} />
|
||
|
||
{/* 素材区:图片排成缩略图格(点开除灯箱,右上叉删除),音频排成播放条 */}
|
||
{!!assets.filter(isImageAsset).length && (
|
||
<div className="grid grid-cols-4 gap-1 max-sm:grid-cols-2 min-w-0 [&>*]:min-w-0">
|
||
{assets.filter(isImageAsset).map((asset: any) => (
|
||
<MediaThumb key={asset.id} src={asset.url} kind={asset.kind} size="sm"
|
||
queue={mediaQueue(row)} index={assets.indexOf(asset)}
|
||
title={`${assetKindLabel(asset.kind)} · ${asset.name} · v${asset.version}`}
|
||
onRemove={() => void dropAsset(asset)} />
|
||
))}
|
||
</div>
|
||
)}
|
||
{assets.filter(isAudioAsset).map((asset: any) => (
|
||
<div key={`audio-${asset.id}`} className="flex items-center gap-1 min-w-0">
|
||
<div className="flex-1 min-w-0">
|
||
<AudioPlay src={asset.url} size="sm" label={asset.name} durationMs={asset.duration_ms}
|
||
hint={`v${asset.version}${asset.metadata?.model ? ` · ${asset.metadata.provider}/${asset.metadata.model}` : ''}`} />
|
||
</div>
|
||
<Tag size="sm" className="flex-none min-w-0 max-w-[36%] truncate"
|
||
title={assetKindLabel(asset.kind)}>{assetKindLabel(asset.kind)}</Tag>
|
||
<Button type="text" danger size="sm" title="单独删除此音频(含全部历史版本)"
|
||
aria-label="删除这条音频" onClick={() => void dropAsset(asset)} icon={<IconDelete />} />
|
||
</div>
|
||
))}
|
||
{!assets.length && (
|
||
<div className="flex min-h-[46px] items-center gap-2 rounded-md bg-fill-secondary px-3 py-2 text-xs leading-normal text-text-quaternary">
|
||
{kind === 'voice' ? <IconVoice className="flex-none" /> : <IconImage className="flex-none" />}
|
||
<span className="min-w-0">暂无素材:用下方「{kind === 'voice' ? '生成试听' : 'AI 生成'}」出图 / 出试听,或直接上传现成文件。</span>
|
||
</div>
|
||
)}
|
||
|
||
{/* 一条横轨两段:AI 生成 │ 类型 + 上传 + 录制 + 上架。
|
||
分界线左边是「让模型跑一张」(走排队任务,回来的时间不由这张卡决定),
|
||
右边三个都是「我自己动手」,所以并成一轨不拆开。
|
||
AI 生成不涂底色、与右轨同为 sm:这张卡的重点色只给右上角那颗「编辑」。 */}
|
||
<div className="mt-auto flex flex-wrap items-center gap-x-3 gap-y-2 border-t border-fill-secondary pt-3">
|
||
<Button size="sm" className="flex-none" disabled={!genKindProviders.length}
|
||
icon={<IconBolt />} onClick={() => openGen(kind, row)}
|
||
title={genKindProviders.length ? '打开生成台(模型 / 类型 / 参考图 / 提示词)' : GEN_DISABLED_HINT[kind]}>
|
||
{kind === 'voice' ? '生成试听' : 'AI 生成'}
|
||
</Button>
|
||
<CardActions className="!mt-0 flex-1 border-s border-fill-secondary ps-3 max-lg:border-s-0 max-lg:ps-0">
|
||
<ActionGroup>
|
||
<Select className="w-[105px]" ariaLabel="选择要上传的素材类型" value={uploadKindOf(row.id)}
|
||
onChange={(next) => setUploadKinds((prev) => ({ ...prev, [`${panel}:${row.id}`]: String(next) }))}
|
||
options={UPLOAD_KINDS[panel].map((assetKind) => ({ value: assetKind, label: assetKindLabel(assetKind) }))} />
|
||
<FilePick icon={<IconUpload />} label="上传" accept={UPLOAD_ACCEPT[panel]}
|
||
title="按左侧类型登记为新版本;同名素材会追加版本,不会新建一条"
|
||
onFiles={onUpload(assetPath(kind, row.id), uploadKindOf(row.id), row.name)} />
|
||
{kind === 'voice' && (
|
||
<RecordAudio label="录制" target={assetKindLabel(uploadKindOf(row.id))}
|
||
defaultName={defaultAssetName(row.assets, row.name, uploadKindOf(row.id))}
|
||
names={existingNames(row.assets)}
|
||
hint="弹出小面板:录 → 试听 → 再决定存成哪条素材的哪个版本"
|
||
onPick={(file, meta) => void onRecord(assetPath('voice', row.id), uploadKindOf(row.id), row.name, file, meta)} />
|
||
)}
|
||
<Button icon={<IconLibrary />} title="上架为平台母版"
|
||
onClick={() => publish(kind, row)}>上架平台</Button>
|
||
</ActionGroup>
|
||
</CardActions>
|
||
</div>
|
||
</Tile>
|
||
)
|
||
})}
|
||
</Grid>
|
||
))}
|
||
|
||
{/* ===== 项目素材:配乐 / 音效 / 通用参考(素材墙 / 列表,与平台「全部素材」同一族) ===== */}
|
||
{panel === 'project' && (
|
||
<>
|
||
<CardActions className="mt-0 mb-3">
|
||
<ActionGroup>
|
||
{PROJECT_ASSET_KINDS.map((assetKind) => (
|
||
<FilePick key={assetKind} icon={<IconUpload />} label={`上传${assetKindLabel(assetKind)}`}
|
||
title={`上传后立即出现在下方素材里;配乐可在「时间线合成」页直接挂到音轨`}
|
||
onFiles={onUpload(`/api/projects/${projectId}/assets`, assetKind, assetKindLabel(assetKind))} />
|
||
))}
|
||
</ActionGroup>
|
||
</CardActions>
|
||
{!panelRows.length ? (
|
||
<Empty>
|
||
{filterActive
|
||
? <>当前筛选下没有素材。
|
||
<Button icon={<IconClose />} type="link" onClick={resetFilters}>清除全部筛选</Button>
|
||
</>
|
||
: <>还没有项目级素材。用上方「上传配乐 / 音效 / 通用参考」放入文件,配乐可在「时间线合成」页直接挂到音轨。</>}
|
||
</Empty>
|
||
) : view === 'list' ? (
|
||
<div className="flex flex-col gap-1.5 min-w-0">
|
||
{panelRows.map((row: any, idx: number) => (
|
||
<Tile key={row.id} as="div" className="flex-wrap items-center gap-3 p-3">
|
||
<div className="min-w-0">
|
||
<div className="flex items-center gap-1 flex-wrap">
|
||
<b className="text-xs">{row.name}</b>
|
||
<Tag>{assetKindLabel(row.kind)}</Tag>
|
||
<span className={MUTED_MONO}>v{row.version}</span>
|
||
</div>
|
||
<div className={cn(MUTED_MONO, 'line-clamp-1 text-xs')}>{row.path}</div>
|
||
<TagGroup size="sm" className="mb-0 flex-nowrap overflow-hidden">
|
||
<Tag size="sm">{fmtBytes(row.size_bytes)}</Tag>
|
||
<Tag size="sm">{fmtTime(row.created_at || row.versions?.[0]?.created_at)}</Tag>
|
||
</TagGroup>
|
||
</div>
|
||
<div className="flex items-center gap-1 shrink-0 max-lg:hidden min-w-0">
|
||
{isAudioAsset(row)
|
||
? <div className="w-[200px] flex-none min-w-0">
|
||
<AudioPlay src={row.url} size="sm" compact label={row.name} durationMs={row.duration_ms} />
|
||
</div>
|
||
: isImageAsset(row) || isVideoAsset(row)
|
||
? <MediaThumb src={row.url} kind={row.kind} size="xs" width="58px" inlineAudio={false}
|
||
queue={projectMediaQueue} index={idx} title={row.name} />
|
||
: <ExtLink href={row.url}>打开</ExtLink>}
|
||
</div>
|
||
{/* 素材行这一对同样收 sm:卡片动作一律 24 高,
|
||
实底只留给「删除」这颗(它是这一行的主按钮)。 */}
|
||
<div className="flex w-[176px] flex-none gap-1.5 [&>*]:flex-1">
|
||
<Button size="sm" icon={<IconSync />} title="提交一次资产校验任务,进度见顶栏「平台动态」"
|
||
onClick={() => void refreshAsset(row)}>校验</Button>
|
||
<Button size="sm" type="primary" danger icon={<IconDelete />} title="删除这个素材"
|
||
aria-label={`删除素材 ${row.name}`} onClick={() => void dropAsset(row)}>删除</Button>
|
||
</div>
|
||
</Tile>
|
||
))}
|
||
</div>
|
||
) : (
|
||
/* 素材墙按**容器**宽度铺满缩略图:auto-fill + minmax 是这一族该有的行为
|
||
(antd 的 Row/Col 断点看视口,抽屉与两栏里会算错列数)。 */
|
||
<div className="grid gap-2 grid-cols-[repeat(auto-fill,minmax(148px,1fr))] min-w-0 [&>*]:min-w-0">
|
||
{panelRows.map((row: any, idx: number) => (
|
||
<Tile key={row.id} as="div" className="relative flex-col items-stretch gap-1 p-2">
|
||
{isAudioAsset(row)
|
||
? <AudioPlay src={row.url} size="sm" compact label={row.name} durationMs={row.duration_ms} />
|
||
: isImageAsset(row) || isVideoAsset(row)
|
||
? <MediaThumb src={row.url} kind={row.kind} size="sm" inlineAudio={false}
|
||
queue={projectMediaQueue} index={idx}
|
||
title={`${row.name} · ${assetKindLabel(row.kind)}`} />
|
||
: <ExtLink href={row.url}>打开文件</ExtLink>}
|
||
<div className="min-w-0">
|
||
<b className="block truncate text-text-secondary text-xs" title={row.name}>{row.name}</b>
|
||
<small className="block text-text-quaternary text-xs leading-normal wrap-anywhere">
|
||
{assetKindLabel(row.kind)} · {fmtTime(row.created_at || row.versions?.[0]?.created_at)}
|
||
</small>
|
||
<small className={cn(MUTED_MONO, 'block text-xs')}>{fmtBytes(row.size_bytes)} · v{row.version}</small>
|
||
</div>
|
||
<div className="mt-auto flex items-center gap-1 pt-1">
|
||
<Button size="sm" icon={<IconSync />} title="提交一次资产校验任务,进度见顶栏「平台动态」"
|
||
onClick={() => void refreshAsset(row)}>校验</Button>
|
||
<Button type="text" danger size="sm" title="删除这个素材"
|
||
aria-label={`删除素材 ${row.name}`} onClick={() => void dropAsset(row)} icon={<IconDelete />} />
|
||
</div>
|
||
</Tile>
|
||
))}
|
||
</div>
|
||
)}
|
||
{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 icon={<IconClose />} className="mr-auto" onClick={() => { setChar({ ...EMPTY_CHAR }); setEditing({ kind: '', id: null }) }}>清空</Button>
|
||
<Button icon={<IconClose />} onClick={closeForm}>取消</Button>
|
||
<Button icon={<IconCheck />} 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="外观描述" title="同时进入定妆图与镜头提示词,是角色长相的主要来源。">
|
||
<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="一致性提示词" title="只用于生成定妆图与关键帧,不进镜头提示词。">
|
||
<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="标签" title="多个标签用逗号分隔"><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 icon={<IconClose />} className="mr-auto" onClick={() => { setScene({ ...EMPTY_SCENE }); setEditing({ kind: '', id: null }) }}>清空</Button>
|
||
<Button icon={<IconClose />} onClick={closeForm}>取消</Button>
|
||
<Button icon={<IconCheck />} 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="标签" title="多个标签用逗号分隔">
|
||
<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 icon={<IconClose />} className="mr-auto" onClick={clearVoiceForm}>清空</Button>
|
||
<Button icon={<IconClose />} onClick={closeForm}>取消</Button>
|
||
<Button icon={<IconCheck />} 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>
|
||
<Field label="供应商音色 ID"
|
||
hint="克隆模型可留空:音色由参考音频决定;没录过音就填下方「音色描述」,IndexTTS2 会按描述词直出">
|
||
<Input value={voice.provider_voice_id} placeholder="云端音色库填音色 ID;IndexTTS2 留空" 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>
|
||
</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>
|
||
</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 icon={<IconClose />} 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}
|
||
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 icon=<IconVoice /> label="上传参考音色" accept="audio/*" className="flex-none border-primary-border text-primary"
|
||
title="上传一段真人录音做克隆参考,选完自动勾上。参考音频与声线的「音色描述」至少要有一个,否则平台直接拦下生成。"
|
||
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)} />
|
||
{voiceRefStatus && (
|
||
<RefStatus ready={!!voiceRefStatus.ready} borrowed={!!voiceRefStatus.borrowed}
|
||
instruct={!!voiceRefStatus.instruct} 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="生成描述" title={`留空时自动使用${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}
|
||
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 icon=<IconImage /> 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…),
|
||
* 改动请连同注释里的旧类名一起改,否则下次对不上号。
|
||
* ========================================================================== */
|
||
|
||
/**
|
||
* 引用情况一行(.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 (
|
||
// 间距只由 Tile 的 gap 给:上一版在这里补了 mt-2,还写了压不住 .nex-taggroup
|
||
// 自带 margin-block-end 的 mb-0(app.css 第 17 轮那条反向证据),于是这张卡的
|
||
// 纵向节奏成了 12/12/20/24 四档——rhythmcheck 只认「同一容器只有一档」。
|
||
<TagGroup size="sm" className="!mb-0">
|
||
<Tag>被 {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>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 全选框(规则①:一行都不多占)——它只是「本面板 N 条全选」的一颗 Checkbox,
|
||
* 原先那条虚线框是自己画的壳,现在整颗挪进卡头 right,和标题共用一行。
|
||
*/
|
||
function SelectAll({ checked, onChange, label }: {
|
||
checked: boolean; onChange: () => void; label: ReactNode
|
||
}) {
|
||
return (
|
||
<Check checked={checked} onChange={onChange}
|
||
title="勾选后可批量上架 / 删除;按住 Shift 连选">{label}</Check>
|
||
)
|
||
}
|
||
|
||
/** 参考素材行(.generation-reference):抽屉里唯一一处「选择 + 上传 + 录制」并排 */
|
||
function GenerationReference({ children }: { children: ReactNode }) {
|
||
return (
|
||
<Block>
|
||
<Ctlbar className="!mb-0 w-full">{children}</Ctlbar>
|
||
</Block>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 音色预告(.ref-status)。
|
||
*
|
||
* 三种音色来源必须分得开:借了别人的嗓子(warning)、走描述词直出(正常但标明来源)、
|
||
* 用自己的参考音频克隆(正常)。两者都没有时后端会按性别「借」一条嗓子,
|
||
* 必须把这次用的是谁的嗓子写在生成按钮够得着的地方,而不是等失败才知道。
|
||
*/
|
||
function RefStatus({ ready, borrowed, instruct, note }: {
|
||
ready: boolean; borrowed: boolean; instruct?: boolean; note?: string
|
||
}) {
|
||
return (
|
||
<Notice className="!mb-0 w-full" type={!ready ? 'error' : borrowed ? 'warning' : 'success'}
|
||
description={<span className="min-w-0">{note}</span>}>
|
||
{!ready ? '现在还不能生成' : instruct ? '本次音色 · 描述词直出' : '本次音色'}
|
||
</Notice>
|
||
)
|
||
}
|
||
|
||
/** 模型未就绪 / 完全没模型的提醒(.provider-warning):说清楚是「还能选」还是「点不动」 */
|
||
function ProviderWarning({ children }: { children: ReactNode }) {
|
||
return (
|
||
<Notice className="mt-2 w-full !mb-0" type="warning">{children}</Notice>
|
||
)
|
||
}
|
||
|
||
/** AI 补全结果的预览框(.suggestion-box):先预览再采用,避免一句话直接盖掉已写好的提示词 */
|
||
function SuggestionBox({ text, busy, onApply, onDismiss }: {
|
||
text: string; busy: boolean; onApply: () => void; onDismiss: () => void
|
||
}) {
|
||
return (
|
||
<Block tone="info" align="start" className="w-full">
|
||
<p className="m-0 w-full text-xs leading-relaxed text-text-secondary">{text}</p>
|
||
<CardActions>
|
||
<Button icon={<IconCheck />} type="primary" disabled={busy} onClick={onApply}>采用为一致性提示词</Button>
|
||
<Button icon={<IconClose />} onClick={onDismiss}>放弃</Button>
|
||
</CardActions>
|
||
</Block>
|
||
)
|
||
}
|