Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
@@ -0,0 +1,389 @@
/*
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, { useEffect, useMemo, useState } from 'react';
import {
Button,
Checkbox,
Empty,
Input,
Modal,
Progress,
Radio,
Spin,
Tag,
Tooltip,
Upload,
} from '@douyinfe/semi-ui';
import {
Check,
ExternalLink,
Image as ImageIcon,
Plus,
ShieldCheck,
Trash2,
UserRound,
} from 'lucide-react';
import { QRCodeSVG } from 'qrcode.react';
import { useTranslation } from 'react-i18next';
import { showError, showSuccess } from '../../../../../helpers';
import { usePortraitAssets } from '../../../../../hooks/video/usePortraitAssets';
const statusColor = {
active: 'green',
draft: 'grey',
processing: 'blue',
failed: 'red',
};
const PortraitAssetPicker = ({
onSelect,
selectedAssetId,
onClearSelection,
}) => {
const { t } = useTranslation();
const [visible, setVisible] = useState(false);
const [name, setName] = useState('');
const [consent, setConsent] = useState(false);
const [selectedPortraitId, setSelectedPortraitId] = useState('');
const [busy, setBusy] = useState(false);
const [secondsLeft, setSecondsLeft] = useState(0);
const portrait = usePortraitAssets(visible);
const selectedPortrait = useMemo(
() =>
portrait.portraits.find((item) => item.id === selectedPortraitId) || null,
[portrait.portraits, selectedPortraitId],
);
useEffect(() => {
if (!selectedPortraitId && portrait.portraits.length > 0) {
setSelectedPortraitId(portrait.portraits[0].id);
}
}, [portrait.portraits, selectedPortraitId]);
useEffect(() => {
if (!portrait.session?.expires_at) {
setSecondsLeft(0);
return undefined;
}
const tick = () => {
setSecondsLeft(
Math.max(
0,
portrait.session.expires_at - Math.floor(Date.now() / 1000),
),
);
};
tick();
const timer = setInterval(tick, 1000);
return () => clearInterval(timer);
}, [portrait.session?.expires_at]);
const handleCreate = async () => {
if (!name.trim() || !consent) return;
setBusy(true);
try {
const created = await portrait.createPortrait(name.trim());
setSelectedPortraitId(created.id);
setName('');
setConsent(false);
} catch (error) {
showError(portrait.errorMessage(error));
} finally {
setBusy(false);
}
};
const handleVerify = async () => {
if (!selectedPortraitId) return;
setBusy(true);
try {
await portrait.startVerification(selectedPortraitId);
} catch (error) {
showError(portrait.errorMessage(error));
} finally {
setBusy(false);
}
};
const handleUpload = async ({ fileList }) => {
const file = fileList?.[fileList.length - 1]?.fileInstance;
if (!file || !selectedPortraitId) return;
setBusy(true);
try {
const asset = await portrait.uploadPortraitAsset(
selectedPortraitId,
file,
);
showSuccess(t('素材已提交审核'));
portrait.refreshAssetUntilTerminal(asset.id).catch(() => {});
} catch (error) {
showError(portrait.errorMessage(error));
} finally {
setBusy(false);
}
};
const assets = portrait.assets.filter(
(asset) => asset.portrait_id === selectedPortraitId,
);
const confirmDeleteAsset = (asset) => {
Modal.confirm({
title: t('删除素材'),
content: t('删除后将无法继续用于视频生成。'),
okType: 'danger',
onOk: async () => {
try {
await portrait.deleteAsset(asset.id);
if (asset.id === selectedAssetId) onClearSelection?.();
} catch (error) {
showError(portrait.errorMessage(error));
throw error;
}
},
});
};
const confirmDeletePortrait = (item) => {
Modal.confirm({
title: t('删除人像'),
content: t('该人像及其全部关联素材将被删除。'),
okType: 'danger',
onOk: async () => {
try {
const clearsSelection = portrait.assets.some(
(asset) =>
asset.id === selectedAssetId && asset.portrait_id === item.id,
);
await portrait.deletePortrait(item.id);
if (clearsSelection) onClearSelection?.();
if (selectedPortraitId === item.id) setSelectedPortraitId('');
showSuccess(t('人像已删除'));
} catch (error) {
showError(portrait.errorMessage(error));
throw error;
}
},
});
};
return (
<>
<Button
icon={<UserRound size={16} />}
theme='light'
onClick={() => setVisible(true)}
>
{t('真人人像素材')}
</Button>
<Modal
title={t('真人人像素材')}
visible={visible}
onCancel={() => setVisible(false)}
footer={null}
width={720}
bodyStyle={{ maxHeight: '72vh', overflow: 'auto' }}
>
{portrait.loading ? (
<div className='flex justify-center py-12'>
<Spin />
</div>
) : portrait.enabled === false ? (
<Empty title={t('真人人像素材未启用')} />
) : (
<div className='flex flex-col gap-5'>
<div className='flex flex-col gap-3 border-b border-solid border-semi-color-border pb-5'>
<div className='flex gap-2'>
<Input
value={name}
onChange={setName}
maxLength={128}
placeholder={t('人像名称')}
/>
<Tooltip content={t('创建人像')}>
<Button
icon={<Plus size={16} />}
onClick={handleCreate}
loading={busy}
disabled={!name.trim() || !consent}
/>
</Tooltip>
</div>
<Checkbox
checked={consent}
onChange={(event) => setConsent(event.target.checked)}
>
{t('我已获得本人授权并拥有该人像素材的合法使用权')}
</Checkbox>
</div>
{portrait.portraits.length > 0 && (
<Radio.Group
value={selectedPortraitId}
onChange={(event) => {
setSelectedPortraitId(event.target.value);
portrait.setSession(null);
}}
direction='vertical'
className='w-full'
>
{portrait.portraits.map((item) => (
<div key={item.id} className='flex items-center gap-2'>
<Radio value={item.id} className='min-w-0 flex-1'>
<span className='inline-flex min-w-0 items-center gap-2 py-1'>
<span className='truncate'>{item.name}</span>
<Tag
color={statusColor[item.status] || 'grey'}
size='small'
>
{item.status}
</Tag>
<span className='text-xs text-semi-color-text-2'>
{item.id.slice(-6)}
</span>
</span>
</Radio>
<Tooltip content={t('删除人像')}>
<Button
type='danger'
theme='borderless'
icon={<Trash2 size={16} />}
onClick={() => confirmDeletePortrait(item)}
/>
</Tooltip>
</div>
))}
</Radio.Group>
)}
{selectedPortrait &&
selectedPortrait.status !== 'active' &&
!portrait.session && (
<Button
icon={<ShieldCheck size={16} />}
onClick={handleVerify}
loading={busy}
>
{t('开始活体认证')}
</Button>
)}
{portrait.session &&
['pending', 'confirming'].includes(portrait.session.status) && (
<div className='flex flex-col items-center gap-3 border-y border-solid border-semi-color-border py-5'>
<QRCodeSVG value={portrait.session.h5_url} size={184} />
<Progress
percent={Math.round((secondsLeft / 120) * 100)}
showInfo
format={() => `${secondsLeft}s`}
style={{ width: 240 }}
/>
<Button
icon={<ExternalLink size={16} />}
onClick={() =>
window.open(
portrait.session.h5_url,
'_blank',
'noopener,noreferrer',
)
}
>
{t('打开认证页面')}
</Button>
</div>
)}
{portrait.session?.status === 'succeeded' && (
<Tag color='green' prefixIcon={<Check size={14} />}>
{t('认证通过')}
</Tag>
)}
{selectedPortrait?.status === 'active' && (
<Upload
accept='image/*'
limit={1}
uploadTrigger='custom'
showUploadList={false}
onChange={handleUpload}
>
<Button icon={<ImageIcon size={16} />} loading={busy}>
{t('上传真人素材')}
</Button>
</Upload>
)}
<div className='flex flex-col divide-y divide-semi-color-border'>
{assets.map((asset) => (
<div
key={asset.id}
className='flex min-h-[64px] items-center gap-3 py-3'
>
<div className='h-12 w-12 shrink-0 overflow-hidden rounded-[6px] bg-semi-color-fill-0'>
{asset.preview_url && (
<img
src={asset.preview_url}
alt={asset.name}
className='h-full w-full object-cover'
/>
)}
</div>
<div className='min-w-0 flex-1'>
<div className='truncate text-sm font-medium'>
{asset.name}
</div>
<Tag
color={statusColor[asset.status] || 'grey'}
size='small'
>
{asset.status}
</Tag>
</div>
{asset.status === 'active' && (
<Tooltip content={t('选择素材')}>
<Button
icon={<Check size={16} />}
onClick={() => {
onSelect(asset);
setVisible(false);
}}
/>
</Tooltip>
)}
<Tooltip content={t('删除素材')}>
<Button
type='danger'
theme='borderless'
icon={<Trash2 size={16} />}
onClick={() => confirmDeleteAsset(asset)}
/>
</Tooltip>
</div>
))}
</div>
</div>
)}
</Modal>
</>
);
};
export default PortraitAssetPicker;
@@ -0,0 +1,944 @@
/*
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 {
Card,
TextArea,
Upload,
Collapse,
Select,
InputNumber,
Switch,
Button,
Tag,
Typography,
Tooltip,
} from '@douyinfe/semi-ui';
import {
ChevronLeft,
ChevronRight,
Image as ImageIcon,
Video,
Info,
CreditCard,
X,
Film,
Wand2,
Layers,
Settings2,
Clock,
Maximize,
Mic,
Sparkles,
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { PROMPT_TEMPLATES } from '../../../../../constants/video-generation.constant';
import ModelSelector from '../../../../../components/common/ModelSelector';
import { MODEL_CATEGORY } from '../../../../../constants';
import { convertUSDToCurrency } from '../../../../../helpers';
import PortraitAssetPicker from './PortraitAssetPicker';
const { Text } = Typography;
// 判断是否是阿里云模型(支持高级参数)
const isAlibabaModel = (model) => {
if (!model) return false;
// 检查 vendor 字段
const vendor =
typeof model === 'object' ? model.vendor || model.provider || '' : '';
// 检查模型名称
const modelName =
typeof model === 'object' ? model.model_name || model.id || '' : model;
// 阿里云厂商名称匹配
const aliVendors = ['阿里云', '阿里', 'alibaba', 'aliyun', 'dashscope'];
const isAliVendor = aliVendors.some((v) =>
vendor.toLowerCase().includes(v.toLowerCase()),
);
// 阿里云模型名称特征
const aliModelPrefixes = ['wan', 'wanx', 'qwen'];
const isAliModel = aliModelPrefixes.some((prefix) =>
modelName.toLowerCase().startsWith(prefix),
);
return isAliVendor || isAliModel;
};
const VideoInputPanel = ({
formData,
setFormData,
onCollapse,
collapsed,
selectedModel,
setSelectedModel,
modelInfo,
collapsible = true,
}) => {
const { t } = useTranslation();
// 检查当前模型是否支持高级参数
const showAdvancedParams = isAlibabaModel(selectedModel);
const hoverScale = (e) => {
e.currentTarget.style.transform = 'scale(1.1)';
};
const resetScale = (e) => {
e.currentTarget.style.transform = 'scale(1)';
};
// 根据模式动态获取模型分类
const getModelCategory = () => {
return formData.mode === 'text2video'
? MODEL_CATEGORY.TEXT_TO_VIDEO
: MODEL_CATEGORY.IMAGE_TO_VIDEO;
};
// 更新表单字段
const updateField = (field, value) => {
setFormData((prev) => ({ ...prev, [field]: value }));
};
// 选择模板
const handleTemplateSelect = (value) => {
updateField('selectedTemplate', value);
};
// 图片上传处理
const handleImageUpload = (info) => {
const { fileList } = info;
if (fileList && fileList.length > 0) {
const file = fileList[fileList.length - 1];
const fileInstance = file.fileInstance;
if (fileInstance) {
const reader = new FileReader();
reader.onload = (e) => {
setFormData((prev) => ({
...prev,
image: e.target.result,
imagePreview: e.target.result,
imageFile: fileInstance,
imageName: fileInstance.name,
imageIdentityType: 'aigc',
}));
};
reader.readAsDataURL(fileInstance);
}
}
};
// 移除图片
const handleImageRemove = () => {
setFormData((prev) => ({
...prev,
image: null,
imagePreview: null,
imageFile: null,
imageName: null,
imageIdentityType: null,
}));
};
const handlePortraitAssetSelect = (asset) => {
setFormData((prev) => ({
...prev,
image: `asset://${asset.id}`,
imagePreview: asset.preview_url || null,
imageFile: null,
imageName: asset.name,
imageIdentityType: 'real_person',
}));
};
// 单列(手机)布局不提供折叠:没有相邻面板可以让位,收起只会留下一片空白,
// 而唯一的恢复入口是一个浮在屏幕左侧垂直中央的裸箭头。
if (collapsed && collapsible) {
return (
<div
style={{
position: 'fixed',
left: 0,
top: '50%',
transform: 'translateY(-50%)',
zIndex: 100,
}}
>
<Button
icon={<ChevronRight size={20} />}
onClick={onCollapse}
style={{
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
color: '#1890ff',
}}
/>
</div>
);
}
return (
<div className='relative h-full overflow-auto' style={{ padding: '16px' }}>
{/* 背景装饰 —— 走 bg-glow-* 两 stop(from/to) */}
<div className='absolute inset-0 pointer-events-none opacity-30'>
<div className='absolute top-10 right-0 w-32 h-32 bg-gradient-to-br from-bg-glow-from/20 to-bg-glow-to/20 rounded-full blur-3xl' />
<div className='absolute bottom-20 left-0 w-40 h-40 bg-gradient-to-br from-bg-glow-from/20 to-bg-glow-to/20 rounded-full blur-3xl' />
</div>
{/* 收起按钮 —— 仅在左右分栏布局下提供 */}
{collapsible && (
<div style={{ marginBottom: '16px', textAlign: 'right' }}>
<Button
icon={<ChevronLeft size={18} />}
onClick={onCollapse}
size='small'
type='tertiary'
className='hover:bg-cyan-50 dark:hover:bg-cyan-900/30 transition-colors'
style={{ color: '#06b6d4' }}
/>
</div>
)}
{/* 生成方式 */}
<div className='relative mb-4'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-cyan-400/20 to-blue-400/20 rounded-[14px] blur-sm' />
<Card
title={
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<div className='p-1.5 bg-gradient-to-br from-cyan-500 to-blue-600 rounded-lg'>
<Layers size={14} className='text-white' />
</div>
<span className='font-semibold bg-clip-text text-transparent bg-gradient-to-r from-cyan-600 to-blue-600 dark:from-cyan-400 dark:to-blue-400'>
{t('生成方式')}
</span>
</div>
}
className='relative bg-white/90 dark:bg-neutral-900/90 backdrop-blur-sm'
style={{
borderRadius: '12px',
boxShadow: '0 4px 16px rgba(6, 182, 212, 0.08)',
border: 'none',
}}
bodyStyle={{ padding: '16px' }}
headerStyle={{ padding: '12px 16px' }}
>
<div style={{ display: 'flex', gap: '12px' }}>
<div
onClick={() => updateField('mode', 'text2video')}
onMouseEnter={hoverScale}
onMouseLeave={resetScale}
className={`group relative overflow-hidden ${formData.mode === 'text2video' ? 'ring-2 ring-cyan-500 shadow-lg shadow-cyan-500/20' : 'border border-gray-200 dark:border-neutral-700'}`}
style={{
flex: 1,
padding: '16px',
borderRadius: '12px',
cursor: 'pointer',
backgroundColor:
formData.mode === 'text2video'
? 'rgba(6, 182, 212, 0.05)'
: 'transparent',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: '8px',
transition: 'all 0.3s ease',
}}
>
{formData.mode === 'text2video' && (
<div className='absolute inset-0 bg-gradient-to-br from-cyan-500/10 to-blue-500/10' />
)}
<div
className={`relative p-2.5 rounded-xl transition-all ${formData.mode === 'text2video' ? 'bg-gradient-to-br from-cyan-500 to-blue-600 shadow-lg' : 'bg-gray-100 dark:bg-neutral-800'}`}
>
<Film
size={24}
className={
formData.mode === 'text2video'
? 'text-white'
: 'text-gray-500 dark:text-gray-400'
}
/>
</div>
<span
className={`relative text-sm font-medium ${formData.mode === 'text2video' ? 'text-cyan-600 dark:text-cyan-400' : 'text-gray-600 dark:text-gray-400'}`}
>
{t('文生视频')}
</span>
</div>
<div
onClick={() => updateField('mode', 'image2video')}
onMouseEnter={hoverScale}
onMouseLeave={resetScale}
className={`group relative overflow-hidden ${formData.mode === 'image2video' ? 'ring-2 ring-blue-500 shadow-lg shadow-blue-500/20' : 'border border-gray-200 dark:border-neutral-700'}`}
style={{
flex: 1,
padding: '16px',
borderRadius: '12px',
cursor: 'pointer',
backgroundColor:
formData.mode === 'image2video'
? 'rgba(59, 130, 246, 0.05)'
: 'transparent',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: '8px',
transition: 'all 0.3s ease',
}}
>
{formData.mode === 'image2video' && (
<div className='absolute inset-0 bg-gradient-to-br from-blue-500/10 to-brand-to/10' />
)}
<div
className={`relative p-2.5 rounded-xl transition-all ${formData.mode === 'image2video' ? 'bg-gradient-to-br from-blue-500 to-brand-to shadow-lg' : 'bg-gray-100 dark:bg-neutral-800'}`}
>
<ImageIcon
size={24}
className={
formData.mode === 'image2video'
? 'text-white'
: 'text-gray-500 dark:text-gray-400'
}
/>
</div>
<span
className={`relative text-sm font-medium ${formData.mode === 'image2video' ? 'text-blue-600 dark:text-blue-400' : 'text-gray-600 dark:text-gray-400'}`}
>
{t('图生视频')}
</span>
</div>
</div>
</Card>
</div>
{/* 模型选择 */}
<div className='relative mb-4'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-brand-from/20 to-brand-to/20 rounded-[14px] blur-sm' />
<Card
title={
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<div className='p-1.5 bg-gradient-to-br from-brand-from to-brand-to rounded-lg'>
<Wand2 size={14} className='text-white' />
</div>
<span className='font-semibold bg-clip-text text-transparent bg-gradient-to-r from-brand-from to-brand-to dark:from-brand-from dark:to-brand-to'>
{t('选择模型')}
</span>
</div>
}
className='relative bg-white/90 dark:bg-neutral-900/90 backdrop-blur-sm'
style={{
borderRadius: '12px',
boxShadow:
'0 4px 16px color-mix(in srgb, var(--brand-gradient-via) 8%, transparent)',
border: 'none',
}}
bodyStyle={{ padding: '16px' }}
headerStyle={{ padding: '12px 16px' }}
>
<ModelSelector
key={formData.mode}
category={getModelCategory()}
value={
selectedModel?.id || selectedModel?.model_name || selectedModel
}
onChange={(model) => {
setSelectedModel(model);
}}
placeholder={t('请选择模型')}
/>
{/* 模型信息简要展示 */}
{modelInfo && (
<div
style={{
marginTop: '12px',
padding: '12px',
backgroundColor: 'var(--semi-color-fill-0)',
borderRadius: '8px',
fontSize: '13px',
border: '1px solid var(--semi-color-border)',
}}
>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text type='tertiary'>{t('厂商')}</Text>
<Tag size='small' color='blue'>
{modelInfo.provider}
</Tag>
</div>
{Number(modelInfo.price) > 0 && (
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginTop: '8px',
}}
>
<Text
type='tertiary'
style={{
display: 'flex',
alignItems: 'center',
gap: '4px',
}}
>
<CreditCard size={14} />
{t('单价')}
</Text>
<Text strong style={{ color: 'var(--semi-color-danger)' }}>
{convertUSDToCurrency(Number(modelInfo.price || 0), 6)}
</Text>
</div>
)}
</div>
)}
</Card>
</div>
{/* 场景模板 */}
<div className='relative mb-4'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-amber-400/20 to-orange-400/20 rounded-[14px] blur-sm' />
<Card
title={
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<div className='p-1.5 bg-gradient-to-br from-amber-500 to-orange-500 rounded-lg'>
<Sparkles size={14} className='text-white' />
</div>
<span className='font-semibold bg-clip-text text-transparent bg-gradient-to-r from-amber-600 to-orange-600 dark:from-amber-400 dark:to-orange-400'>
{t('场景模板')}
</span>
</div>
}
className='relative bg-white/90 dark:bg-neutral-900/90 backdrop-blur-sm'
style={{
borderRadius: '12px',
boxShadow: '0 4px 16px rgba(251, 146, 60, 0.08)',
border: 'none',
}}
bodyStyle={{ padding: '16px' }}
headerStyle={{ padding: '12px 16px' }}
>
<Select
placeholder={t('选择场景模板(可选)')}
value={formData.selectedTemplate}
onChange={handleTemplateSelect}
style={{ width: '100%' }}
showClear
>
{PROMPT_TEMPLATES.map((template, index) => (
<Select.Option key={index} value={template.prompt}>
{template.label}
</Select.Option>
))}
</Select>
{formData.selectedTemplate && (
<div
style={{
marginTop: '12px',
padding: '12px',
backgroundColor: 'var(--semi-color-fill-0)',
borderRadius: '8px',
border: '1px solid var(--semi-color-border)',
}}
>
<Text type='tertiary' size='small'>
{t('模板内容')}: {formData.selectedTemplate}
</Text>
</div>
)}
</Card>
</div>
{/* 提示词 */}
<div className='relative mb-4'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-emerald-400/20 to-teal-400/20 rounded-[14px] blur-sm' />
<Card
title={
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<div className='p-1.5 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-lg'>
<Video size={14} className='text-white' />
</div>
<span className='font-semibold bg-clip-text text-transparent bg-gradient-to-r from-emerald-600 to-teal-600 dark:from-emerald-400 dark:to-teal-400'>
{t('提示词')}
</span>
</div>
}
className='relative bg-white/90 dark:bg-neutral-900/90 backdrop-blur-sm'
style={{
borderRadius: '12px',
boxShadow: '0 4px 16px rgba(20, 184, 166, 0.08)',
border: 'none',
}}
bodyStyle={{ padding: '16px' }}
headerStyle={{ padding: '12px 16px' }}
>
<TextArea
placeholder={t(
'描述你想要生成的视频内容,例如:一只可爱的猫咪在草地上玩耍',
)}
value={formData.prompt}
onChange={(value) => updateField('prompt', value)}
autosize={{ minRows: 4, maxRows: 8 }}
maxLength={2000}
showClear
/>
<Text
type='tertiary'
size='small'
style={{ marginTop: '8px', display: 'block' }}
>
{formData.prompt?.length || 0} / 2000
</Text>
</Card>
</div>
{/* 反向提示词 */}
<div className='relative mb-4'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-rose-400/20 to-pink-400/20 rounded-[14px] blur-sm' />
<Card
title={
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<div className='p-1.5 bg-gradient-to-br from-rose-500 to-pink-500 rounded-lg'>
<X size={14} className='text-white' />
</div>
<span className='font-semibold bg-clip-text text-transparent bg-gradient-to-r from-rose-600 to-pink-600 dark:from-rose-400 dark:to-pink-400'>
{t('反向提示词')}
</span>
<Tooltip content={t('描述不希望出现的内容')}>
<Info size={14} className='text-rose-400' />
</Tooltip>
</div>
}
className='relative bg-white/90 dark:bg-neutral-900/90 backdrop-blur-sm'
style={{
borderRadius: '12px',
boxShadow: '0 4px 16px rgba(244, 63, 94, 0.08)',
border: 'none',
}}
bodyStyle={{ padding: '16px' }}
headerStyle={{ padding: '12px 16px' }}
>
<TextArea
placeholder={t('例如:模糊、扭曲、低质量')}
value={formData.negative_prompt}
onChange={(value) => updateField('negative_prompt', value)}
autosize={{ minRows: 2, maxRows: 4 }}
maxLength={500}
showClear
/>
</Card>
</div>
{/* 图片上传(图生视频时显示) */}
{formData.mode === 'image2video' && (
<div className='relative mb-4'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-blue-400/20 to-brand-to/20 rounded-[14px] blur-sm' />
<Card
title={
<div
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
>
<div className='p-1.5 bg-gradient-to-br from-blue-500 to-brand-to rounded-lg'>
<ImageIcon size={14} className='text-white' />
</div>
<span className='font-semibold bg-clip-text text-transparent bg-gradient-to-r from-blue-600 to-brand-to dark:from-blue-400 dark:to-brand-to'>
{t('首帧图片')}
</span>
</div>
}
className='relative bg-white/90 dark:bg-neutral-900/90 backdrop-blur-sm'
style={{
borderRadius: '12px',
boxShadow:
'0 4px 16px color-mix(in srgb, var(--brand-primary) 8%, transparent)',
border: 'none',
}}
bodyStyle={{ padding: '16px' }}
headerStyle={{ padding: '12px 16px' }}
>
{formData.image ? (
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '12px',
padding: '12px',
backgroundColor: 'var(--semi-color-fill-0)',
borderRadius: '8px',
border: '1px solid var(--semi-color-border)',
}}
>
<img
src={formData.imagePreview || formData.image}
alt='Preview'
style={{
width: '64px',
height: '64px',
objectFit: 'cover',
borderRadius: '6px',
flexShrink: 0,
}}
/>
<div style={{ minWidth: 0 }}>
<Text
ellipsis
style={{
display: 'block',
fontSize: '13px',
fontWeight: 500,
}}
>
{formData.imageName ||
formData.imageFile?.name ||
t('已上传图片')}
</Text>
{formData.imageIdentityType === 'real_person' ? (
<Tag color='green' size='small'>
{t('真人人像')}
</Tag>
) : (
<Text type='tertiary' size='small'>
{formData.imageFile?.size
? `${(formData.imageFile.size / 1024).toFixed(1)} KB`
: ''}
</Text>
)}
</div>
<Tooltip content={t('删除图片')}>
<Button
size='small'
type='danger'
theme='borderless'
icon={<X size={16} />}
onClick={handleImageRemove}
style={{ marginLeft: 'auto' }}
/>
</Tooltip>
</div>
) : (
<Upload
accept='image/*'
limit={1}
onChange={handleImageUpload}
uploadTrigger='custom'
draggable
dragMainText={
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '8px',
}}
>
<ImageIcon
size={32}
style={{ color: '#1890ff', opacity: 0.6 }}
/>
<span>{t('点击上传或拖拽图片到此处')}</span>
</div>
}
dragSubText={t('支持 JPG、PNG 格式')}
showUploadList={false}
style={{
border: '1px dashed var(--semi-color-border)',
borderRadius: '8px',
padding: '24px',
}}
/>
)}
<div style={{ marginTop: '12px', display: 'flex' }}>
<PortraitAssetPicker
onSelect={handlePortraitAssetSelect}
selectedAssetId={
formData.image?.startsWith('asset://')
? formData.image.slice('asset://'.length)
: ''
}
onClearSelection={handleImageRemove}
/>
</div>
</Card>
</div>
)}
{/* 高级参数 - 仅对阿里云模型显示 */}
{showAdvancedParams && (
<div className='relative'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-slate-400/20 to-gray-400/20 rounded-[14px] blur-sm' />
<div
className='relative bg-white/90 dark:bg-neutral-900/90 backdrop-blur-sm rounded-xl overflow-hidden'
style={{ boxShadow: '0 4px 16px rgba(100, 116, 139, 0.08)' }}
>
<Collapse defaultActiveKey={[]} className='border-0'>
<Collapse.Panel
header={
<div
style={{
display: 'flex',
alignItems: 'center',
gap: '8px',
}}
>
<div className='p-1.5 bg-gradient-to-br from-slate-500 to-gray-600 rounded-lg'>
<Settings2 size={14} className='text-white' />
</div>
<span className='font-semibold text-slate-700 dark:text-slate-300'>
{t('高级参数')}
</span>
</div>
}
itemKey='advanced'
>
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: '20px',
}}
>
{/* 分辨率 */}
<div>
<label
style={{
display: 'flex',
alignItems: 'center',
gap: '6px',
marginBottom: '8px',
fontSize: '14px',
fontWeight: 500,
}}
>
<Maximize size={16} style={{ color: '#1890ff' }} />
{t('分辨率')}
</label>
<Select
value={formData.resolution}
onChange={(value) => updateField('resolution', value)}
style={{ width: '100%' }}
>
<Select.Option value='480P'>480P (832x480)</Select.Option>
<Select.Option value='720P'>
720P (1280x720)
</Select.Option>
<Select.Option value='1080P'>
1080P (1920x1080)
</Select.Option>
</Select>
</div>
{/* 时长 */}
<div>
<label
style={{
display: 'flex',
alignItems: 'center',
gap: '6px',
marginBottom: '8px',
fontSize: '14px',
fontWeight: 500,
}}
>
<Clock size={16} style={{ color: '#1890ff' }} />
{t('时长(秒)')}
</label>
<InputNumber
value={formData.duration}
onChange={(value) => updateField('duration', value)}
min={3}
max={10}
style={{ width: '100%' }}
/>
</div>
{/* 帧率 */}
<div>
<label
style={{
display: 'block',
marginBottom: '8px',
fontSize: '14px',
fontWeight: 500,
}}
>
{t('帧率')}
</label>
<Select
value={formData.fps}
onChange={(value) => updateField('fps', value)}
style={{ width: '100%' }}
>
<Select.Option value={24}>24 FPS</Select.Option>
<Select.Option value={30}>30 FPS</Select.Option>
<Select.Option value={60}>60 FPS</Select.Option>
</Select>
</div>
{/* 比例 */}
<div>
<label
style={{
display: 'block',
marginBottom: '8px',
fontSize: '14px',
fontWeight: 500,
}}
>
{t('画面比例')}
</label>
<Select
value={formData.ratio}
onChange={(value) => updateField('ratio', value)}
style={{ width: '100%' }}
>
<Select.Option value='16:9'>
{t('16:9 (横屏)')}
</Select.Option>
<Select.Option value='9:16'>
{t('9:16 (竖屏)')}
</Select.Option>
<Select.Option value='1:1'>
{t('1:1 (方形)')}
</Select.Option>
</Select>
</div>
{/* 音频 */}
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<label
style={{
display: 'flex',
alignItems: 'center',
gap: '6px',
fontSize: '14px',
fontWeight: 500,
}}
>
<Mic size={16} style={{ color: '#1890ff' }} />
{t('自动生成音频')}
</label>
<Switch
checked={formData.audio}
onChange={(checked) => updateField('audio', checked)}
/>
</div>
{/* Seed */}
<div>
<label
style={{
display: 'block',
marginBottom: '8px',
fontSize: '14px',
fontWeight: 500,
}}
>
{t('随机种子')}
</label>
<InputNumber
value={formData.seed}
onChange={(value) => updateField('seed', value)}
min={-1}
max={999999999}
style={{ width: '100%' }}
placeholder={t('-1 表示随机')}
/>
</div>
{/* 提示词优化 */}
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<div>
<label
style={{
display: 'block',
marginBottom: '4px',
fontSize: '14px',
fontWeight: 500,
}}
>
{t('智能改写提示词')}
</label>
<Text type='tertiary' size='small'>
{t('AI 自动优化提示词')}
</Text>
</div>
<Switch
checked={formData.prompt_extend}
onChange={(checked) =>
updateField('prompt_extend', checked)
}
/>
</div>
{/* 水印 */}
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<label
style={{
display: 'block',
fontSize: '14px',
fontWeight: 500,
}}
>
{t('添加水印')}
</label>
<Switch
checked={formData.watermark}
onChange={(checked) => updateField('watermark', checked)}
/>
</div>
</div>
</Collapse.Panel>
</Collapse>
</div>
</div>
)}
</div>
);
};
export default VideoInputPanel;
@@ -0,0 +1,151 @@
/*
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, { useEffect } from 'react';
import { Card, Typography, Space, Tag } from '@douyinfe/semi-ui';
import { IconCreditCard, IconTickCircle } from '@douyinfe/semi-icons';
import { useTranslation } from 'react-i18next';
import ModelSelector from '../../../../../components/common/ModelSelector';
import { MODEL_CATEGORY } from '../../../../../constants';
import { convertUSDToCurrency } from '../../../../../helpers';
const { Text, Paragraph } = Typography;
const VideoModelPanel = ({
selectedModel,
setSelectedModel,
modelInfo,
mode,
}) => {
const { t } = useTranslation();
// 根据模式动态获取模型分类
const getModelCategory = () => {
return mode === 'text2video'
? MODEL_CATEGORY.TEXT_TO_VIDEO
: MODEL_CATEGORY.IMAGE_TO_VIDEO;
};
// 当模式切换时,清空选中的模型
useEffect(() => {
setSelectedModel(null);
}, [mode, setSelectedModel]);
return (
<div style={{ padding: '16px', height: '100%', overflow: 'auto' }}>
{/* 模型选择 */}
<Card
title={t('选择模型')}
style={{ marginBottom: '16px' }}
bodyStyle={{ padding: '12px' }}
>
<ModelSelector
key={mode}
category={getModelCategory()}
value={
selectedModel?.id || selectedModel?.model_name || selectedModel
}
onChange={(model) => {
// 传递完整的模型对象,而不仅仅是名称
setSelectedModel(model);
}}
placeholder={t('请选择模型')}
/>
</Card>
{/* 模型信息 */}
{modelInfo && (
<Card
title={t('模型信息')}
style={{ marginBottom: '16px' }}
bodyStyle={{ padding: '12px' }}
>
<Space vertical spacing='medium' style={{ width: '100%' }}>
{/* 厂商 */}
<div>
<Text type='tertiary'>{t('厂商')}</Text>
<div style={{ marginTop: '4px' }}>
<Tag>{modelInfo.provider}</Tag>
</div>
</div>
{/* 模型描述 */}
{modelInfo.description && (
<div>
<Text type='tertiary'>{t('描述')}</Text>
<Paragraph style={{ marginTop: '4px', marginBottom: 0 }}>
{modelInfo.description}
</Paragraph>
</div>
)}
{/* 能力特点 */}
{modelInfo.features && modelInfo.features.length > 0 && (
<div>
<Text type='tertiary'>{t('能力特点')}</Text>
<Space wrap style={{ marginTop: '4px' }}>
{modelInfo.features.map((feature, index) => (
<Tag key={index} color='blue'>
<IconTickCircle
size='small'
style={{ marginRight: '4px' }}
/>
{feature}
</Tag>
))}
</Space>
</div>
)}
</Space>
</Card>
)}
{/* 模型价格 —— 单价为 0(含管理员隐藏价格场景)时不展示,避免误导性的 0.00 */}
{Number(modelInfo?.price) > 0 && (
<Card
title={
<div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
<IconCreditCard />
<span>{t('模型价格')}</span>
</div>
}
bodyStyle={{ padding: '12px' }}
>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text type='tertiary'>{t('单价')}</Text>
<Text
strong
style={{ fontSize: '18px', color: 'var(--semi-color-primary)' }}
>
{convertUSDToCurrency(Number(modelInfo?.price || 0), 6)}
</Text>
</div>
</Card>
)}
</div>
);
};
export default VideoModelPanel;
@@ -0,0 +1,66 @@
/* 视频预览面板 - 电影感动画背景(增强版) */
/* 动态光晕1 - 缓慢飘动 */
@keyframes videoPreviewFloat1 {
0%,
100% {
transform: translate3d(0, 0, 0);
}
25% {
transform: translate3d(50px, -30px, 0);
}
50% {
transform: translate3d(80px, 20px, 0);
}
75% {
transform: translate3d(30px, 50px, 0);
}
}
/* 动态光晕2 - 反向飘动 */
@keyframes videoPreviewFloat2 {
0%,
100% {
transform: translate3d(0, 0, 0);
}
25% {
transform: translate3d(-60px, 40px, 0);
}
50% {
transform: translate3d(-30px, -50px, 0);
}
75% {
transform: translate3d(-70px, -20px, 0);
}
}
/* 脉动效果 */
@keyframes videoPreviewPulse {
0%,
100% {
opacity: 0.4;
transform: scale(1);
}
50% {
opacity: 1;
transform: scale(1.1);
}
}
/* 动画类 - GPU 加速 */
.video-preview-glow1 {
animation: videoPreviewFloat1 12s ease-in-out infinite;
will-change: transform;
backface-visibility: hidden;
}
.video-preview-glow2 {
animation: videoPreviewFloat2 15s ease-in-out infinite;
will-change: transform;
backface-visibility: hidden;
}
.video-preview-glow3 {
animation: videoPreviewPulse 6s ease-in-out infinite;
will-change: opacity, transform;
}
@@ -0,0 +1,855 @@
/*
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, { useState, useEffect } from 'react';
import {
Card,
Button,
Progress,
Empty,
Space,
Typography,
Spin,
Tooltip,
} from '@douyinfe/semi-ui';
import {
Play,
Square,
Download,
RotateCcw,
Share2,
Film,
HelpCircle,
X,
Loader2,
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import {
canCancelVideoTask,
canRegenerateVideoTask,
getVideoURLFromDetail,
normalizeVideoTaskStatus,
} from '../../../../../helpers/videoTask';
import './VideoPreviewPanel.css';
const { Title, Text, Paragraph } = Typography;
const VideoPreviewPanel = ({
formData,
generating,
currentTask,
onGenerate,
onCancel,
selectedModel,
selectedTaskForPlay, // 新增:从任务列表选择的任务
onRegenerate, // 新增:再生成回调
onClearSelectedTask, // 新增:清除选中任务的回调(关闭视频播放)
}) => {
const { t } = useTranslation();
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
// 监听窗口大小变化
useEffect(() => {
const handleResize = () => {
setWindowWidth(window.innerWidth);
};
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
// 根据屏幕宽度获取响应式配置
const getResponsiveConfig = () => {
if (windowWidth > 1600) {
return {
minHeight: '400px',
padding: '40px',
videoMaxHeight: '600px',
buttonSize: 'large',
titleSize: 4,
iconSize: 64,
progressWidth: 120,
};
}
if (windowWidth > 1280) {
return {
minHeight: '350px',
padding: '32px',
videoMaxHeight: '500px',
buttonSize: 'default',
titleSize: 5,
iconSize: 56,
progressWidth: 100,
};
}
if (windowWidth > 1024) {
return {
minHeight: '300px',
padding: '24px',
videoMaxHeight: '400px',
buttonSize: 'default',
titleSize: 5,
iconSize: 48,
progressWidth: 90,
};
}
// 小屏幕
return {
minHeight: '250px',
padding: '16px',
videoMaxHeight: '350px',
buttonSize: 'small',
titleSize: 6,
iconSize: 40,
progressWidth: 80,
};
};
const config = getResponsiveConfig();
// 处理下载
const handleDownload = () => {
const task = selectedTaskForPlay || currentTask;
const videoUrl = getVideoURLFromDetail(task);
if (videoUrl) {
const link = document.createElement('a');
link.href = videoUrl;
link.download = `video_${task.task_id || 'download'}.mp4`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
};
// 处理分享
const handleShare = async () => {
const task = selectedTaskForPlay || currentTask;
const videoUrl = getVideoURLFromDetail(task);
if (videoUrl) {
if (navigator.share) {
try {
await navigator.share({
title: t('视频分享'),
text: task.prompt || t('AI生成的视频'),
url: videoUrl,
});
} catch (err) {
// 用户取消分享或分享失败
copyToClipboard(videoUrl);
}
} else {
// 不支持分享API,复制链接
copyToClipboard(videoUrl);
}
}
};
// 复制到剪贴板
const copyToClipboard = (text) => {
if (navigator.clipboard) {
navigator.clipboard.writeText(text).then(() => {
// 可以添加提示
console.log('链接已复制到剪贴板');
});
} else {
// 兼容旧浏览器
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
}
};
// 处理生成视频(同时关闭当前播放的视频)
const handleGenerate = () => {
// 先清除选中的任务,关闭视频播放窗口
if (onClearSelectedTask) {
onClearSelectedTask();
}
// 然后开始生成
if (onGenerate) {
onGenerate();
}
};
// 处理关闭视频播放窗口
const handleCloseVideo = () => {
if (onClearSelectedTask) {
onClearSelectedTask();
}
};
// 处理重新生成
const handleRegenerate = () => {
const task = selectedTaskForPlay || currentTask;
if (onRegenerate && task) {
onRegenerate(task);
} else {
// 如果没有提供 onRegenerate 回调,则直接调用 onGenerate
onGenerate();
}
};
// 判断按钮是否禁用
const isButtonDisabled =
(!formData.prompt && !formData.selectedTemplate) ||
!selectedModel ||
(typeof selectedModel === 'object' && selectedModel.level_locked) ||
(formData.mode === 'image2video' && !formData.image);
// 渲染顶部操作栏(始终显示)
const renderTopBar = () => {
// 优先显示从任务列表选择的任务
const displayTask = selectedTaskForPlay || currentTask;
const normalizedStatus = normalizeVideoTaskStatus(displayTask?.status);
const isCompleted = normalizedStatus === 'success';
// 检查是否有视频URL
let _hasVideo = false;
if (displayTask) {
const videoUrl = getVideoURLFromDetail(displayTask);
_hasVideo = isCompleted && !!videoUrl;
}
return (
<div
style={{
padding: windowWidth > 768 ? '16px 20px' : '12px 16px',
display: 'flex',
alignItems: 'center',
gap: '12px',
backgroundColor: 'var(--semi-color-bg-1)',
borderBottom: '1px solid var(--semi-color-border)',
flexShrink: 0,
}}
>
<Button
type='primary'
theme='solid'
size={windowWidth > 768 ? 'default' : 'small'}
icon={<Play size={16} fill='currentColor' />}
onClick={isButtonDisabled ? undefined : handleGenerate}
disabled={isButtonDisabled || generating}
style={{
fontWeight: 600,
background:
isButtonDisabled || generating
? undefined
: 'linear-gradient(135deg, #1890ff 0%, #0050b3 100%)',
border: 'none',
}}
>
{generating
? t('生成中...')
: windowWidth > 768
? t('开始生成')
: t('生成')}
</Button>
{/* 禁用提示 */}
{isButtonDisabled && !generating && (
<Text type='tertiary' style={{ fontSize: '12px' }}>
{!selectedModel && t('请选择模型')}
{selectedModel &&
typeof selectedModel === 'object' &&
selectedModel.level_locked &&
t('当前等级无权调用此模型')}
{selectedModel &&
!(
typeof selectedModel === 'object' && selectedModel.level_locked
) &&
!formData.prompt &&
!formData.selectedTemplate &&
t('请输入提示词或选择模板')}
{selectedModel &&
!(
typeof selectedModel === 'object' && selectedModel.level_locked
) &&
(formData.prompt || formData.selectedTemplate) &&
formData.mode === 'image2video' &&
!formData.image &&
t('请上传图片')}
</Text>
)}
{/* 生成中状态提示 */}
{generating && displayTask && (
<Text
type='tertiary'
style={{
fontSize: '12px',
display: 'flex',
alignItems: 'center',
gap: '4px',
}}
>
<Loader2 size={12} className='animate-spin' />
{displayTask.progress || '0%'}
</Text>
)}
<div style={{ flex: 1 }} />
<Tooltip
content={
<div style={{ padding: '12px', maxWidth: '300px' }}>
<div
style={{
fontWeight: 600,
marginBottom: '8px',
fontSize: '14px',
}}
>
{t('使用提示')}
</div>
<div style={{ fontSize: '13px', lineHeight: '1.8' }}>
• {t('详细的提示词能获得更好的效果')}
<br />• {t('建议使用高质量的首帧图片')}
<br />• {t('视频生成可能需要 1-3 分钟')}
<br />• {t('可在任务队列中查看历史记录')}
</div>
</div>
}
position='bottomRight'
trigger='hover'
showArrow={true}
>
<Button
icon={<HelpCircle size={18} />}
type='tertiary'
size={windowWidth > 768 ? 'default' : 'small'}
/>
</Tooltip>
</div>
);
};
// 渲染预览区域
const renderPreview = () => {
// 优先显示从任务列表选择的任务
const displayTask = selectedTaskForPlay || currentTask;
// 统一转换状态为小写进行比较
const normalizedStatus = normalizeVideoTaskStatus(displayTask?.status);
// 生成完成 - 优先检查,包括从任务列表点击播放的情况
const isCompleted = normalizedStatus === 'success';
const videoUrl = getVideoURLFromDetail(displayTask);
const taskData = displayTask?.request || {};
// 如果是已完成的任务且有视频URL,直接显示(无论是从任务列表还是当前生成)
if (isCompleted && videoUrl) {
return (
<div style={{ textAlign: 'center', padding: config.padding }}>
{/* 视频播放器容器 */}
<div
style={{
position: 'relative',
marginBottom: windowWidth > 768 ? '24px' : '16px',
}}
>
{/* 关闭按钮 */}
<Button
icon={<X size={16} />}
type='tertiary'
theme='borderless'
size='small'
onClick={handleCloseVideo}
style={{
position: 'absolute',
top: '8px',
right: '8px',
zIndex: 10,
backgroundColor: 'rgba(0, 0, 0, 0.5)',
color: 'white',
borderRadius: '50%',
}}
/>
{/* 视频播放器 */}
<video
controls
style={{
width: '100%',
maxHeight: config.videoMaxHeight,
borderRadius: '8px',
}}
src={videoUrl}
/>
</div>
{/* 操作按钮 */}
<Space wrap={windowWidth <= 768}>
<Button
type='primary'
size={config.buttonSize}
icon={<Download size={16} />}
onClick={handleDownload}
>
{windowWidth > 768 ? t('下载视频') : t('下载')}
</Button>
<Button
size={config.buttonSize}
icon={<Share2 size={16} />}
onClick={handleShare}
>
{t('分享')}
</Button>
{canRegenerateVideoTask(displayTask) && (
<Button
size={config.buttonSize}
icon={<RotateCcw size={16} />}
onClick={handleRegenerate}
>
{windowWidth > 768 ? t('再生成') : t('重新')}
</Button>
)}
</Space>
{/* 视频信息 */}
<div
style={{
marginTop: windowWidth > 768 ? '24px' : '16px',
padding: windowWidth > 768 ? '16px' : '12px',
backgroundColor: 'var(--semi-color-fill-0)',
borderRadius: '8px',
textAlign: 'left',
}}
>
<Space vertical spacing='small' style={{ width: '100%' }}>
{(taskData.prompt || displayTask.prompt) && (
<div>
<Text
strong
style={{ fontSize: windowWidth > 768 ? '14px' : '12px' }}
>
{t('提示词')}:
</Text>
<Paragraph
copyable
style={{
fontSize: windowWidth > 768 ? '13px' : '11px',
marginTop: '4px',
}}
>
{taskData.prompt || displayTask.prompt}
</Paragraph>
</div>
)}
{taskData.negative_prompt && (
<div>
<Text
strong
style={{ fontSize: windowWidth > 768 ? '14px' : '12px' }}
>
{t('反向提示词')}:
</Text>
<Paragraph
copyable
style={{
fontSize: windowWidth > 768 ? '13px' : '11px',
marginTop: '4px',
}}
>
{taskData.negative_prompt}
</Paragraph>
</div>
)}
<div>
<Text
type='tertiary'
style={{ fontSize: windowWidth > 768 ? '12px' : '10px' }}
>
{t('模型')}:{' '}
{taskData.model ||
displayTask.properties?.upstream_model_name ||
displayTask.properties?.origin_model_name ||
(typeof selectedModel === 'object'
? selectedModel?.model_name
: selectedModel)}{' '}
| {t('时长')}:{' '}
{taskData.duration || displayTask.properties?.duration || '-'}
s | {t('分辨率')}:{' '}
{taskData.resolution ||
displayTask.properties?.resolution ||
'-'}
</Text>
</div>
</Space>
</div>
</div>
);
}
// 生成中(只在没有 selectedTaskForPlay 时显示)
if (generating && displayTask && !selectedTaskForPlay) {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
minHeight: config.minHeight,
padding: config.padding,
}}
>
<Spin
size={windowWidth > 768 ? 'large' : 'default'}
indicator={<Loader2 className='animate-spin' size={32} />}
/>
<Title
heading={config.titleSize}
style={{ marginTop: '24px', marginBottom: '8px' }}
>
{t('视频生成中...')}
</Title>
<Text
type='tertiary'
style={{ fontSize: windowWidth > 768 ? '14px' : '12px' }}
>
{normalizedStatus === 'queued' && t('等待处理')}
{normalizedStatus === 'in_progress' && t('正在生成')}
</Text>
{/* 进度条 */}
{displayTask.progress !== undefined &&
(() => {
// 解析进度值,处理字符串格式(如 "50%")
let percentValue = 0;
if (typeof displayTask.progress === 'string') {
percentValue =
parseInt(displayTask.progress.replace('%', '')) || 0;
} else if (typeof displayTask.progress === 'number') {
percentValue = displayTask.progress;
}
return (
<Progress
percent={percentValue}
showInfo
type='circle'
style={{ marginTop: '24px' }}
width={config.progressWidth}
/>
);
})()}
{/* 任务信息 */}
<div style={{ marginTop: '24px', textAlign: 'center' }}>
<Space vertical spacing='small'>
<Text
type='tertiary'
style={{ fontSize: windowWidth > 768 ? '13px' : '11px' }}
>
{t('任务ID')}: {displayTask.task_id}
</Text>
<Text
type='tertiary'
style={{ fontSize: windowWidth > 768 ? '13px' : '11px' }}
>
{t('模型')}:{' '}
{typeof selectedModel === 'object'
? selectedModel?.model_name
: selectedModel}
</Text>
{displayTask.estimated_time && (
<Text
type='tertiary'
style={{ fontSize: windowWidth > 768 ? '13px' : '11px' }}
>
{t('预计时间')}: {displayTask.estimated_time}s
</Text>
)}
</Space>
</div>
{canCancelVideoTask(displayTask) && (
<Button
type='danger'
size={config.buttonSize}
icon={<Square size={16} fill='currentColor' />}
onClick={onCancel}
style={{ marginTop: '32px' }}
>
{t('取消生成')}
</Button>
)}
</div>
);
}
// 生成失败 - 检查 'failed' 或 'failure' 状态
const isFailed =
normalizedStatus === 'failed' || normalizedStatus === 'failure';
if (isFailed) {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
minHeight: config.minHeight,
padding: config.padding,
}}
>
<Empty
title={t('生成失败')}
description={
displayTask.fail_reason || displayTask.error || t('未知错误')
}
/>
{canRegenerateVideoTask(displayTask) && (
<Button
type='primary'
size={config.buttonSize}
icon={<RotateCcw size={16} />}
onClick={handleRegenerate}
style={{ marginTop: '24px' }}
>
{t('重新生成')}
</Button>
)}
</div>
);
}
// 初始状态或图生视频预览
if (formData.mode === 'image2video' && formData.image) {
return (
<div style={{ textAlign: 'center', padding: config.padding }}>
<Title
heading={config.titleSize + 1}
style={{ marginBottom: '16px' }}
>
{t('首帧预览')}
</Title>
<img
src={formData.imagePreview || formData.image}
alt='Preview'
style={{
maxWidth: '100%',
maxHeight: windowWidth > 1024 ? '500px' : '350px',
borderRadius: '8px',
}}
/>
</div>
);
}
// 默认空状态 - 纯CSS电影感动画背景(无网络资源消耗)
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
minHeight: config.minHeight,
height: '100%',
position: 'relative',
borderRadius: '12px',
overflow: 'hidden',
margin: '16px',
background:
'linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%)',
}}
>
{/* CSS动画背景 - 流动光效(增强版) */}
<div
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
overflow: 'hidden',
pointerEvents: 'none',
}}
>
{/* 动态光晕1 - 紫色 */}
<div
className='video-preview-glow1'
style={{
position: 'absolute',
width: '60%',
height: '60%',
top: '10%',
left: '5%',
background:
'radial-gradient(ellipse at center, color-mix(in srgb, var(--brand-gradient-via) 35%, transparent) 0%, color-mix(in srgb, var(--brand-gradient-via) 10%, transparent) 40%, transparent 70%)',
borderRadius: '50%',
filter: 'blur(40px)',
}}
/>
{/* 动态光晕2 - 橙红色 */}
<div
className='video-preview-glow2'
style={{
position: 'absolute',
width: '50%',
height: '50%',
bottom: '10%',
right: '5%',
background:
'radial-gradient(ellipse at center, rgba(251, 146, 60, 0.3) 0%, rgba(251, 146, 60, 0.1) 40%, transparent 70%)',
borderRadius: '50%',
filter: 'blur(40px)',
}}
/>
{/* 动态光晕3 - 金色中心 */}
<div
className='video-preview-glow3'
style={{
position: 'absolute',
width: '40%',
height: '40%',
top: '30%',
left: '30%',
background:
'radial-gradient(ellipse at center, rgba(251, 191, 36, 0.25) 0%, transparent 60%)',
borderRadius: '50%',
filter: 'blur(30px)',
}}
/>
</div>
{/* 电影宽银幕效果 - 上下黑边 */}
<div
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
height: '6%',
background:
'linear-gradient(180deg, rgba(0,0,0,0.95) 0%, transparent 100%)',
zIndex: 2,
}}
/>
<div
style={{
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
height: '6%',
background:
'linear-gradient(0deg, rgba(0,0,0,0.95) 0%, transparent 100%)',
zIndex: 2,
}}
/>
{/* 中央内容区域 */}
<div
style={{
flex: 1,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
padding: config.padding,
color: 'white',
position: 'relative',
zIndex: 3,
}}
>
<div
style={{
backgroundColor: 'rgba(255, 255, 255, 0.1)',
borderRadius: '50%',
padding: windowWidth > 1024 ? '32px' : '24px',
marginBottom: windowWidth > 768 ? '32px' : '24px',
border: '1px solid rgba(255, 255, 255, 0.2)',
boxShadow: '0 8px 32px rgba(0, 0, 0, 0.3)',
transition: 'transform 0.3s ease',
}}
onMouseEnter={(e) => {
e.currentTarget.style.transform = 'scale(1.05)';
}}
onMouseLeave={(e) => {
e.currentTarget.style.transform = 'scale(1)';
}}
>
<Film
size={config.iconSize}
style={{
color: 'rgba(255, 220, 180, 0.9)',
filter: 'drop-shadow(0 2px 12px rgba(255,200,150,0.4))',
}}
/>
</div>
<Title
heading={config.titleSize}
style={{
marginBottom: '12px',
color: 'rgba(255, 250, 245, 0.95)',
fontWeight: 700,
textShadow: '0 4px 20px rgba(0, 0, 0, 0.6)',
letterSpacing: '3px',
}}
>
{t('AI 视频生成')}
</Title>
<Text
style={{
marginBottom: windowWidth > 768 ? '24px' : '16px',
textAlign: 'center',
fontSize: windowWidth > 768 ? '16px' : '14px',
padding: '0 16px',
color: 'rgba(255, 255, 255, 0.7)',
maxWidth: '500px',
lineHeight: '1.8',
textShadow: '0 2px 8px rgba(0, 0, 0, 0.5)',
}}
>
{formData.mode === 'text2video'
? t('输入提示词,让 AI 为你创造精彩视频')
: t('上传图片并输入提示词,生成动态视频')}
</Text>
</div>
</div>
);
};
return (
<Card
style={{ height: '100%', display: 'flex', flexDirection: 'column' }}
bodyStyle={{
flex: 1,
display: 'flex',
flexDirection: 'column',
overflow: 'hidden',
padding: 0,
}}
>
{/* 始终显示的顶部操作栏 */}
{renderTopBar()}
{/* 内容区域 */}
<div style={{ flex: 1, overflow: 'auto' }}>{renderPreview()}</div>
</Card>
);
};
export default VideoPreviewPanel;
@@ -0,0 +1,296 @@
/*
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, { useState, useEffect } from 'react';
import {
Modal,
Form,
Select,
Input,
InputNumber,
Switch,
Space,
Typography,
} from '@douyinfe/semi-ui';
import { useTranslation } from 'react-i18next';
import { useIsMobile } from '../../../../../hooks/common/useIsMobile';
import ModelSelector from '../../../../../components/common/ModelSelector';
import { MODEL_CATEGORY } from '../../../../../constants';
import { buildVideoRegenerateRequest } from '../../../../../helpers/videoTask';
const { TextArea } = Input;
const { Text } = Typography;
const VideoRegenerateModal = ({ visible, onCancel, onConfirm, task }) => {
const isNarrow = useIsMobile();
const { t } = useTranslation();
const [formData, setFormData] = useState({
mode: 'text2video',
prompt: '',
negative_prompt: '',
resolution: '1080P',
duration: 5,
fps: 30,
ratio: '16:9',
audio: false,
seed: -1,
prompt_extend: false,
watermark: false,
image: '',
});
const [selectedModel, setSelectedModel] = useState('');
// 从任务数据中提取参数
useEffect(() => {
if (task && visible) {
const taskData = task.request || {};
const mode = taskData.mode || 'text2video';
const prompt = taskData.prompt || '';
const negativePrompt = taskData.negative_prompt || '';
const resolution = taskData.resolution || '1080P';
const duration = taskData.duration || 5;
const fps = taskData.fps || 30;
const ratio = taskData.ratio || '16:9';
const audio = taskData.audio === true;
const seed = taskData.seed ?? -1;
const promptExtend = taskData.prompt_extend === true;
const watermark = taskData.watermark === true;
const image = taskData.image || '';
const model = taskData.model || '';
setFormData({
mode,
prompt,
negative_prompt: negativePrompt,
resolution,
duration,
fps,
ratio,
audio,
seed,
prompt_extend: promptExtend,
watermark,
image,
});
setSelectedModel(model);
}
}, [task, visible]);
// 处理表单提交
const handleSubmit = () => {
if (!selectedModel || typeof selectedModel !== 'object') {
return;
}
// 构建请求数据
onConfirm(buildVideoRegenerateRequest(formData, selectedModel));
};
return (
<Modal
title={t('再生成视频')}
visible={visible}
onCancel={onCancel}
onOk={handleSubmit}
okText={t('确认生成')}
cancelText={t('取消')}
width={700}
bodyStyle={{
maxHeight: '70vh',
overflowX: 'hidden',
overflowY: 'auto',
}}
>
<Form
// 窄屏改为标签在上:labelWidth=120 在 ~294px 的弹窗体里要吃掉 41%,
// 剩给控件的宽度放不下 seed 输入框和它的说明文案
labelPosition={isNarrow ? 'top' : 'left'}
labelAlign='right'
labelWidth={isNarrow ? undefined : 120}
>
{/* 生成模式 */}
<Form.Label>
<Text strong>{t('生成模式')}</Text>
</Form.Label>
<Form.Input>
<Select
value={formData.mode}
onChange={(value) => {
setFormData({ ...formData, mode: value });
setSelectedModel('');
}}
style={{ width: '100%' }}
>
<Select.Option value='text2video'>{t('文生视频')}</Select.Option>
<Select.Option value='image2video'>{t('图生视频')}</Select.Option>
</Select>
</Form.Input>
{/* 模型选择 */}
<Form.Label required>
<Text strong>{t('选择模型')}</Text>
</Form.Label>
<Form.Input>
<ModelSelector
key={formData.mode}
category={
formData.mode === 'text2video'
? MODEL_CATEGORY.TEXT_TO_VIDEO
: MODEL_CATEGORY.IMAGE_TO_VIDEO
}
value={
selectedModel?.id || selectedModel?.model_name || selectedModel
}
onChange={setSelectedModel}
placeholder={t('请选择模型')}
autoSelectFirst={false}
onModelsLoaded={(models) => {
if (typeof selectedModel !== 'string' || !selectedModel) return;
const match = models.find(
(model) => model.model_name === selectedModel,
);
setSelectedModel(match || '');
}}
/>
</Form.Input>
{/* 提示词 */}
<Form.Label required>
<Text strong>{t('提示词')}</Text>
</Form.Label>
<Form.Input>
<TextArea
value={formData.prompt}
onChange={(value) => setFormData({ ...formData, prompt: value })}
placeholder={t('描述你想生成的视频内容')}
rows={3}
maxLength={2000}
showClear
/>
</Form.Input>
{/* 反向提示词 */}
<Form.Label>
<Text strong>{t('反向提示词')}</Text>
</Form.Label>
<Form.Input>
<TextArea
value={formData.negative_prompt}
onChange={(value) =>
setFormData({ ...formData, negative_prompt: value })
}
placeholder={t('描述不想出现的内容')}
rows={2}
maxLength={1000}
showClear
/>
</Form.Input>
{/* 分辨率 */}
<Form.Label>
<Text strong>{t('分辨率')}</Text>
</Form.Label>
<Form.Input>
<Select
value={formData.resolution}
onChange={(value) =>
setFormData({ ...formData, resolution: value })
}
style={{ width: '100%' }}
>
<Select.Option value='480P'>480P (832*480)</Select.Option>
<Select.Option value='720P'>720P (1280*720)</Select.Option>
<Select.Option value='1080P'>1080P (1920*1080)</Select.Option>
</Select>
</Form.Input>
{/* 时长 */}
<Form.Label>
<Text strong>{t('视频时长')}</Text>
</Form.Label>
<Form.Input>
<InputNumber
value={formData.duration}
onChange={(value) => setFormData({ ...formData, duration: value })}
min={3}
max={10}
suffix={t('秒')}
style={{ width: '100%' }}
/>
</Form.Input>
{/* 宽高比 */}
<Form.Label>
<Text strong>{t('宽高比')}</Text>
</Form.Label>
<Form.Input>
<Select
value={formData.ratio}
onChange={(value) => setFormData({ ...formData, ratio: value })}
style={{ width: '100%' }}
>
<Select.Option value='16:9'>{t('16:9 (横屏)')}</Select.Option>
<Select.Option value='9:16'>{t('9:16 (竖屏)')}</Select.Option>
<Select.Option value='1:1'>{t('1:1 (方形)')}</Select.Option>
</Select>
</Form.Input>
{/* 高级选项 */}
<Form.Label>
<Text strong>{t('高级选项')}</Text>
</Form.Label>
<Form.Input>
<Space vertical align='start' style={{ width: '100%' }}>
<Space>
<Switch
checked={formData.audio}
onChange={(checked) =>
setFormData({ ...formData, audio: checked })
}
/>
<Text>{t('生成音频')}</Text>
</Space>
<Space>
<Switch
checked={formData.prompt_extend}
onChange={(checked) =>
setFormData({ ...formData, prompt_extend: checked })
}
/>
<Text>{t('提示词扩展')}</Text>
</Space>
<Space>
<InputNumber
value={formData.seed}
onChange={(value) => setFormData({ ...formData, seed: value })}
placeholder={t('随机种子(可选)')}
min={0}
style={{ width: '100%', maxWidth: 200 }}
/>
<Text type='tertiary'>{t('固定种子可复现结果')}</Text>
</Space>
</Space>
</Form.Input>
</Form>
</Modal>
);
};
export default VideoRegenerateModal;
@@ -0,0 +1,483 @@
/*
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, { useState, useEffect } from 'react';
import {
Table,
Button,
Space,
Tag,
Progress,
Tooltip,
Modal,
Badge,
Select,
} from '@douyinfe/semi-ui';
import {
ChevronUp,
ChevronDown,
RefreshCw,
Download,
Trash2,
Play,
CheckCircle2,
AlertCircle,
Clock,
Loader2,
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useIsMobile } from '../../../../../hooks/common/useIsMobile';
import {
canRegenerateVideoTask,
normalizeVideoTaskStatus,
} from '../../../../../helpers/videoTask';
const VideoTaskQueue = ({
visible,
setVisible,
tasks,
onRefresh,
onDelete,
onDownload,
onPlay, // 新增:播放回调
onRegenerate, // 新增:再生成回调
}) => {
const { t } = useTranslation();
// 断点判定必须按「宽度」。本组件此前 20 多处响应式判断写的是 !isCompact,
// 判的是窗口高度——390x844 的手机上 844 > 768 成立,于是整个队列走桌面分支:
// 8 列合计 1190px 塞进 ~340px 容器、按钮全带文字,实际完全用不了。
const isCompact = useIsMobile();
const [selectedTasks, setSelectedTasks] = useState([]);
const [windowHeight, setWindowHeight] = useState(window.innerHeight);
const [pageSize, setPageSize] = useState(5); // 新增:分页大小状态
// 监听窗口高度变化
useEffect(() => {
const handleResize = () => {
setWindowHeight(window.innerHeight);
};
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
// 计算任务队列高度:不超过屏幕高度的20%(五分之一)
// 同时设置最小高度150px,最大高度300px
const getQueueHeight = () => {
const maxHeightPercent = windowHeight * 0.2; // 屏幕高度的20%
// 手机端工具栏本身会换行占掉 ~100px,再按 20%(844px 屏上仅 169px)会让表格只剩
// 不到 70px,连表头带分页都放不下。窄屏改用更宽松的下限。
const minHeight = isCompact ? 300 : 150;
const maxHeight = isCompact ? 420 : 300;
// 在最小和最大值之间取适当的高度
return Math.max(minHeight, Math.min(maxHeightPercent, maxHeight));
};
const queueHeight = getQueueHeight();
// 状态标签映射
const getStatusTag = (status) => {
// 统一转换为小写进行比较
const normalizedStatus = normalizeVideoTaskStatus(status);
const statusMap = {
queued: { color: 'blue', text: t('排队中'), icon: <Clock size={12} /> },
in_progress: {
color: 'cyan',
text: t('生成中'),
icon: <Loader2 size={12} className='animate-spin' />,
},
success: {
color: 'green',
text: t('已完成'),
icon: <CheckCircle2 size={12} />,
},
completed: {
color: 'green',
text: t('已完成'),
icon: <CheckCircle2 size={12} />,
},
failure: {
color: 'red',
text: t('失败'),
icon: <AlertCircle size={12} />,
},
failed: {
color: 'red',
text: t('失败'),
icon: <AlertCircle size={12} />,
},
canceled: {
color: 'grey',
text: t('已取消'),
icon: <AlertCircle size={12} />,
},
};
const config = statusMap[normalizedStatus] || {
color: 'grey',
text: status,
};
return (
<Tag
color={config.color}
style={{ display: 'inline-flex', alignItems: 'center', gap: '4px' }}
>
{config.icon}
{config.text}
</Tag>
);
};
// 批量下载 - 只下载已完成的任务
const handleBatchDownload = () => {
selectedTasks.forEach((taskId) => {
const task = tasks.find((t) => t.task_id === taskId);
if (task) {
const normalizedStatus = normalizeVideoTaskStatus(task.status);
// 只下载已完成的任务,视频URL会在 onDownload 中获取
if (normalizedStatus === 'success') {
onDownload(task);
}
}
});
};
// 批量删除
const handleBatchDelete = () => {
selectedTasks.forEach((taskId) => {
onDelete(taskId);
});
setSelectedTasks([]);
};
// 表格列定义
const columns = [
{
title: t('任务ID'),
dataIndex: 'task_id',
width: !isCompact ? 120 : 100,
render: (text) => (
<Tooltip content={text}>
<span style={{ cursor: 'pointer' }}>{text?.substring(0, 8)}...</span>
</Tooltip>
),
},
{
title: t('模式'),
dataIndex: 'action',
width: !isCompact ? 100 : 80,
render: (text) => {
// action 字段存储的是 text2video 或 image2video
const isText2Video = text === 'text2video' || text === 'TEXT2VIDEO';
return (
<Tag size={!isCompact ? 'default' : 'small'}>
{isText2Video ? t('文生视频') : t('图生视频')}
</Tag>
);
},
},
{
title: t('模型'),
dataIndex: 'model',
width: !isCompact ? 150 : 120,
render: (model) => model || '-',
},
{
title: t('提示词'),
dataIndex: 'prompt',
width: !isCompact ? 200 : 150,
ellipsis: { showTitle: true },
render: (prompt) => prompt || '-',
},
{
title: t('状态'),
dataIndex: 'status',
width: !isCompact ? 120 : 100,
render: (status) => getStatusTag(status),
},
{
title: t('进度'),
dataIndex: 'progress',
width: !isCompact ? 120 : 100,
render: (progress, record) => {
const normalizedStatus = normalizeVideoTaskStatus(record.status);
if (normalizedStatus === 'success') return '100%';
if (normalizedStatus === 'failure') return '-';
// 去除百分号并转换为数字
const percentValue =
typeof progress === 'string'
? parseInt(progress.replace('%', ''))
: progress || 0;
return <Progress percent={percentValue} showInfo size='small' />;
},
},
{
title: t('创建时间'),
dataIndex: 'created_at',
width: !isCompact ? 160 : 140,
render: (timestamp) => new Date(timestamp * 1000).toLocaleString('zh-CN'),
},
{
title: t('操作'),
dataIndex: 'operate',
width: !isCompact ? 220 : 180,
fixed: 'right',
render: (text, record) => {
const normalizedStatus = normalizeVideoTaskStatus(record.status);
return (
<Space>
{/* 播放和下载按钮:仅根据状态显示,视频URL在点击时才获取 */}
{normalizedStatus === 'success' && (
<>
<Button
size='small'
type='tertiary'
icon={<Play size={14} />}
onClick={() => onPlay && onPlay(record)}
>
{!isCompact ? t('播放') : ''}
</Button>
<Button
size='small'
type='tertiary'
icon={<Download size={14} />}
onClick={() => onDownload(record)}
>
{!isCompact ? t('下载') : ''}
</Button>
</>
)}
{/* 再生成按钮 - 对所有已完成或失败的任务显示 */}
{(normalizedStatus === 'success' ||
normalizedStatus === 'failure') &&
canRegenerateVideoTask(record) && (
<Button
size='small'
type='primary'
icon={<RefreshCw size={14} />}
onClick={() => onRegenerate && onRegenerate(record)}
>
{!isCompact ? t('再生成') : ''}
</Button>
)}
<Button
size='small'
type='danger'
icon={<Trash2 size={14} />}
onClick={() => {
Modal.warning({
title: t('确定删除此任务?'),
content: t('删除后将无法恢复'),
icon: <AlertCircle size={24} style={{ color: '#f59e0b' }} />,
okText: t('确定'),
cancelText: t('取消'),
onOk: () => onDelete(record.task_id),
centered: true,
okButtonProps: { type: 'danger' },
});
}}
>
{!isCompact ? t('删除') : ''}
</Button>
</Space>
);
},
},
];
// 统计信息
const taskStats = {
total: tasks.length,
queued: tasks.filter((t) => normalizeVideoTaskStatus(t.status) === 'queued')
.length,
in_progress: tasks.filter(
(t) => normalizeVideoTaskStatus(t.status) === 'in_progress',
).length,
completed: tasks.filter((t) => {
return normalizeVideoTaskStatus(t.status) === 'success';
}).length,
failed: tasks.filter((t) => {
return normalizeVideoTaskStatus(t.status) === 'failure';
}).length,
};
return (
<>
{/* 折叠触发器 */}
<div
style={{
position: 'absolute',
bottom: visible ? `${queueHeight}px` : '0',
left: 0,
right: 0,
height: '40px',
backgroundColor: 'var(--semi-color-bg-1)',
borderTop: '1px solid var(--semi-color-border)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
transition: 'bottom 0.3s',
zIndex: 10,
}}
onClick={() => setVisible(!visible)}
>
<Space>
{visible ? <ChevronDown size={16} /> : <ChevronUp size={16} />}
<span style={{ fontSize: !isCompact ? '14px' : '12px' }}>
{t('任务队列')} ({taskStats.total})
</span>
{taskStats.in_progress > 0 && (
<Badge count={taskStats.in_progress} type='danger' />
)}
</Space>
</div>
{/* 任务队列抽屉 */}
<div
style={{
position: 'absolute',
bottom: visible ? '0' : `-${queueHeight}px`,
left: 0,
right: 0,
height: `${queueHeight}px`,
backgroundColor: 'var(--semi-color-bg-0)',
borderTop: '1px solid var(--semi-color-border)',
transition: 'bottom 0.3s',
display: 'flex',
flexDirection: 'column',
zIndex: 9,
}}
>
{/* 工具栏 */}
<div
style={{
padding: !isCompact ? '12px 16px' : '8px 12px',
borderBottom: '1px solid var(--semi-color-border)',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
flexWrap: 'wrap',
gap: '8px',
}}
>
<Space wrap>
<Button
size={!isCompact ? 'default' : 'small'}
icon={<RefreshCw size={14} />}
onClick={onRefresh}
>
{t('刷新')}
</Button>
{selectedTasks.length > 0 && (
<>
<Button
size={!isCompact ? 'default' : 'small'}
icon={<Download size={14} />}
onClick={handleBatchDownload}
>
{t('批量下载')} ({selectedTasks.length})
</Button>
<Button
size={!isCompact ? 'default' : 'small'}
type='danger'
icon={<Trash2 size={14} />}
onClick={() => {
Modal.warning({
title: t('确定删除选中的任务?'),
content: t('将删除 {{count}} 个任务,删除后将无法恢复', {
count: selectedTasks.length,
}),
icon: (
<AlertCircle size={24} style={{ color: '#f59e0b' }} />
),
okText: t('确定删除'),
cancelText: t('取消'),
onOk: handleBatchDelete,
centered: true,
okButtonProps: { type: 'danger' },
});
}}
>
{t('批量删除')} ({selectedTasks.length})
</Button>
</>
)}
</Space>
{/* 统计信息 */}
<Space wrap>
<Tag size={!isCompact ? 'default' : 'small'} color='blue'>
{t('排队')}: {taskStats.queued}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='cyan'>
{t('生成中')}: {taskStats.in_progress}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='green'>
{t('完成')}: {taskStats.completed}
</Tag>
<Tag size={!isCompact ? 'default' : 'small'} color='red'>
{t('失败')}: {taskStats.failed}
</Tag>
{/* 分页大小选择器 */}
<Select
size={!isCompact ? 'default' : 'small'}
value={pageSize}
onChange={setPageSize}
style={{ width: !isCompact ? '120px' : '100px' }}
>
<Select.Option value={3}>3 {t('条/页')}</Select.Option>
<Select.Option value={5}>5 {t('条/页')}</Select.Option>
<Select.Option value={10}>10 {t('条/页')}</Select.Option>
<Select.Option value={20}>20 {t('条/页')}</Select.Option>
<Select.Option value={50}>50 {t('条/页')}</Select.Option>
</Select>
</Space>
</div>
{/* 任务表格 */}
<div style={{ flex: 1, overflow: 'auto' }}>
<Table
columns={columns}
dataSource={tasks}
rowKey='task_id'
scroll={{ x: 'max-content' }}
pagination={{
pageSize: pageSize,
showSizeChanger: false,
size: !isCompact ? 'default' : 'small',
}}
rowSelection={{
selectedRowKeys: selectedTasks,
onChange: setSelectedTasks,
getCheckboxProps: (record) => ({
disabled: record.status === 'in_progress',
}),
}}
size='small'
empty={t('暂无任务')}
/>
</div>
</div>
</>
);
};
export default VideoTaskQueue;