Commit 3b42dc8105321bb2d98d7fef4a08fea2867c43e0

Authored by ww
1 parent 2087a712

fix: 优化首页数据点过大

... ... @@ -120,6 +120,7 @@
120 120 totals: RecordType[];
121 121 tooltips: RecordType[];
122 122 todayTotals: RecordType[];
  123 + withUnit?: boolean;
123 124 }
124 125
125 126 defineProps<{
... ... @@ -190,6 +191,7 @@
190 191
191 192 const messageTotal: StatisticalItemType = {
192 193 images: msgPicture,
  194 + withUnit: true,
193 195 totals: [
194 196 { label: '消息数', value: messageInfo?.messageCount },
195 197 { label: '消息点数', value: messageInfo?.dataPointsCount },
... ...
... ... @@ -8,13 +8,14 @@
8 8 label: string;
9 9 }
10 10
11   - withDefaults(
  11 + const props = withDefaults(
12 12 defineProps<{
13 13 value?: {
14 14 images: string;
15 15 totals: RecordType[];
16 16 tooltips: RecordType[];
17 17 todayTotals: RecordType[];
  18 + withUnit?: boolean;
18 19 };
19 20 }>(),
20 21 {
... ... @@ -26,6 +27,17 @@
26 27 }),
27 28 }
28 29 );
  30 +
  31 + const getThresholdValue = (value: number) => {
  32 + const record = { value, unit: null };
  33 +
  34 + if (!props.value?.withUnit) return record;
  35 +
  36 + if (value > 10 ** 6) return { unit: 'M', value: value / 10 ** 6 };
  37 + if (value > 10 ** 3) return { unit: 'K', value: value / 10 ** 4 };
  38 +
  39 + return record;
  40 + };
29 41 </script>
30 42
31 43 <template>
... ... @@ -41,7 +53,8 @@
41 53 :style="{ width: `${100 / value.totals.length}%` }"
42 54 >
43 55 <div class="font-bold text-2xl">
44   - <CountTo :end-val="item.value ?? 0" class="break-all" />
  56 + <CountTo :end-val="getThresholdValue(item.value).value ?? 0" class="break-all" />
  57 + <span>{{ getThresholdValue(item.value).unit || '' }}</span>
45 58 </div>
46 59 <div class="text-gray-600">{{ item.label }}</div>
47 60 </div>
... ...