Commit 3dff7011a56adb449a345a1ed6ff3f733186280c
Merge branch 'perf/dashboard-statistics' into 'main_dev'
fix: 优化首页数据点过大 See merge request yunteng/thingskit-front!680
Showing
2 changed files
with
17 additions
and
2 deletions
| ... | ... | @@ -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> | ... | ... |