'use client'; import { BotLog } from '@/app/infra/http/requestParam/bots/GetBotLogsResponse'; import styles from './botLog.module.css'; import { httpClient } from '@/app/infra/http/HttpClient'; import { PhotoProvider } from 'react-photo-view'; import { useTranslation } from 'react-i18next'; import { toast } from 'sonner'; export function BotLogCard({ botLog }: { botLog: BotLog }) { const { t } = useTranslation(); const baseURL = httpClient.getBaseUrl(); function formatTime(timestamp: number) { const now = new Date(); const date = new Date(timestamp * 1000); // 获取各个时间部分 const year = date.getFullYear(); const month = date.getMonth() + 1; // 月份从0开始,需要+1 const day = date.getDate(); const hours = date.getHours().toString().padStart(2, '0'); const minutes = date.getMinutes().toString().padStart(2, '0'); // 判断时间范围 const isToday = now.toDateString() === date.toDateString(); const isYesterday = new Date(now.setDate(now.getDate() - 1)).toDateString() === date.toDateString(); const isThisYear = now.getFullYear() === year; if (isToday) { return `${hours}:${minutes}`; // 今天的消息:小时:分钟 } else if (isYesterday) { return `${t('bots.yesterday')} ${hours}:${minutes}`; // 昨天的消息:昨天 小时:分钟 } else if (isThisYear) { return t('bots.dateFormat', { month, day }); // 本年消息:x月x日 } else { return t('bots.earlier'); // 更早的消息:更久之前 } } function getSubChatId(str: string) { const strArr = str.split(''); return strArr; } // 根据日志级别返回对应的样式类 function getLevelStyles(level: string) { switch (level.toLowerCase()) { case 'error': return 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400'; case 'warning': return 'bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-400'; case 'info': return 'bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400'; case 'debug': return 'bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400'; default: return 'bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-400'; } } return (
{/* 头部标签,时间 */}
{botLog.level}
{botLog.message_session_id && (
{ navigator.clipboard .writeText(botLog.message_session_id) .then(() => { toast.success(t('common.copySuccess')); }); }} title={t('common.clickToCopy')} > {getSubChatId(botLog.message_session_id)}
)}
{formatTime(botLog.timestamp)}
{botLog.text}
{botLog.images.length > 0 && (
{botLog.images.map((item) => ( ))}
)}
); }