From 31ffedbcf2fd7085e95284f81999e2abf51bfece Mon Sep 17 00:00:00 2001 From: hajimi Date: Sun, 2 Aug 2026 20:32:57 +0800 Subject: [PATCH] refactor: improve community count formatting --- .../packages_community/components/post-card.vue | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/uniapp/src/packages_community/components/post-card.vue b/uniapp/src/packages_community/components/post-card.vue index 50a7090..f26f7ea 100644 --- a/uniapp/src/packages_community/components/post-card.vue +++ b/uniapp/src/packages_community/components/post-card.vue @@ -174,9 +174,18 @@ const formatTime = (value: any) => { } const formatCount = (value: any) => { - const count = Number(value || 0) - if (count >= 10000) return `${(count / 10000).toFixed(1)}万` - if (count >= 1000) return `${(count / 1000).toFixed(1)}k` + const numericValue = Number(value) + if (!Number.isFinite(numericValue) || numericValue <= 0) return '0' + + const count = Math.floor(numericValue) + const compact = (divisor: number, unit: string) => { + const formatted = (count / divisor).toFixed(1).replace(/\.0$/, '') + return `${formatted}${unit}` + } + + if (count >= 100000000) return compact(100000000, '亿') + if (count >= 10000) return compact(10000, '万') + if (count >= 1000) return compact(1000, 'k') return String(count) }