diff --git a/src/@core/utils/formatters.ts b/src/@core/utils/formatters.ts index 2700663a..05419a61 100644 --- a/src/@core/utils/formatters.ts +++ b/src/@core/utils/formatters.ts @@ -23,6 +23,13 @@ export function kFormatter(num: number) { : Math.abs(num).toFixed(0).replace(regex, ',') } +// 格式化下载量显示,超过1000显示为x.xk格式 +export function formatDownloadCount(num: number): string { + if (!num || num < 1000) return num?.toLocaleString() || '0' + + return `${(num / 1000).toFixed(1)}k` +} + /** * Format and return date in Humanize format * Intl docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format diff --git a/src/components/cards/PluginAppCard.vue b/src/components/cards/PluginAppCard.vue index 32828318..37789559 100644 --- a/src/components/cards/PluginAppCard.vue +++ b/src/components/cards/PluginAppCard.vue @@ -6,6 +6,7 @@ import type { Plugin } from '@/api/types' import { getLogoUrl } from '@/utils/imageUtils' import { getDominantColor } from '@/@core/utils/image' import { isNullOrEmptyObject } from '@/@core/utils' +import { formatDownloadCount } from '@/@core/utils/formatters' import ProgressDialog from '@/components/dialog/ProgressDialog.vue' import { useI18n } from 'vue-i18n' @@ -244,7 +245,7 @@ const dropdownItems = ref([
- {{ props.count?.toLocaleString() }} + {{ formatDownloadCount(props.count) }}
@@ -327,7 +328,7 @@ const dropdownItems = ref([ }}
{{ - t('plugin.totalDownloads', { count: props.count?.toLocaleString() }) + t('plugin.totalDownloads', { count: formatDownloadCount(props.count) }) }}
diff --git a/src/components/cards/PluginCard.vue b/src/components/cards/PluginCard.vue index b080b933..12524d9c 100644 --- a/src/components/cards/PluginCard.vue +++ b/src/components/cards/PluginCard.vue @@ -6,6 +6,7 @@ import type { Plugin } from '@/api/types' import { isNullOrEmptyObject } from '@core/utils' import { getLogoUrl } from '@/utils/imageUtils' import { getDominantColor } from '@/@core/utils/image' +import { formatDownloadCount } from '@/@core/utils/formatters' import VersionHistory from '@/components/misc/VersionHistory.vue' import ProgressDialog from '../dialog/ProgressDialog.vue' import PluginConfigDialog from '../dialog/PluginConfigDialog.vue' @@ -492,7 +493,7 @@ watch( - {{ props.count?.toLocaleString() }} + {{ formatDownloadCount(props.count) }}