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

130 lines
4.1 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 from 'react';
import { Button, Modal, Spin } from '@/components/ui';
import { AlertTriangle } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { compareParamSummary } from '../../hooks/creation/creationCompare';
import { formatQuoteAmount } from '../../hooks/creation/useCreationQuote';
import { displayNameOf } from './ModelPicker';
const amountOf = (item) =>
item && !item.error
? formatQuoteAmount(item.display_amount, item.currency)
: '';
/**
* 对比生成提交前摘要(WP C-2,方案 §4.2):逐模型"模型 · 实际参数 · 价格"与合计;
* 合计超过系统阈值时显示二次确认提示,确认按钮写明合计金额。
*/
const CompareSummary = ({ visible, compare, onCancel, onConfirm }) => {
const { t } = useTranslation();
const {
entries,
quote,
quoteLoading,
quoteFailed,
overThreshold,
submitting,
} = compare;
const items = quote?.items || [];
const total = quote
? formatQuoteAmount(quote.display_amount, quote.currency)
: '';
const approximate = Boolean(
quote?.approximate || items.some((item) => item?.approximate),
);
const totalText = total
? approximate
? t('约 {{amount}}', { amount: total })
: total
: quoteLoading
? t('正在估价...')
: t('价格以实际扣费为准');
return (
<Modal
visible={visible}
title={t('确认对比生成')}
onCancel={onCancel}
maskClosable={!submitting}
width='min(560px, 94vw)'
footer={
<div className='cs-summary-foot'>
<Button onClick={onCancel} disabled={submitting}>
{t('取消')}
</Button>
<Button
theme='solid'
type={overThreshold ? 'warning' : 'primary'}
loading={submitting}
onClick={onConfirm}
>
{total
? t('确认生成(合计 {{amount}})', { amount: totalText })
: t('确认生成')}
</Button>
</div>
}
>
<div className='cs-summary'>
<p className='cs-summary-desc'>
{t(
'将用同一提示词分别提交 {{n}} 个模型,每个模型单独计费,失败自动退还',
{
n: entries.length,
},
)}
</p>
<ul className='cs-summary-list'>
{entries.map((entry, i) => {
const amount = amountOf(items[i]);
const params = compareParamSummary(entry.payload);
return (
<li key={entry.payload.model} className='cs-summary-row'>
<span className='cs-summary-model' title={entry.payload.model}>
{displayNameOf(entry.model)}
</span>
<span className='cs-summary-params' title={params}>
{params || '-'}
</span>
<span className='cs-summary-price'>
{amount ? (
items[i]?.approximate ? (
t('约 {{amount}}', { amount })
) : (
amount
)
) : quoteLoading ? (
<Spin size='small' />
) : (
'-'
)}
</span>
{entry.adjustments?.length ? (
<span className='cs-summary-note'>
{t('部分参数已按该模型调整')}
</span>
) : null}
</li>
);
})}
</ul>
<div className='cs-summary-total'>
<span>{t('合计')}</span>
<span className='cs-num'>{totalText}</span>
</div>
{quoteFailed ? (
<p className='cs-summary-desc'>{t('估价失败,价格以实际扣费为准')}</p>
) : null}
{overThreshold ? (
<div className='cs-summary-warn' role='alert'>
<AlertTriangle size={14} aria-hidden='true' />
<span>{t('本次合计金额较高,请确认后再生成')}</span>
</div>
) : null}
</div>
</Modal>
);
};
export default CompareSummary;