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([