mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-15 20:16:02 +00:00
🐛 fix: fix format short number (#5294)
* pin pdfjs dist * refactor * fix number format * Revert "pin pdfjs dist" This reverts commit 1a2eae1494d2355c0354dd44b1af767a77c8a548. * fix * fix * fix
This commit is contained in:
+2
-8
@@ -10,7 +10,6 @@ const enableReactScan = !!process.env.REACT_SCAN_MONITOR_API_KEY;
|
||||
const isUsePglite = process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite';
|
||||
|
||||
// if you need to proxy the api endpoint to remote server
|
||||
const API_PROXY_ENDPOINT = process.env.API_PROXY_ENDPOINT || '';
|
||||
|
||||
const basePath = process.env.NEXT_PUBLIC_BASE_PATH;
|
||||
|
||||
@@ -28,7 +27,6 @@ const nextConfig: NextConfig = {
|
||||
],
|
||||
webVitalsAttribution: ['CLS', 'LCP'],
|
||||
},
|
||||
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
@@ -166,14 +164,10 @@ const nextConfig: NextConfig = {
|
||||
source: '/welcome',
|
||||
},
|
||||
],
|
||||
rewrites: async () => [
|
||||
// due to google api not work correct in some countries
|
||||
// we need a proxy to bypass the restriction
|
||||
{ destination: `${API_PROXY_ENDPOINT}/api/chat/google`, source: '/api/chat/google' },
|
||||
],
|
||||
|
||||
serverExternalPackages: ['@electric-sql/pglite'],
|
||||
|
||||
transpilePackages: ['pdfjs-dist', 'mermaid'],
|
||||
|
||||
webpack(config) {
|
||||
config.experiments = {
|
||||
asyncWebAssembly: true,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { Icon, Tooltip } from '@lobehub/ui';
|
||||
import { Badge } from 'antd';
|
||||
import { createStyles } from 'antd-style';
|
||||
import { isNumber, isUndefined } from 'lodash-es';
|
||||
import { isUndefined } from 'lodash-es';
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { memo, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -14,6 +14,7 @@ import { messageService } from '@/services/message';
|
||||
import { sessionService } from '@/services/session';
|
||||
import { topicService } from '@/services/topic';
|
||||
import { useServerConfigStore } from '@/store/serverConfig';
|
||||
import { formatShortenNumber } from '@/utils/format';
|
||||
import { today } from '@/utils/time';
|
||||
|
||||
const useStyles = createStyles(({ css, token }) => ({
|
||||
@@ -42,23 +43,6 @@ const useStyles = createStyles(({ css, token }) => ({
|
||||
`,
|
||||
}));
|
||||
|
||||
const formatNumber = (num: any) => {
|
||||
if (!isNumber(num)) return num;
|
||||
// 使用Intl.NumberFormat来添加千分号
|
||||
const formattedWithComma = new Intl.NumberFormat('en-US').format(num);
|
||||
|
||||
// 格式化为 K 或 M
|
||||
if (num >= 10_000_000) {
|
||||
return (num / 1_000_000).toFixed(1) + 'M';
|
||||
} else if (num >= 10_000) {
|
||||
return (num / 1000).toFixed(1) + 'K';
|
||||
} else if (num === 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return formattedWithComma;
|
||||
}
|
||||
};
|
||||
|
||||
const DataStatistics = memo<Omit<FlexboxProps, 'children'>>(({ style, ...rest }) => {
|
||||
const mobile = useServerConfigStore((s) => s.isMobile);
|
||||
// sessions
|
||||
@@ -128,7 +112,7 @@ const DataStatistics = memo<Omit<FlexboxProps, 'children'>>(({ style, ...rest })
|
||||
key={item.key}
|
||||
>
|
||||
<Flexbox gap={2}>
|
||||
<div className={styles.count}>{formatNumber(item.count)}</div>
|
||||
<div className={styles.count}>{formatShortenNumber(item.count)}</div>
|
||||
<div className={styles.title}>{item.title}</div>
|
||||
</Flexbox>
|
||||
{showBadge && (
|
||||
@@ -150,7 +134,7 @@ const DataStatistics = memo<Omit<FlexboxProps, 'children'>>(({ style, ...rest })
|
||||
return (
|
||||
<Flexbox className={styles.card} flex={1} gap={2} key={item.key}>
|
||||
<Flexbox horizontal>
|
||||
<div className={styles.count}>{formatNumber(item.count)}</div>
|
||||
<div className={styles.count}>{formatShortenNumber(item.count)}</div>
|
||||
</Flexbox>
|
||||
<div className={styles.title}>{item.title}</div>
|
||||
</Flexbox>
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
formatTokenNumber,
|
||||
} from './format';
|
||||
|
||||
// 保留你已经编写的测试用例
|
||||
describe('format', () => {
|
||||
describe('formatSize', () => {
|
||||
it('should format bytes to KB correctly', () => {
|
||||
@@ -128,10 +127,13 @@ describe('format', () => {
|
||||
expect(formatShortenNumber(9999)).toBe('9,999');
|
||||
});
|
||||
|
||||
it('should format numbers between 10,000 and 9,999,999 correctly', () => {
|
||||
it('should format numbers between 10,000 and 999,999 correctly', () => {
|
||||
expect(formatShortenNumber(10000)).toBe('10.0K');
|
||||
expect(formatShortenNumber(123456)).toBe('123.5K');
|
||||
expect(formatShortenNumber(9999999)).toBe('10000.0K');
|
||||
expect(formatShortenNumber(998000)).toBe('998.0K');
|
||||
expect(formatShortenNumber(999999)).toBe('1000.0K');
|
||||
expect(formatShortenNumber(1000000)).toBe('1.0M');
|
||||
expect(formatShortenNumber(9999999)).toBe('10.0M');
|
||||
});
|
||||
|
||||
it('should format numbers 10,000,000 and above correctly', () => {
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ export const formatShortenNumber = (num: any) => {
|
||||
const formattedWithComma = new Intl.NumberFormat('en-US').format(num);
|
||||
|
||||
// 格式化为 K 或 M
|
||||
if (num >= 10_000_000) {
|
||||
if (num >= 1_000_000) {
|
||||
return (num / 1_000_000).toFixed(1) + 'M';
|
||||
} else if (num >= 10_000) {
|
||||
return (num / 1000).toFixed(1) + 'K';
|
||||
|
||||
Reference in New Issue
Block a user