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,120 @@
/*
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, Typography, Tag } from '@douyinfe/semi-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;