fix(*): 全量 UI 审查与 undefined 展示异常修复
分析模块:补齐看板、排行、趋势及报表数值兜底 企业与用户中心:修复统计、成员、技能及资金字段展示 充值与交易:修复充值、发票、订单、订阅及支付字段拼接 平台页面:修复渠道、模型、服务监控与状态空值展示 通用能力:新增安全展示工具,补齐九语言文案与回归测试 文档记录:更新修复范围、影响及回滚说明
This commit is contained in:
@@ -21,6 +21,7 @@ import React from 'react';
|
||||
import { Card, Table, Button } from '@/components/ui';
|
||||
import { IconDownload } from '@/components/ui/icons';
|
||||
import { renderQuota } from '../../helpers';
|
||||
import { formatNumber, toFiniteNumber } from '../../helpers/safeDisplay';
|
||||
|
||||
const DailyStatsTable = ({ data, title, icon, t, embedded = false }) => {
|
||||
const columns = [
|
||||
@@ -68,7 +69,7 @@ const DailyStatsTable = ({ data, title, icon, t, embedded = false }) => {
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-yellow-600 font-medium'>
|
||||
¥{(val || 0).toFixed(2)}
|
||||
¥{formatNumber(val, 2, '0.00')}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
@@ -99,7 +100,7 @@ const DailyStatsTable = ({ data, title, icon, t, embedded = false }) => {
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => {
|
||||
const tokens = val || 0;
|
||||
const tokens = toFiniteNumber(val) ?? 0;
|
||||
if (tokens >= 1000000) {
|
||||
return <span>{(tokens / 1000000).toFixed(2)}M</span>;
|
||||
} else if (tokens >= 1000) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import { RefreshCw } from '@/components/common/icons/ActionIcons';
|
||||
import { ConsoleDrawer } from '@/components/console/ConsolePrimitives';
|
||||
import useOrgCacheHourly from '../../hooks/analytics/useOrgCacheHourly';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import { formatIdReference, formatPercent } from '../../helpers/safeDisplay';
|
||||
|
||||
// 图表序列色属于专用图表(VChart)配色,统计块沿用同色以便与图例对应。
|
||||
// 千分位缩写。线上单小时 cache_read 能到十亿量级,不缩写轴标签会糊成一片。
|
||||
@@ -179,7 +180,7 @@ const OrgCacheHourlySheet = ({ visible, org, onClose, t }) => {
|
||||
value: (datum) =>
|
||||
datum?.hit_rate === null || datum?.hit_rate === undefined
|
||||
? t('无流量')
|
||||
: `${Number(datum.hit_rate).toFixed(1)}%`,
|
||||
: formatPercent(datum.hit_rate, 1),
|
||||
},
|
||||
{
|
||||
key: () => t('实际消费'),
|
||||
@@ -228,14 +229,15 @@ const OrgCacheHourlySheet = ({ visible, org, onClose, t }) => {
|
||||
// 自适应量程会把 76%~87% 的波动拉成满屏振荡,像出了故障。
|
||||
min: 0,
|
||||
max: 100,
|
||||
label: { formatMethod: (v) => `${Math.round(v)}%` },
|
||||
label: { formatMethod: (v) => formatPercent(v, 0) },
|
||||
seriesIndex: [1],
|
||||
},
|
||||
],
|
||||
};
|
||||
}, [points, hasTraffic, t]);
|
||||
|
||||
const orgTitle = org?.org_name || (org ? `${t('企业')} ${org.org_id}` : '');
|
||||
const orgReference = formatIdReference(org?.org_id);
|
||||
const orgTitle = org?.org_name || (org ? `${t('企业')} ${orgReference}` : '');
|
||||
|
||||
return (
|
||||
<ConsoleDrawer
|
||||
@@ -250,7 +252,7 @@ const OrgCacheHourlySheet = ({ visible, org, onClose, t }) => {
|
||||
</span>
|
||||
{org?.org_id ? (
|
||||
<span className='text-xs font-normal text-[var(--text-secondary)]'>
|
||||
#{org.org_id}
|
||||
{orgReference}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -284,7 +286,7 @@ const OrgCacheHourlySheet = ({ visible, org, onClose, t }) => {
|
||||
value={
|
||||
totals.hit_rate === null || totals.hit_rate === undefined
|
||||
? '--'
|
||||
: `${Number(totals.hit_rate).toFixed(2)}%`
|
||||
: formatPercent(totals.hit_rate, 2)
|
||||
}
|
||||
sub={t('按 token 加权')}
|
||||
color={SERIES_COLORS.hitRate}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { formatPercent } from '../../helpers/safeDisplay';
|
||||
import { formatIdReference, formatPercent } from '../../helpers/safeDisplay';
|
||||
import React, { useState, useCallback } from 'react';
|
||||
import { Badge, Empty, Progress, Skeleton, Tag, Tooltip, theme } from 'antd';
|
||||
import { ArrowDown } from 'lucide-react';
|
||||
@@ -104,16 +104,19 @@ const OrgRealtimeUsage = ({
|
||||
key: 'org_name',
|
||||
width: 220,
|
||||
fixed: 'left',
|
||||
render: (text, record) => (
|
||||
<div className='flex items-center gap-2 min-w-0'>
|
||||
<span className='text-sm font-medium truncate' title={text || ''}>
|
||||
{text || `${t('企业')} ${record.org_id}`}
|
||||
</span>
|
||||
<span className='text-xs text-[var(--text-secondary)] flex-shrink-0'>
|
||||
#{record.org_id}
|
||||
</span>
|
||||
</div>
|
||||
),
|
||||
render: (text, record) => {
|
||||
const orgReference = formatIdReference(record.org_id);
|
||||
return (
|
||||
<div className='flex items-center gap-2 min-w-0'>
|
||||
<span className='text-sm font-medium truncate' title={text || ''}>
|
||||
{text || `${t('企业')} ${orgReference}`}
|
||||
</span>
|
||||
<span className='text-xs text-[var(--text-secondary)] flex-shrink-0'>
|
||||
{orgReference}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: (
|
||||
|
||||
@@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import { formatPercent } from '../../helpers/safeDisplay';
|
||||
import { formatNumber, formatPercent } from '../../helpers/safeDisplay';
|
||||
|
||||
import React from 'react';
|
||||
import { Card } from '@/components/ui';
|
||||
@@ -66,7 +66,7 @@ const OverviewCards = ({ overview, loading = false, t }) => {
|
||||
},
|
||||
{
|
||||
title: t('今日充值'),
|
||||
value: `¥${overview.today_topup?.toFixed(2) || '0.00'}`,
|
||||
value: `¥${formatNumber(overview.today_topup, 2, '0.00')}`,
|
||||
change: overview.today_topup_change,
|
||||
icon: <DollarSign className='w-5 h-5' />,
|
||||
color: 'yellow',
|
||||
@@ -93,7 +93,7 @@ const OverviewCards = ({ overview, loading = false, t }) => {
|
||||
},
|
||||
{
|
||||
title: t('付费率'),
|
||||
value: `${overview.pay_rate?.toFixed(1) || '0.0'}%`,
|
||||
value: formatPercent(overview.pay_rate, 1, '0.0%'),
|
||||
change: null,
|
||||
icon: <Percent className='w-5 h-5' />,
|
||||
color: 'pink',
|
||||
|
||||
@@ -18,6 +18,11 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
|
||||
import {
|
||||
formatNumber,
|
||||
formatPercent,
|
||||
toFiniteNumber,
|
||||
} from '../../helpers/safeDisplay';
|
||||
import React, { useMemo } from 'react';
|
||||
import { Card } from '@/components/ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
@@ -48,8 +53,8 @@ const TopupChannelChart = ({ data, title, icon, t }) => {
|
||||
const chartData = data.map((item) => ({
|
||||
name: item.payment_method ? t(item.payment_method) : t('未知'),
|
||||
rawName: item.payment_method,
|
||||
value: item.amount || 0,
|
||||
count: item.count || 0,
|
||||
value: toFiniteNumber(item.amount) ?? 0,
|
||||
count: toFiniteNumber(item.count) ?? 0,
|
||||
}));
|
||||
|
||||
// 根据支付渠道名称生成颜色数组
|
||||
@@ -78,7 +83,7 @@ const TopupChannelChart = ({ data, title, icon, t }) => {
|
||||
content: [
|
||||
{
|
||||
key: (datum) => datum?.name,
|
||||
value: (datum) => `¥${(datum?.value || 0).toFixed(2)}`,
|
||||
value: (datum) => `¥${formatNumber(datum?.value, 2, '0.00')}`,
|
||||
},
|
||||
{
|
||||
key: () => t('笔数'),
|
||||
@@ -108,7 +113,7 @@ const TopupChannelChart = ({ data, title, icon, t }) => {
|
||||
// 统计列表
|
||||
const channelList = data || [];
|
||||
const totalAmount = channelList.reduce(
|
||||
(sum, item) => sum + (item.amount || 0),
|
||||
(sum, item) => sum + (toFiniteNumber(item.amount) ?? 0),
|
||||
0,
|
||||
);
|
||||
|
||||
@@ -141,10 +146,10 @@ const TopupChannelChart = ({ data, title, icon, t }) => {
|
||||
</span>
|
||||
<div className='text-right'>
|
||||
<span className='font-medium'>
|
||||
¥{(item.amount || 0).toFixed(2)}
|
||||
¥{formatNumber(item.amount, 2, '0.00')}
|
||||
</span>
|
||||
<span className='text-gray-400 text-xs ml-2'>
|
||||
({item.percent?.toFixed(1)}
|
||||
({formatPercent(item.percent, 1).replace('%', '')}
|
||||
{I18N_TECHNICAL_TEXT.PERCENT_CLOSE}
|
||||
</span>
|
||||
</div>
|
||||
@@ -152,7 +157,7 @@ const TopupChannelChart = ({ data, title, icon, t }) => {
|
||||
))}
|
||||
<div className='flex items-center justify-between text-sm pt-2 font-semibold'>
|
||||
<span>{t('合计')}</span>
|
||||
<span>¥{totalAmount.toFixed(2)}</span>
|
||||
<span>¥{formatNumber(totalAmount, 2, '0.00')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
import React, { useMemo } from 'react';
|
||||
import { Card } from '@/components/ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { formatCurrency } from '@/helpers/safeDisplay';
|
||||
|
||||
const TrendCharts = ({ title, icon, data, type, t }) => {
|
||||
const spec = useMemo(() => {
|
||||
@@ -142,7 +143,7 @@ const TrendCharts = ({ title, icon, data, type, t }) => {
|
||||
content: [
|
||||
{
|
||||
key: () => topupKey,
|
||||
value: (datum) => `¥${(datum?.[topupKey] || 0).toFixed(2)}`,
|
||||
value: (datum) => formatCurrency(datum?.[topupKey]),
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -174,8 +175,7 @@ const TrendCharts = ({ title, icon, data, type, t }) => {
|
||||
content: [
|
||||
{
|
||||
key: () => consumeKey,
|
||||
value: (datum) =>
|
||||
`¥${(datum?.[consumeKey] || 0).toFixed(2)}`,
|
||||
value: (datum) => formatCurrency(datum?.[consumeKey]),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -16,7 +16,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import { formatUserReference } from '../../helpers/safeDisplay';
|
||||
import {
|
||||
formatIdReference,
|
||||
formatUserReference,
|
||||
} from '../../helpers/safeDisplay';
|
||||
|
||||
import { Trans } from 'react-i18next';
|
||||
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
|
||||
@@ -113,7 +116,7 @@ const UserRanking = ({ data, title, icon, t }) => {
|
||||
t('未知用户'),
|
||||
)}
|
||||
<span className='text-xs text-gray-400 ml-1'>
|
||||
#{item.user_id}
|
||||
{formatIdReference(item.user_id)}
|
||||
</span>
|
||||
</span>
|
||||
<span className='text-sm font-semibold text-gray-700 dark:text-gray-300 ml-2'>
|
||||
|
||||
@@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import { formatPercent } from '../../helpers/safeDisplay';
|
||||
import { formatPercent, formatRatioPercent } from '../../helpers/safeDisplay';
|
||||
|
||||
import React, { useMemo, useState, useEffect, useCallback } from 'react';
|
||||
import { Card, Spin, Tag, Progress } from '@/components/ui';
|
||||
@@ -335,10 +335,7 @@ const UserSurveyStats = ({ title, icon, t }) => {
|
||||
{techUsers}
|
||||
</div>
|
||||
<div className='text-xs text-gray-400 mt-1'>
|
||||
{totalUsers > 0
|
||||
? ((techUsers / totalUsers) * 100).toFixed(1)
|
||||
: 0}
|
||||
%
|
||||
{formatRatioPercent(techUsers, totalUsers, 1, '0.0%')}
|
||||
</div>
|
||||
</div>
|
||||
<div className='p-4 bg-gradient-to-br from-green-50 to-emerald-50 dark:from-green-900/20 dark:to-emerald-900/20 rounded-xl'>
|
||||
@@ -352,10 +349,12 @@ const UserSurveyStats = ({ title, icon, t }) => {
|
||||
{activeAIUsers}
|
||||
</div>
|
||||
<div className='text-xs text-gray-400 mt-1'>
|
||||
{totalUsers > 0
|
||||
? ((activeAIUsers / totalUsers) * 100).toFixed(1)
|
||||
: 0}
|
||||
%
|
||||
{formatRatioPercent(
|
||||
activeAIUsers,
|
||||
totalUsers,
|
||||
1,
|
||||
'0.0%',
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className='p-4 bg-gradient-to-br from-orange-50 to-amber-50 dark:from-orange-900/20 dark:to-amber-900/20 rounded-xl'>
|
||||
@@ -369,10 +368,12 @@ const UserSurveyStats = ({ title, icon, t }) => {
|
||||
{interestedUsers}
|
||||
</div>
|
||||
<div className='text-xs text-gray-400 mt-1'>
|
||||
{totalUsers > 0
|
||||
? ((interestedUsers / totalUsers) * 100).toFixed(1)
|
||||
: 0}
|
||||
%
|
||||
{formatRatioPercent(
|
||||
interestedUsers,
|
||||
totalUsers,
|
||||
1,
|
||||
'0.0%',
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -16,7 +16,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import { formatUserReference } from '../../helpers/safeDisplay';
|
||||
import {
|
||||
formatNumber,
|
||||
formatIdReference,
|
||||
formatUserReference,
|
||||
} from '../../helpers/safeDisplay';
|
||||
|
||||
import { Trans } from 'react-i18next';
|
||||
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
|
||||
@@ -86,7 +90,7 @@ const UserTopupRanking = ({ data, title, icon, t, embedded = false }) => {
|
||||
{formatUserReference(text, record.user_id, t('未知用户'))}
|
||||
</span>
|
||||
<span className='text-xs text-gray-400 truncate'>
|
||||
{I18N_TECHNICAL_TEXT.ID} {record.user_id}
|
||||
{I18N_TECHNICAL_TEXT.ID} {formatIdReference(record.user_id)}
|
||||
</span>
|
||||
</div>
|
||||
),
|
||||
@@ -99,7 +103,7 @@ const UserTopupRanking = ({ data, title, icon, t, embedded = false }) => {
|
||||
defaultSortOrder: 'descend',
|
||||
render: (value) => (
|
||||
<span className='font-semibold text-red-500'>
|
||||
¥{(value || 0).toFixed(2)}
|
||||
¥{formatNumber(value, 2, '0.00')}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -16,8 +16,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import { formatIdReference } from '../../../helpers/safeDisplay';
|
||||
import { formatPercent } from '../../../helpers/safeDisplay';
|
||||
import {
|
||||
formatIdReference,
|
||||
formatPercent,
|
||||
toFiniteNumber,
|
||||
} from '../../../helpers/safeDisplay';
|
||||
|
||||
// 企业经营决策报表:口径常量、行动清单派生、要点生成、CSV 导出
|
||||
|
||||
@@ -29,7 +32,8 @@ export const getCnyParams = () => {
|
||||
let usdRate = 1;
|
||||
try {
|
||||
const s = JSON.parse(localStorage.getItem('status') || '{}');
|
||||
usdRate = s?.usd_exchange_rate || 1;
|
||||
const parsedRate = toFiniteNumber(s?.usd_exchange_rate);
|
||||
usdRate = parsedRate !== null && parsedRate > 0 ? parsedRate : 1;
|
||||
} catch (e) {
|
||||
usdRate = 1;
|
||||
}
|
||||
@@ -37,7 +41,7 @@ export const getCnyParams = () => {
|
||||
};
|
||||
|
||||
export const quotaToCny = (quota, { quotaPerUnit, usdRate }) =>
|
||||
((quota || 0) / quotaPerUnit) * usdRate;
|
||||
((toFiniteNumber(quota) ?? 0) / quotaPerUnit) * usdRate;
|
||||
|
||||
export const formatCny = (quota, params, digits = 2) =>
|
||||
`¥${quotaToCny(quota, params).toLocaleString(undefined, {
|
||||
@@ -49,10 +53,12 @@ export const formatCny = (quota, params, digits = 2) =>
|
||||
export const changeRate = (cur, prev) =>
|
||||
prev > 0 ? (((cur || 0) - prev) / prev) * 100 : null;
|
||||
|
||||
export const formatRate = (rate) =>
|
||||
rate === null || rate === undefined
|
||||
export const formatRate = (rate) => {
|
||||
const number = Number(rate);
|
||||
return rate === null || rate === undefined || !Number.isFinite(number)
|
||||
? '—'
|
||||
: `${rate >= 0 ? '+' : ''}${rate.toFixed(1)}%`;
|
||||
: `${number >= 0 ? '+' : ''}${number.toFixed(1)}%`;
|
||||
};
|
||||
|
||||
export const pct = (part, total) => {
|
||||
const numerator = Number(part);
|
||||
|
||||
@@ -22,6 +22,7 @@ import { Empty as AntEmpty, Tag as AntTag } from 'antd';
|
||||
import { Modal, Table, Typography, Pagination, Toast } from '@/components/ui';
|
||||
import i18next from 'i18next';
|
||||
import { API, renderQuota } from '../../helpers';
|
||||
import { formatCurrency } from '../../helpers/safeDisplay';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@@ -200,7 +201,7 @@ export const MembershipHistoryContent = ({ visible, t, inline = false }) => {
|
||||
dataIndex: 'price_paid',
|
||||
key: 'price_paid',
|
||||
width: 100,
|
||||
render: (price) => `¥${price?.toFixed(2) || '0.00'}`,
|
||||
render: (price) => formatCurrency(price, '¥', 2, '¥0.00'),
|
||||
},
|
||||
{
|
||||
title: t('生效日期'),
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
} from '@/components/ui';
|
||||
import { BellRing } from 'lucide-react';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import { formatIdReference, formatNumber } from '../../helpers/safeDisplay';
|
||||
import {
|
||||
ALERT_DIM_TYPES,
|
||||
ALERT_METRICS,
|
||||
@@ -265,7 +266,7 @@ const QualityAlerts = ({ quality, t }) => {
|
||||
width: 160,
|
||||
render: (v, r) => (
|
||||
<span className='quality-num'>
|
||||
{Number(v).toFixed(2)} / {r.threshold}
|
||||
{formatNumber(v, 2)} / {formatNumber(r.threshold, 2)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
@@ -311,7 +312,7 @@ const QualityAlerts = ({ quality, t }) => {
|
||||
placeholder={t('选择渠道')}
|
||||
optionList={(options.channels || []).map((c) => ({
|
||||
value: String(c.id),
|
||||
label: `${c.name} (#${c.id})`,
|
||||
label: `${c.name || t('未知渠道')} (${formatIdReference(c.id)})`,
|
||||
}))}
|
||||
onChange={(v) => patch({ dim_key: v || '' })}
|
||||
style={{ width: '100%' }}
|
||||
@@ -529,7 +530,7 @@ const QualityAlerts = ({ quality, t }) => {
|
||||
{
|
||||
start: fmtTs(testResult.start),
|
||||
end: fmtTs(testResult.end),
|
||||
value: Number(testResult.value).toFixed(2),
|
||||
value: formatNumber(testResult.value, 2),
|
||||
samples: fmtInt(testResult.samples),
|
||||
},
|
||||
)}
|
||||
|
||||
@@ -104,15 +104,19 @@ const RemoteSelect = ({
|
||||
useEffect(() => () => window.clearTimeout(timer.current), []);
|
||||
|
||||
const optionList = useMemo(() => {
|
||||
const opts = list.map((it) => ({
|
||||
value: String(it.id),
|
||||
label: `${it.name || '-'} (#${it.id})`,
|
||||
}));
|
||||
const opts = list
|
||||
.filter((it) => it?.id !== null && it?.id !== undefined)
|
||||
.map((it) => ({
|
||||
value: String(it.id),
|
||||
label: `${it.name || '-'} (${formatIdReference(it.id)})`,
|
||||
}));
|
||||
if (value && !opts.some((o) => o.value === String(value))) {
|
||||
const name = labels.current[String(value)];
|
||||
opts.unshift({
|
||||
value: String(value),
|
||||
label: name ? `${name} (#${value})` : formatIdReference(value),
|
||||
label: name
|
||||
? `${name} (${formatIdReference(value)})`
|
||||
: formatIdReference(value),
|
||||
});
|
||||
}
|
||||
return opts;
|
||||
@@ -149,10 +153,12 @@ const QualityFilterBar = ({ quality, t, onOpenDetail }) => {
|
||||
const [moreOpen, setMoreOpen] = useState(false);
|
||||
|
||||
const idOptions = (items) =>
|
||||
(items || []).map((it) => ({
|
||||
value: String(it.id),
|
||||
label: `${it.name || '-'} (#${it.id})`,
|
||||
}));
|
||||
(items || [])
|
||||
.filter((it) => it?.id !== null && it?.id !== undefined)
|
||||
.map((it) => ({
|
||||
value: String(it.id),
|
||||
label: `${it.name || '-'} (${formatIdReference(it.id)})`,
|
||||
}));
|
||||
const strOptions = (items) =>
|
||||
(items || []).map((v) => ({ value: v, label: v }));
|
||||
|
||||
@@ -178,19 +184,20 @@ const QualityFilterBar = ({ quality, t, onOpenDetail }) => {
|
||||
if (filters.channel_id)
|
||||
push(
|
||||
'channel_id',
|
||||
`${t('渠道')}: ${nameOf(options.channels, filters.channel_id) || '#' + filters.channel_id}`,
|
||||
`${t('渠道')}: ${nameOf(options.channels, filters.channel_id) || formatIdReference(filters.channel_id)}`,
|
||||
);
|
||||
if (filters.group) push('group', `${t('分组')}: ${filters.group}`);
|
||||
if (filters.org_id) push('org_id', `${t('企业')}: #${filters.org_id}`);
|
||||
if (filters.org_id)
|
||||
push('org_id', `${t('企业')}: ${formatIdReference(filters.org_id)}`);
|
||||
if (filters.dept_id)
|
||||
push(
|
||||
'dept_id',
|
||||
`${t('部门')}: ${nameOf(options.depts, filters.dept_id) || (filters.dept_id === '0' ? t('未分配部门') : '#' + filters.dept_id)}`,
|
||||
`${t('部门')}: ${nameOf(options.depts, filters.dept_id) || (filters.dept_id === '0' ? t('未分配部门') : formatIdReference(filters.dept_id))}`,
|
||||
);
|
||||
if (filters.project_id)
|
||||
push(
|
||||
'project_id',
|
||||
`${t('项目')}: ${nameOf(options.projects, filters.project_id) || (filters.project_id === '0' ? t('未绑定项目') : '#' + filters.project_id)}`,
|
||||
`${t('项目')}: ${nameOf(options.projects, filters.project_id) || (filters.project_id === '0' ? t('未绑定项目') : formatIdReference(filters.project_id))}`,
|
||||
);
|
||||
if (filters.user_id)
|
||||
push(
|
||||
@@ -200,7 +207,7 @@ const QualityFilterBar = ({ quality, t, onOpenDetail }) => {
|
||||
if (filters.token_id)
|
||||
push(
|
||||
'token_id',
|
||||
`${t('密钥')}: ${nameOf(options.tokens, filters.token_id) || '#' + filters.token_id}`,
|
||||
`${t('密钥')}: ${nameOf(options.tokens, filters.token_id) || formatIdReference(filters.token_id)}`,
|
||||
);
|
||||
if (filters.path) push('path', `${t('接口')}: ${filters.path}`);
|
||||
if (filters.error_code)
|
||||
|
||||
@@ -22,6 +22,7 @@ import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
|
||||
import React, { useMemo } from 'react';
|
||||
import { Button, Skeleton, Tooltip } from '@/components/ui';
|
||||
import { useActualTheme } from '../../context/Theme';
|
||||
import { formatPercent } from '../../helpers/safeDisplay';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { Activity, AlertTriangle, Info, PieChart } from 'lucide-react';
|
||||
import {
|
||||
@@ -372,7 +373,7 @@ export const QualityTrendChart = ({ trend, loading, onZoom, t }) => {
|
||||
min: 0,
|
||||
max: 100,
|
||||
grid: { visible: false },
|
||||
label: { formatMethod: (v) => `${v}%` },
|
||||
label: { formatMethod: (v) => formatPercent(v, 0) },
|
||||
},
|
||||
{ orient: 'bottom', type: 'band' },
|
||||
],
|
||||
@@ -388,7 +389,7 @@ export const QualityTrendChart = ({ trend, loading, onZoom, t }) => {
|
||||
{
|
||||
seriesId: 'rateLine',
|
||||
key: t('成功率'),
|
||||
value: (d) => (d?.rate === null ? '-' : `${d?.rate}%`),
|
||||
value: (d) => formatPercent(d?.rate, 1),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -183,10 +183,12 @@ export const outcomeTagColor = {
|
||||
6: 'purple',
|
||||
};
|
||||
|
||||
export const pct = (v, digits = 1) =>
|
||||
v === null || v === undefined || Number.isNaN(v)
|
||||
export const pct = (v, digits = 1) => {
|
||||
const number = Number(v);
|
||||
return v === null || v === undefined || !Number.isFinite(number)
|
||||
? '-'
|
||||
: `${(v * 100).toFixed(digits)}%`;
|
||||
: `${(number * 100).toFixed(digits)}%`;
|
||||
};
|
||||
|
||||
export const fmtInt = (v) => Number(v || 0).toLocaleString();
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
|
||||
import { formatIdReference } from '../../helpers/safeDisplay';
|
||||
import { TestTube2 as ActionTestTube2 } from '@/components/common/icons/ActionIcons';
|
||||
import {
|
||||
RefreshCw as ActionRefreshCw,
|
||||
@@ -484,7 +485,7 @@ export default function ContentGuardSetting() {
|
||||
}}
|
||||
optionList={users.map((user) => ({
|
||||
value: user.id,
|
||||
label: `${user.display_name || user.username} (#${user.id})`,
|
||||
label: `${user.display_name || user.username || t('未知用户')} (${formatIdReference(user.id)})`,
|
||||
}))}
|
||||
emptyContent={
|
||||
userKeyword
|
||||
|
||||
@@ -45,6 +45,11 @@ import { CHANNEL_OPTIONS } from '../../../constants';
|
||||
import { IconTreeTriangleDown } from '@/components/ui/icons';
|
||||
import { ShuffleBrandIcon } from '../../common/icons/BrandIcons';
|
||||
|
||||
const formatDisplayPercent = (value, digits = 0) => {
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) ? `${number.toFixed(digits)}%` : '-';
|
||||
};
|
||||
|
||||
function ChannelStatusSwitch({ record, manageChannel, t }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
return (
|
||||
@@ -311,7 +316,7 @@ const renderDailyQuota = (record, dailyQuotaInfo, t) => {
|
||||
{t('已使用')}: {formatQuotaCount(info.daily_quota)}
|
||||
</div>
|
||||
<div>
|
||||
{t('使用率')}: {percent}%
|
||||
{t('使用率')}: {formatDisplayPercent(percent)}
|
||||
</div>
|
||||
{isExceeded && (
|
||||
<div style={{ color: 'var(--ui-color-danger)' }}>
|
||||
@@ -327,7 +332,7 @@ const renderDailyQuota = (record, dailyQuotaInfo, t) => {
|
||||
strokeColor={strokeColor}
|
||||
size='small'
|
||||
showInfo
|
||||
format={(percent) => `${percent}%`}
|
||||
format={(percent) => formatDisplayPercent(percent)}
|
||||
/>
|
||||
</div>
|
||||
</Tooltip>
|
||||
|
||||
@@ -25,6 +25,11 @@ import { copy, showError, showInfo, showSuccess } from '../../../../helpers';
|
||||
import { MODEL_TABLE_PAGE_SIZE } from '../../../../constants';
|
||||
import './model-test-modal.css';
|
||||
|
||||
const formatTestTime = (value) => {
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) ? number.toFixed(2) : '0.00';
|
||||
};
|
||||
|
||||
const ModelTestModal = ({
|
||||
showModelTestModal,
|
||||
currentTestChannel,
|
||||
@@ -141,7 +146,7 @@ const ModelTestModal = ({
|
||||
{testResult.success && (
|
||||
<Typography.Text type='secondary'>
|
||||
{t('请求时长: {{time}}s', {
|
||||
time: testResult.time.toFixed(2),
|
||||
time: formatTestTime(testResult.time),
|
||||
})}
|
||||
</Typography.Text>
|
||||
)}
|
||||
|
||||
@@ -39,6 +39,7 @@ import {
|
||||
import { IconGift } from '@/components/ui/icons';
|
||||
import { useMinimumLoadingTime } from '../../hooks/common/useMinimumLoadingTime';
|
||||
import { getCurrencyConfig } from '../../helpers/render';
|
||||
import { formatNumber, toFiniteNumber } from '../../helpers/safeDisplay';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@@ -300,7 +301,7 @@ const RechargeCard = ({
|
||||
return (
|
||||
<span className='text-xs font-normal px-2 py-0.5 bg-gray-100 dark:bg-gray-700 rounded-full text-gray-500'>
|
||||
{I18N_TECHNICAL_TEXT.USD_EXCHANGE_PREFIX}{' '}
|
||||
{rate.toFixed(2)} {symbol}
|
||||
{formatNumber(rate, 2, '1.00')} {symbol}
|
||||
</span>
|
||||
);
|
||||
})()}
|
||||
@@ -309,11 +310,14 @@ const RechargeCard = ({
|
||||
>
|
||||
<div className='grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4'>
|
||||
{presetAmounts.map((preset, index) => {
|
||||
const presetValue = toFiniteNumber(preset.value) ?? 0;
|
||||
const discount =
|
||||
preset.discount ||
|
||||
topupInfo?.discount?.[preset.value] ||
|
||||
1.0;
|
||||
const originalPrice = preset.value * priceRatio;
|
||||
toFiniteNumber(
|
||||
preset.discount ??
|
||||
topupInfo?.discount?.[preset.value],
|
||||
) ?? 1.0;
|
||||
const originalPrice =
|
||||
presetValue * (toFiniteNumber(priceRatio) ?? 0);
|
||||
const discountedPrice = originalPrice * discount;
|
||||
const hasDiscount = discount < 1.0;
|
||||
const actualPay = discountedPrice;
|
||||
@@ -326,15 +330,17 @@ const RechargeCard = ({
|
||||
if (statusStr) {
|
||||
const s = JSON.parse(statusStr);
|
||||
// 注意:如果设置了汇率值(包括1),使用设置值;只有未设置(undefined/null)时才用默认值1
|
||||
const parsedRate = toFiniteNumber(
|
||||
s?.usd_exchange_rate,
|
||||
);
|
||||
usdRate =
|
||||
s?.usd_exchange_rate !== undefined &&
|
||||
s?.usd_exchange_rate !== null
|
||||
? s.usd_exchange_rate
|
||||
parsedRate !== null && parsedRate > 0
|
||||
? parsedRate
|
||||
: 1;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
let displayValue = preset.value;
|
||||
let displayValue = presetValue;
|
||||
let displayActualPay = actualPay;
|
||||
let displaySave = save;
|
||||
|
||||
@@ -393,7 +399,7 @@ const RechargeCard = ({
|
||||
{hasDiscount && (
|
||||
<div className='text-xs font-semibold px-2 py-0.5 bg-green-100 text-green-700 rounded-full mb-2'>
|
||||
{t('省')} {symbol}
|
||||
{displaySave.toFixed(0)}
|
||||
{formatNumber(displaySave, 0, '0')}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -403,7 +409,7 @@ const RechargeCard = ({
|
||||
className={`font-bold ${isSelected ? 'text-blue-600' : 'text-gray-900 dark:text-gray-100'}`}
|
||||
>
|
||||
{symbol}
|
||||
{displayActualPay.toFixed(2)}
|
||||
{formatNumber(displayActualPay, 2, '0.00')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -43,6 +43,7 @@ import { IconSearch } from '@/components/ui/icons';
|
||||
import { API, timestamp2string } from '../../../helpers';
|
||||
import { isAdmin } from '../../../helpers/utils';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
import { formatCurrency } from '../../../helpers/safeDisplay';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@@ -236,7 +237,7 @@ const TopupHistoryModal = ({ visible, onCancel, t }) => {
|
||||
key: 'money',
|
||||
render: (money) => (
|
||||
<span className='text-base font-semibold text-rose-500'>
|
||||
¥{Number(money || 0).toFixed(2)}
|
||||
{formatCurrency(money, '¥', 2, '¥0.00')}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -24,6 +24,7 @@ import { IconRefresh, IconClose } from '@/components/ui/icons';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import QRCode from 'qrcode';
|
||||
import { API, renderQuota } from '../../../helpers';
|
||||
import { formatCurrency } from '../../../helpers/safeDisplay';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@@ -228,7 +229,7 @@ const WechatQRModal = ({ visible, onClose, orderData, pollFn }) => {
|
||||
<div>
|
||||
<Text type='secondary'>{t('支付金额:')}</Text>
|
||||
<Text strong style={{ fontSize: 20, color: '#f5222d' }}>
|
||||
¥{orderData.amount?.toFixed(2)}
|
||||
{formatCurrency(orderData.amount)}
|
||||
</Text>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user