/*
Copyright (c) 2025 Tethys Plex
This file is part of Veloera.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
import React, { useEffect, useState } from 'react';
import {
API,
copy,
isAdmin,
showError,
showSuccess,
timestamp2string,
} from '../helpers';
import {
Banner,
Button,
Form,
ImagePreview,
Layout,
Modal,
Progress,
Table,
Tag,
Typography,
} from '@douyinfe/semi-ui';
import { ITEMS_PER_PAGE } from '../constants';
import { useTranslation } from 'react-i18next';
const colors = [
'amber',
'blue',
'cyan',
'green',
'grey',
'indigo',
'light-blue',
'lime',
'orange',
'pink',
'purple',
'red',
'teal',
'violet',
'yellow',
];
const LogsTable = () => {
const { t } = useTranslation();
const [isModalOpen, setIsModalOpen] = useState(false);
const [modalContent, setModalContent] = useState('');
function renderType(type) {
switch (type) {
case 'IMAGINE':
return (
{t('绘图')}
);
case 'UPSCALE':
return (
{t('放大')}
);
case 'VARIATION':
return (
{t('变换')}
);
case 'HIGH_VARIATION':
return (
{t('强变换')}
);
case 'LOW_VARIATION':
return (
{t('弱变换')}
);
case 'PAN':
return (
{t('平移')}
);
case 'DESCRIBE':
return (
{t('图生文')}
);
case 'BLEND':
return (
{t('图混合')}
);
case 'UPLOAD':
return (
上传文件
);
case 'SHORTEN':
return (
{t('缩词')}
);
case 'REROLL':
return (
{t('重绘')}
);
case 'INPAINT':
return (
{t('局部重绘-提交')}
);
case 'ZOOM':
return (
{t('变焦')}
);
case 'CUSTOM_ZOOM':
return (
{t('自定义变焦-提交')}
);
case 'MODAL':
return (
{t('窗口处理')}
);
case 'SWAP_FACE':
return (
{t('换脸')}
);
default:
return (
{t('未知')}
);
}
}
function renderCode(code) {
switch (code) {
case 1:
return (
{t('已提交')}
);
case 21:
return (
{t('等待中')}
);
case 22:
return (
{t('重复提交')}
);
case 0:
return (
{t('未提交')}
);
default:
return (
{t('未知')}
);
}
}
function renderStatus(type) {
switch (type) {
case 'SUCCESS':
return (
{t('成功')}
);
case 'NOT_START':
return (
{t('未启动')}
);
case 'SUBMITTED':
return (
{t('队列中')}
);
case 'IN_PROGRESS':
return (
{t('执行中')}
);
case 'FAILURE':
return (
{t('失败')}
);
case 'MODAL':
return (
{t('窗口等待')}
);
default:
return (
{t('未知')}
);
}
}
const renderTimestamp = (timestampInSeconds) => {
const date = new Date(timestampInSeconds * 1000); // 从秒转换为毫秒
const year = date.getFullYear(); // 获取年份
const month = ('0' + (date.getMonth() + 1)).slice(-2); // 获取月份,从0开始需要+1,并保证两位数
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 `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // 格式化输出
};
// 修改renderDuration函数以包含颜色逻辑
function renderDuration(submit_time, finishTime) {
if (!submit_time || !finishTime) return 'N/A';
const start = new Date(submit_time);
const finish = new Date(finishTime);
const durationMs = finish - start;
const durationSec = (durationMs / 1000).toFixed(1);
const color = durationSec > 60 ? 'red' : 'green';
return (
{durationSec} {t('秒')}
);
}
const columns = [
{
title: t('提交时间'),
dataIndex: 'submit_time',
render: (text, record, index) => {
return