Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,519 @@
|
||||
/*
|
||||
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 { Progress, Tooltip, Typography } from '@douyinfe/semi-ui';
|
||||
import {
|
||||
Music,
|
||||
FileText,
|
||||
HelpCircle,
|
||||
CheckCircle,
|
||||
Pause,
|
||||
Clock,
|
||||
Play,
|
||||
XCircle,
|
||||
Loader,
|
||||
List,
|
||||
Hash,
|
||||
Video,
|
||||
Sparkles,
|
||||
Timer,
|
||||
Image as ImageIcon,
|
||||
ImagePlus,
|
||||
Coins,
|
||||
Cpu,
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
TASK_ACTION_FIRST_TAIL_GENERATE,
|
||||
TASK_ACTION_GENERATE,
|
||||
TASK_ACTION_REFERENCE_GENERATE,
|
||||
TASK_ACTION_TEXT_GENERATE,
|
||||
IMAGE_ACTION_GENERATE,
|
||||
IMAGE_ACTION_EDIT,
|
||||
} from '../../../constants/common.constant';
|
||||
import { CHANNEL_OPTIONS } from '../../../constants/channel.constants';
|
||||
import { renderQuota } from '../../../helpers';
|
||||
|
||||
// 仅保留与下方 COLOR_CONFIG 一一对应的色值,避免 amber/lime/violet/teal/indigo/light-blue
|
||||
// 经历多级三元 fallback 后被挤压到少数颜色上,渠道颜色分布严重偏斜
|
||||
const colors = [
|
||||
'blue',
|
||||
'cyan',
|
||||
'green',
|
||||
'grey',
|
||||
'orange',
|
||||
'pink',
|
||||
'purple',
|
||||
'red',
|
||||
'yellow',
|
||||
];
|
||||
|
||||
// 颜色配置映射
|
||||
const COLOR_CONFIG = {
|
||||
green: {
|
||||
bg: 'bg-emerald-50 dark:bg-emerald-950/30',
|
||||
text: 'text-emerald-600 dark:text-emerald-400',
|
||||
border: 'border-emerald-200/50 dark:border-emerald-800/50',
|
||||
gradient: 'from-emerald-500 to-green-600',
|
||||
},
|
||||
yellow: {
|
||||
bg: 'bg-amber-50 dark:bg-amber-950/30',
|
||||
text: 'text-amber-600 dark:text-amber-400',
|
||||
border: 'border-amber-200/50 dark:border-amber-800/50',
|
||||
gradient: 'from-amber-500 to-yellow-600',
|
||||
},
|
||||
blue: {
|
||||
bg: 'bg-blue-50 dark:bg-blue-950/30',
|
||||
text: 'text-blue-600 dark:text-blue-400',
|
||||
border: 'border-blue-200/50 dark:border-blue-800/50',
|
||||
gradient: 'from-blue-500 to-brand-to',
|
||||
},
|
||||
red: {
|
||||
bg: 'bg-rose-50 dark:bg-rose-950/30',
|
||||
text: 'text-rose-600 dark:text-rose-400',
|
||||
border: 'border-rose-200/50 dark:border-rose-800/50',
|
||||
gradient: 'from-rose-500 to-red-600',
|
||||
},
|
||||
orange: {
|
||||
bg: 'bg-orange-50 dark:bg-orange-950/30',
|
||||
text: 'text-orange-600 dark:text-orange-400',
|
||||
border: 'border-orange-200/50 dark:border-orange-800/50',
|
||||
gradient: 'from-orange-500 to-amber-600',
|
||||
},
|
||||
grey: {
|
||||
bg: 'bg-gray-50 dark:bg-gray-900/30',
|
||||
text: 'text-gray-600 dark:text-gray-400',
|
||||
border: 'border-gray-200/50 dark:border-gray-700/50',
|
||||
gradient: 'from-gray-400 to-gray-600',
|
||||
},
|
||||
pink: {
|
||||
bg: 'bg-pink-50 dark:bg-pink-950/30',
|
||||
text: 'text-pink-600 dark:text-pink-400',
|
||||
border: 'border-pink-200/50 dark:border-pink-800/50',
|
||||
gradient: 'from-pink-500 to-rose-600',
|
||||
},
|
||||
purple: {
|
||||
bg: 'bg-brand/5 dark:bg-brand-deep/30',
|
||||
text: 'text-brand-deep dark:text-brand-from',
|
||||
border: 'border-brand/50 dark:border-brand-deep/50',
|
||||
gradient: 'from-brand-from to-brand-to',
|
||||
},
|
||||
cyan: {
|
||||
bg: 'bg-cyan-50 dark:bg-cyan-950/30',
|
||||
text: 'text-cyan-600 dark:text-cyan-400',
|
||||
border: 'border-cyan-200/50 dark:border-cyan-800/50',
|
||||
gradient: 'from-cyan-500 to-teal-600',
|
||||
},
|
||||
};
|
||||
|
||||
// 自定义标签组件
|
||||
const CustomTag = ({
|
||||
icon: Icon,
|
||||
label,
|
||||
colorKey = 'grey',
|
||||
animate = false,
|
||||
}) => {
|
||||
const config = COLOR_CONFIG[colorKey] || COLOR_CONFIG.grey;
|
||||
return (
|
||||
<span
|
||||
className={`
|
||||
inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium
|
||||
${config.bg} ${config.text} border ${config.border}
|
||||
transition-all duration-200 hover:scale-105
|
||||
`}
|
||||
>
|
||||
<span
|
||||
className={`flex items-center justify-center w-4 h-4 rounded-full bg-gradient-to-br ${config.gradient}`}
|
||||
>
|
||||
<Icon
|
||||
className={`w-2.5 h-2.5 text-white ${animate ? 'animate-spin' : ''}`}
|
||||
strokeWidth={2.5}
|
||||
/>
|
||||
</span>
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
// Render functions
|
||||
const renderTimestamp = (timestampInSeconds) => {
|
||||
const date = new Date(timestampInSeconds * 1000);
|
||||
const year = date.getFullYear();
|
||||
const month = ('0' + (date.getMonth() + 1)).slice(-2);
|
||||
const day = ('0' + date.getDate()).slice(-2);
|
||||
const hours = ('0' + date.getHours()).slice(-2);
|
||||
const minutes = ('0' + date.getMinutes()).slice(-2);
|
||||
const seconds = ('0' + date.getSeconds()).slice(-2);
|
||||
|
||||
return (
|
||||
<span className='text-xs text-gray-600 dark:text-gray-300 font-mono'>
|
||||
{`${year}-${month}-${day}`}
|
||||
<span className='text-gray-400 dark:text-gray-500 mx-1'>|</span>
|
||||
{`${hours}:${minutes}:${seconds}`}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
function renderDuration(submit_time, finishTime) {
|
||||
if (!submit_time || !finishTime) return '-';
|
||||
const durationSec = finishTime - submit_time;
|
||||
const colorKey = durationSec > 60 ? 'red' : 'green';
|
||||
|
||||
return (
|
||||
<CustomTag icon={Timer} label={`${durationSec} 秒`} colorKey={colorKey} />
|
||||
);
|
||||
}
|
||||
|
||||
const renderType = (type, t) => {
|
||||
const typeConfig = {
|
||||
MUSIC: { icon: Music, label: t('生成音乐'), color: 'grey' },
|
||||
LYRICS: { icon: FileText, label: t('生成歌词'), color: 'pink' },
|
||||
[TASK_ACTION_GENERATE]: {
|
||||
icon: Sparkles,
|
||||
label: t('图生视频'),
|
||||
color: 'blue',
|
||||
},
|
||||
[TASK_ACTION_TEXT_GENERATE]: {
|
||||
icon: Sparkles,
|
||||
label: t('文生视频'),
|
||||
color: 'blue',
|
||||
},
|
||||
[TASK_ACTION_FIRST_TAIL_GENERATE]: {
|
||||
icon: Sparkles,
|
||||
label: t('首尾生视频'),
|
||||
color: 'blue',
|
||||
},
|
||||
[TASK_ACTION_REFERENCE_GENERATE]: {
|
||||
icon: Sparkles,
|
||||
label: t('参照生视频'),
|
||||
color: 'blue',
|
||||
},
|
||||
[IMAGE_ACTION_GENERATE]: {
|
||||
icon: Sparkles,
|
||||
label: t('文生图'),
|
||||
color: 'cyan',
|
||||
},
|
||||
[IMAGE_ACTION_EDIT]: {
|
||||
icon: ImagePlus,
|
||||
label: t('图像编辑'),
|
||||
color: 'purple',
|
||||
},
|
||||
};
|
||||
|
||||
const config = typeConfig[type] || {
|
||||
icon: HelpCircle,
|
||||
label: t('未知'),
|
||||
color: 'grey',
|
||||
};
|
||||
return (
|
||||
<CustomTag
|
||||
icon={config.icon}
|
||||
label={config.label}
|
||||
colorKey={config.color}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const renderPlatform = (platform, t) => {
|
||||
let option = CHANNEL_OPTIONS.find(
|
||||
(opt) => String(opt.value) === String(platform),
|
||||
);
|
||||
if (option) {
|
||||
return (
|
||||
<CustomTag
|
||||
icon={Video}
|
||||
label={option.label}
|
||||
colorKey={option.color || 'cyan'}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (platform === 'suno') {
|
||||
return <CustomTag icon={Music} label='Suno' colorKey='green' />;
|
||||
}
|
||||
if (platform === 'image') {
|
||||
return <CustomTag icon={ImageIcon} label={t('图片')} colorKey='cyan' />;
|
||||
}
|
||||
if (platform === 'video') {
|
||||
return <CustomTag icon={Video} label={t('视频')} colorKey='blue' />;
|
||||
}
|
||||
if (platform === 'mj') {
|
||||
return <CustomTag icon={Sparkles} label='Midjourney' colorKey='purple' />;
|
||||
}
|
||||
return <CustomTag icon={HelpCircle} label={t('未知')} colorKey='grey' />;
|
||||
};
|
||||
|
||||
const renderStatus = (type, t) => {
|
||||
const statusConfig = {
|
||||
SUCCESS: { icon: CheckCircle, label: t('成功'), color: 'green' },
|
||||
NOT_START: { icon: Pause, label: t('未启动'), color: 'grey' },
|
||||
SUBMITTED: { icon: Clock, label: t('队列中'), color: 'yellow' },
|
||||
IN_PROGRESS: {
|
||||
icon: Play,
|
||||
label: t('执行中'),
|
||||
color: 'blue',
|
||||
animate: false,
|
||||
},
|
||||
FAILURE: { icon: XCircle, label: t('失败'), color: 'red' },
|
||||
QUEUED: { icon: List, label: t('排队中'), color: 'orange' },
|
||||
UNKNOWN: { icon: HelpCircle, label: t('未知'), color: 'grey' },
|
||||
'': { icon: Loader, label: t('正在提交'), color: 'grey', animate: true },
|
||||
};
|
||||
|
||||
const config = statusConfig[type] || statusConfig['UNKNOWN'];
|
||||
return (
|
||||
<CustomTag
|
||||
icon={config.icon}
|
||||
label={config.label}
|
||||
colorKey={config.color}
|
||||
animate={config.animate}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const getTaskLogsColumns = ({
|
||||
t,
|
||||
COLUMN_KEYS,
|
||||
copyText,
|
||||
openContentModal,
|
||||
isAdminUser,
|
||||
openVideoModal,
|
||||
}) => {
|
||||
return [
|
||||
{
|
||||
key: COLUMN_KEYS.SUBMIT_TIME,
|
||||
title: t('提交时间'),
|
||||
dataIndex: 'submit_time',
|
||||
render: (text, record, index) => {
|
||||
return <div>{text ? renderTimestamp(text) : '-'}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.FINISH_TIME,
|
||||
title: t('结束时间'),
|
||||
dataIndex: 'finish_time',
|
||||
render: (text, record, index) => {
|
||||
return <div>{text ? renderTimestamp(text) : '-'}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.DURATION,
|
||||
title: t('花费时间'),
|
||||
dataIndex: 'finish_time',
|
||||
render: (finish, record) => {
|
||||
return <>{finish ? renderDuration(record.submit_time, finish) : '-'}</>;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.CHANNEL,
|
||||
title: t('渠道'),
|
||||
dataIndex: 'channel_id',
|
||||
render: (text, record, index) => {
|
||||
if (!isAdminUser) return null;
|
||||
|
||||
const idNum = parseInt(text);
|
||||
const colorIndex = Number.isFinite(idNum)
|
||||
? ((idNum % colors.length) + colors.length) % colors.length
|
||||
: 0;
|
||||
const colorKey = colors[colorIndex];
|
||||
|
||||
// 若后端返回 channel_name 则在 Tooltip 中显示名称,便于管理员快速识别;否则回落为 ID
|
||||
const tooltipContent = record.channel_name || text;
|
||||
|
||||
return (
|
||||
<Tooltip content={tooltipContent}>
|
||||
<span onClick={() => copyText(text)} className='cursor-pointer'>
|
||||
<CustomTag icon={Hash} label={text} colorKey={colorKey} />
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.PLATFORM,
|
||||
title: t('平台'),
|
||||
dataIndex: 'platform',
|
||||
render: (text, record, index) => {
|
||||
return <div>{renderPlatform(text, t)}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.TYPE,
|
||||
title: t('类型'),
|
||||
dataIndex: 'action',
|
||||
render: (text, record, index) => {
|
||||
return <div>{renderType(text, t)}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.MODEL,
|
||||
title: t('模型'),
|
||||
dataIndex: 'properties',
|
||||
render: (properties, record, index) => {
|
||||
const modelName =
|
||||
properties?.origin_model_name ||
|
||||
properties?.upstream_model_name ||
|
||||
'';
|
||||
if (!modelName) {
|
||||
return (
|
||||
<span className='text-xs text-gray-400 dark:text-gray-500'>-</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Tooltip content={modelName}>
|
||||
<span
|
||||
onClick={() => copyText(modelName)}
|
||||
className='cursor-pointer'
|
||||
>
|
||||
<CustomTag icon={Cpu} label={modelName} colorKey='purple' />
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.TASK_ID,
|
||||
title: t('任务ID'),
|
||||
dataIndex: 'task_id',
|
||||
render: (text, record, index) => {
|
||||
return (
|
||||
<Typography.Text
|
||||
ellipsis={{ showTooltip: true }}
|
||||
onClick={() => {
|
||||
openContentModal(JSON.stringify(record, null, 2));
|
||||
}}
|
||||
className='cursor-pointer hover:text-blue-500 dark:hover:text-blue-400 transition-colors font-mono text-xs'
|
||||
>
|
||||
{text}
|
||||
</Typography.Text>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.TASK_STATUS,
|
||||
title: t('任务状态'),
|
||||
dataIndex: 'status',
|
||||
render: (text, record, index) => {
|
||||
return <div>{renderStatus(text, t)}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.PROGRESS,
|
||||
title: t('进度'),
|
||||
dataIndex: 'progress',
|
||||
render: (text, record, index) => {
|
||||
if (isNaN(text?.replace('%', ''))) {
|
||||
return <span className='text-xs text-gray-500'>{text || '-'}</span>;
|
||||
}
|
||||
|
||||
const percent = text ? parseInt(text.replace('%', '')) : 0;
|
||||
const isFailure = record.status === 'FAILURE';
|
||||
|
||||
return (
|
||||
<div className='min-w-[140px]'>
|
||||
<Progress
|
||||
stroke={
|
||||
isFailure
|
||||
? 'var(--semi-color-warning)'
|
||||
: 'var(--semi-color-primary)'
|
||||
}
|
||||
percent={percent}
|
||||
showInfo={true}
|
||||
aria-label='task progress'
|
||||
size='small'
|
||||
className='task-progress'
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.QUOTA,
|
||||
title: t('费用'),
|
||||
dataIndex: 'quota',
|
||||
render: (quota, record, index) => {
|
||||
if (quota === undefined || quota === null || quota === 0) {
|
||||
return (
|
||||
<span className='text-xs text-gray-400 dark:text-gray-500'>-</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<CustomTag
|
||||
icon={Coins}
|
||||
label={renderQuota(quota, 6)}
|
||||
colorKey='orange'
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.FAIL_REASON,
|
||||
title: t('详情'),
|
||||
dataIndex: 'fail_reason',
|
||||
fixed: 'right',
|
||||
render: (text, record, index) => {
|
||||
const isVideoTask =
|
||||
record.action === TASK_ACTION_GENERATE ||
|
||||
record.action === TASK_ACTION_TEXT_GENERATE ||
|
||||
record.action === TASK_ACTION_FIRST_TAIL_GENERATE ||
|
||||
record.action === TASK_ACTION_REFERENCE_GENERATE;
|
||||
const isSuccess = record.status === 'SUCCESS';
|
||||
const isUrl = typeof text === 'string' && /^https?:\/\//.test(text);
|
||||
|
||||
if (isSuccess && isVideoTask && isUrl) {
|
||||
const videoUrl = `/v1/videos/${record.task_id}/content`;
|
||||
// text 是上游原始视频 URL,传给弹窗用于"复制链接";代理路径仅用于播放
|
||||
return (
|
||||
<a
|
||||
href='#'
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
openVideoModal(videoUrl, text);
|
||||
}}
|
||||
className='inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-gradient-to-r from-blue-500 to-brand-to text-white hover:from-blue-600 hover:to-brand-to transition-all duration-300 shadow-sm hover:shadow-md'
|
||||
>
|
||||
<Video className='w-3.5 h-3.5' />
|
||||
{t('点击预览视频')}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
if (!text) {
|
||||
return (
|
||||
<span className='text-xs text-gray-400 dark:text-gray-500'>
|
||||
{t('无')}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Typography.Text
|
||||
ellipsis={{ showTooltip: true }}
|
||||
style={{ width: 100 }}
|
||||
onClick={() => {
|
||||
openContentModal(text);
|
||||
}}
|
||||
className='cursor-pointer hover:text-blue-500 dark:hover:text-blue-400 transition-colors text-xs'
|
||||
>
|
||||
{text}
|
||||
</Typography.Text>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
Reference in New Issue
Block a user