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);
|
||||
|
||||
Reference in New Issue
Block a user