Files
monkey-ai-web/src/pages/ExperienceCenter/components/AICreation/ImageCompareModal.jsx
T
zhanjunhao 2aa9d73325 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

102 lines
3.5 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React, { useState, useEffect } from 'react';
import { Modal, Typography, Tag } from '@/components/ui';
import { useTranslation } from 'react-i18next';
const { Text } = Typography;
const ImageCompareModal = ({ visible, tasks, onClose }) => {
const { t } = useTranslation();
// 跟随窗口尺寸变化,保证 Modal 不会溢出视口
const [viewportWidth, setViewportWidth] = useState(
typeof window !== 'undefined' ? window.innerWidth : 1280,
);
useEffect(() => {
if (typeof window === 'undefined') return;
const onResize = () => setViewportWidth(window.innerWidth);
window.addEventListener('resize', onResize);
return () => window.removeEventListener('resize', onResize);
}, []);
if (!visible || !tasks || tasks.length === 0) return null;
// 自适应列数:2 张并排,3 张 3 列,4 张 2×2
const cols = tasks.length === 4 ? 2 : tasks.length;
// 宽度 = 内容理想宽度,但不超过视口(留 48px 边距)和 1280 上限
const ideal = 360 * cols + 64;
const modalWidth = Math.min(1280, ideal, Math.max(320, viewportWidth - 48));
return (
<Modal
title={t('对比 {{n}} 张图片', { n: tasks.length })}
visible={visible}
onCancel={onClose}
footer={null}
width={modalWidth}
bodyStyle={{ maxHeight: '80vh', overflow: 'auto', padding: 16 }}
>
<div
style={{
display: 'grid',
gridTemplateColumns: `repeat(${cols}, 1fr)`,
gap: '16px',
}}
>
{tasks.map((task) => (
<div
key={task.id}
className='rounded-lg overflow-hidden border border-gray-200 dark:border-neutral-700 bg-white dark:bg-neutral-900'
>
<div className='aspect-square bg-gray-50 dark:bg-neutral-800 flex items-center justify-center overflow-hidden'>
{task.imageUrl ? (
<img
src={task.imageUrl}
alt=''
className='w-full h-full object-contain'
/>
) : (
<Text type='tertiary'>{t('无图片')}</Text>
)}
</div>
<div className='p-3 space-y-2'>
<div className='flex items-center gap-2 flex-wrap'>
<Tag
size='small'
color='grey'
className='!rounded !border-brand/25 !bg-brand/10 !text-brand-deep dark:!border-brand/25 dark:!bg-brand/15 dark:!text-brand-from'
>
{task.model || t('未知模型')}
</Tag>
<Tag size='small' color='grey' className='!rounded'>
{task.width}×{task.height}
</Tag>
{task.quality && (
<Tag size='small' color='grey' className='!rounded'>
{task.quality}
</Tag>
)}
</div>
<Text
size='small'
className='block text-gray-600 dark:text-gray-300'
style={{
display: '-webkit-box',
WebkitLineClamp: 4,
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
wordBreak: 'break-word',
}}
title={task.prompt}
>
{task.prompt || t('(无提示词)')}
</Text>
</div>
</div>
))}
</div>
</Modal>
);
};
export default ImageCompareModal;