Files
monkey-ai-web/src/pages/ExperienceCenter/components/AICreation/Video/VideoInputPanel.jsx
T
qiubaishen e3b82b981a merge: 合入总仓库 weiyuan(bfdfb339) web/ 新功能,保留 ui-optimization 的 UI 重构
来源:luoguang/monkey-ai weiyuan@bfdfb339 的 web/(经 sync/main-weiyuan-web-bfdfb339 同步)
同步基准:总仓库 a2ca13cb = 本仓库初始导入 d8f3aee2

冲突处理原则:保留 ui-optimization 的 UI(样式/结构/组件),嫁接 weiyuan 的功能逻辑。
- i18n:按键三方合并;ours 的「令牌→密钥」改名键上移植 theirs 的术语修订
- task-logs / OrgLogs:ours 已手工移植同一功能(6ad95e2),保留 ours
- 删除:OrgCreate(theirs 下线 /org/create)、旧 image 组件与 VideoRegenerateModal(theirs 体验中心重写)、
  OrgAvatarSection / PricingBentoPage / CommissionConsole(ours 重构中已移除)
- 测试:users-pagination 的 i18next mock 补 t();theirs 新增文件补 license header
2026-11-10 12:01:21 +08:00

447 lines
14 KiB
React

/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import {
Button,
Collapse,
Select,
Skeleton,
Tag,
TextArea,
Tooltip,
Typography,
} from '@/components/ui';
import {
ChevronLeft,
ChevronRight,
Film,
Image as ImageIcon,
Images,
Layers,
Lock,
Settings2,
SlidersHorizontal,
Sparkles,
Video,
Wand2,
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { PROMPT_TEMPLATES } from '../../../../../constants/video-generation.constant';
import {
ImageSlot,
OptionGroup,
ParamRenderer,
} from '../../../../../components/creation/params';
import { formatQuoteAmount } from '../../../../../hooks/creation/useCreationQuote';
import { MODE_LABEL_KEYS } from '../../../../../hooks/video/videoCreation';
import PortraitAssetPicker from './PortraitAssetPicker';
import './VideoInputPanel.css';
const { Text } = Typography;
const MODE_ICONS = {
text2video: Film,
image2video: ImageIcon,
first_last_frame: Layers,
reference2video: Images,
};
const PRICE_UNIT_KEYS = { second: '/秒', task: '/次' };
const Section = ({ icon: Icon, title, extra, children }) => (
<section className='vip-card'>
<div className='vip-card-head'>
<span className='vip-card-icon' aria-hidden='true'>
<Icon size={14} />
</span>
<span>{title}</span>
{extra ? <span className='vip-card-extra'>{extra}</span> : null}
</div>
{children}
</section>
);
/** schema 单价(按当前分辨率档位):"¥0.05/秒"。 */
const formatModelPrice = (t, model, resolution) => {
const pricing = model?.pricing;
if (!pricing) return '';
const tier =
resolution && pricing.prices && pricing.prices[resolution] !== undefined
? pricing.prices[resolution]
: pricing.price;
if (tier === undefined || tier === null) return '';
const amount = formatQuoteAmount(tier, pricing.currency);
if (!amount) return '';
const unit = PRICE_UNIT_KEYS[pricing.unit];
return unit ? `${amount}${t(unit)}` : amount;
};
const VideoInputPanel = ({
creation,
onCollapse,
collapsed,
collapsible = true,
}) => {
const { t } = useTranslation();
const {
formData,
setFormData,
setMode,
updateParam,
models,
modelsLoading,
modelsError,
reloadModels,
selectedModel,
setSelectedModel,
modeOptions,
visibleParams,
imageSlots,
pickImage,
removeImage,
retryImage,
selectPortraitAsset,
clearPortraitAsset,
cosEnabled,
} = creation;
const updateField = (field, value) => {
setFormData((prev) => ({ ...prev, [field]: value }));
};
// 单列(手机)布局不提供折叠:没有相邻面板可以让位,收起只会留下一片空白,
// 而唯一的恢复入口是一个浮在屏幕左侧垂直中央的裸箭头。
if (collapsed && collapsible) {
return (
<div className='vip-expand-fab'>
<Button
icon={<ChevronRight size={20} />}
onClick={onCollapse}
aria-label={t('展开')}
/>
</div>
);
}
const advancedParams = visibleParams.filter(
(p) => p.placement === 'advanced',
);
const dockParams = visibleParams.filter(
(p) => (p.placement || 'dock') === 'dock',
);
const constraints = selectedModel?.constraints || [];
const firstFrameSlot = imageSlots.find(
(s) => s.key === 'first_frame' && s.active,
);
const firstFrameRef = String(formData.images?.first_frame?.ref || '');
const hasUnusedImage = imageSlots.some((s) => s.slot && !s.active);
const price = formatModelPrice(t, selectedModel, formData.params?.resolution);
const estSeconds = selectedModel?.est_seconds?.p50;
const renderModelSection = () => {
if (modelsLoading) {
return (
<Skeleton
active
placeholder={<Skeleton.Paragraph rows={2} />}
loading
/>
);
}
if (modelsError) {
return (
<div className='vip-state is-error' role='alert'>
<span className='vip-state-title'>{t('模型列表加载失败')}</span>
<Button size='small' onClick={() => reloadModels()}>
{t('重试')}
</Button>
</div>
);
}
if (models.length === 0) {
return (
<div className='vip-state'>
<span className='vip-state-title'>{t('暂无可用的视频模型')}</span>
<span className='vip-muted'>
{t('当前分组下没有可用的视频模型,请联系管理员开通')}
</span>
</div>
);
}
const allLocked = models.every((m) => m.level_locked);
return (
<>
<Select
value={selectedModel?.model}
onChange={(value) => setSelectedModel(value)}
placeholder={t('请选择模型')}
style={{ width: '100%' }}
filter
aria-label={t('选择模型')}
>
{models.map((m) => (
<Select.Option
key={m.model}
value={m.model}
label={m.display_name || m.model}
disabled={m.level_locked}
showTick={!m.level_locked}
>
<div className='vip-model-option'>
<Text
strong
type={m.level_locked ? 'tertiary' : undefined}
className='vip-model-name'
>
{m.display_name || m.model}
</Text>
{m.display_name && m.display_name !== m.model ? (
<span className='vip-model-id'>{m.model}</span>
) : null}
{m.level_locked ? (
<Tooltip
content={t('当前等级无权调用此模型,升级等级后可用')}
>
<Tag
size='small'
color='grey'
prefixIcon={<Lock size={12} />}
>
{t('仅可见')}
</Tag>
</Tooltip>
) : null}
</div>
</Select.Option>
))}
</Select>
{allLocked ? (
<div className='vip-muted vip-slot-note' role='note'>
{t('当前等级无权调用视频模型,升级等级后可用')}
</div>
) : null}
{selectedModel && (price || estSeconds || selectedModel.description) ? (
<div className='vip-model-meta'>
{price ? (
<span>
{t('单价')} <strong>{price}</strong>
</span>
) : null}
{estSeconds ? (
<span>
{t('预计耗时')}{' '}
<strong>{t('约 {{n}} 秒', { n: estSeconds })}</strong>
</span>
) : null}
{selectedModel.description ? (
<span className='vip-model-desc'>
{selectedModel.description}
</span>
) : null}
</div>
) : null}
</>
);
};
const slotLabel = (entry) =>
entry.labelIndex ? `${t(entry.label)} ${entry.labelIndex}` : t(entry.label);
return (
<div className='video-input-panel'>
{collapsible && (
<div className='vip-collapse-row'>
<Button
icon={<ChevronLeft size={18} />}
onClick={onCollapse}
size='small'
type='tertiary'
className='vip-collapse-btn'
aria-label={t('收起')}
/>
</div>
)}
<Section icon={Wand2} title={t('选择模型')}>
{renderModelSection()}
</Section>
{selectedModel && modeOptions.length > 0 ? (
<Section icon={Layers} title={t('生成方式')}>
<OptionGroup
options={modeOptions.map((o) => o.mode)}
value={formData.mode}
onChange={setMode}
ariaLabel={t('生成方式')}
optionDisabledReasons={Object.fromEntries(
modeOptions
.filter((o) => o.disabled)
.map((o) => [o.mode, t(o.reason || '当前不可用')]),
)}
renderOption={(mode) => {
const Icon = MODE_ICONS[mode] || Film;
return (
<span className='vip-mode-option'>
<Icon size={14} aria-hidden='true' />
{t(MODE_LABEL_KEYS[mode] || mode)}
</span>
);
}}
/>
</Section>
) : null}
{selectedModel && imageSlots.length > 0 ? (
<Section icon={ImageIcon} title={t('参考图片')}>
<div className='vip-slots'>
{imageSlots.map((entry) => {
const slot = entry.slot;
const value = slot
? {
previewUrl: slot.previewUrl,
status: entry.active ? slot.status || 'ready' : 'unused',
error: slot.error,
}
: null;
return (
<ImageSlot
key={`${entry.key}-${entry.index ?? 0}-${slot?.id || 'empty'}`}
label={slotLabel(entry)}
value={value}
onPick={(file) => pickImage(entry.key, entry.index, file)}
onRemove={() => removeImage(entry.key, entry.index)}
onRetry={() => retryImage(entry.key, entry.index, slot)}
disabledReason={
!cosEnabled && !slot
? t('对象存储(COS)未开启,暂不支持上传图片')
: ''
}
/>
);
})}
</div>
{hasUnusedImage ? (
<div className='vip-muted vip-slot-note' role='note'>
{t('置灰的图片当前不会提交,切回支持的模型或模式后自动恢复')}
</div>
) : null}
{firstFrameSlot ? (
<div className='vip-portrait-row'>
<PortraitAssetPicker
onSelect={selectPortraitAsset}
selectedAssetId={
firstFrameRef.startsWith('asset://')
? firstFrameRef.slice('asset://'.length)
: ''
}
onClearSelection={clearPortraitAsset}
/>
{formData.images?.first_frame?.identityType === 'real_person' ? (
<Tag color='green' size='small'>
{t('真人人像')}
</Tag>
) : null}
</div>
) : null}
</Section>
) : null}
<Section icon={Sparkles} title={t('场景模板')}>
<Select
placeholder={t('选择场景模板(可选)')}
value={formData.selectedTemplate}
onChange={(value) => updateField('selectedTemplate', value)}
style={{ width: '100%' }}
showClear
>
{PROMPT_TEMPLATES.map((template, index) => (
<Select.Option key={index} value={template.prompt}>
{t(template.label)}
</Select.Option>
))}
</Select>
{formData.selectedTemplate && (
<div className='vip-template-preview'>
<Text type='tertiary' size='small'>
{t('模板内容')}: {formData.selectedTemplate}
</Text>
</div>
)}
</Section>
<Section icon={Video} title={t('提示词')}>
<TextArea
placeholder={t(
'描述你想要生成的视频内容,例如:一只可爱的猫咪在草地上玩耍',
)}
value={formData.prompt}
onChange={(value) => updateField('prompt', value)}
autosize={{ minRows: 4, maxRows: 8 }}
maxLength={2000}
showClear
/>
<Text type='tertiary' size='small' className='vip-counter'>
{formData.prompt?.length || 0} / 2000
</Text>
</Section>
{selectedModel && dockParams.length > 0 ? (
<Section icon={SlidersHorizontal} title={t('生成参数')}>
<ParamRenderer
params={visibleParams}
values={formData.params}
onChange={updateParam}
placement='dock'
constraints={constraints}
/>
</Section>
) : null}
{selectedModel && advancedParams.length > 0 ? (
<div className='vip-advanced'>
<Collapse defaultActiveKey={[]}>
<Collapse.Panel
itemKey='advanced'
header={
<div className='vip-card-head' style={{ margin: 0 }}>
<span className='vip-card-icon' aria-hidden='true'>
<Settings2 size={14} />
</span>
<span>{t('高级参数')}</span>
</div>
}
>
<ParamRenderer
params={visibleParams}
values={formData.params}
onChange={updateParam}
placement='advanced'
constraints={constraints}
/>
</Collapse.Panel>
</Collapse>
</div>
) : null}
</div>
);
};
export default VideoInputPanel;