|
@@ -1,7 +1,9 @@
|
|
<template>
|
|
<template>
|
|
<div class="counter-wrapper">
|
|
<div class="counter-wrapper">
|
|
<div class="count">
|
|
<div class="count">
|
|
- <CountUp :endVal="count" :options="countUpOptions" />
|
|
|
|
|
|
+ <el-tooltip effect="light" :content="count + ''" placement="top">
|
|
|
|
+ <CountUp v-if="showCountUp" ref="countUpRef" :endVal="info.count" :options="countUpOptions" />
|
|
|
|
+ </el-tooltip>
|
|
<div class="trend">
|
|
<div class="trend">
|
|
<img v-if="[TREND_CONFIG.UP, TREND_CONFIG.DOWN].includes(trend)" :src="require(`../../../assets/images/dashboard/t-${trend}.png`)" alt="" />
|
|
<img v-if="[TREND_CONFIG.UP, TREND_CONFIG.DOWN].includes(trend)" :src="require(`../../../assets/images/dashboard/t-${trend}.png`)" alt="" />
|
|
<span v-if="trend === TREND_CONFIG.STABILIZATION" style="color: #d8d8d8; font-weight: normal">--</span>
|
|
<span v-if="trend === TREND_CONFIG.STABILIZATION" style="color: #d8d8d8; font-weight: normal">--</span>
|
|
@@ -14,13 +16,13 @@
|
|
<script>
|
|
<script>
|
|
import CountUp from 'vue-countup-v2'
|
|
import CountUp from 'vue-countup-v2'
|
|
import { TREND } from '../config'
|
|
import { TREND } from '../config'
|
|
|
|
+import { formatBigNumber } from '../utils'
|
|
|
|
|
|
export default {
|
|
export default {
|
|
props: {
|
|
props: {
|
|
count: { type: Number, required: true },
|
|
count: { type: Number, required: true },
|
|
tip: { type: String, required: true },
|
|
tip: { type: String, required: true },
|
|
- trend: { type: String, default: '' }, // up/down/stabilization
|
|
|
|
- decimalPlaces: { type: Number, default: 0 } // 支持几位小数
|
|
|
|
|
|
+ trend: { type: String, default: '' } // up/down/stabilization
|
|
},
|
|
},
|
|
|
|
|
|
components: { CountUp },
|
|
components: { CountUp },
|
|
@@ -28,16 +30,36 @@ export default {
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
TREND_CONFIG: Object.freeze(TREND),
|
|
TREND_CONFIG: Object.freeze(TREND),
|
|
- countUpOptions: {
|
|
|
|
- useEasing: true,
|
|
|
|
- useGrouping: true,
|
|
|
|
- separator: ',',
|
|
|
|
- decimal: '.',
|
|
|
|
- prefix: '',
|
|
|
|
- suffix: '',
|
|
|
|
- decimalPlaces: this.decimalPlaces
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ info: { count: 0, unit: '' },
|
|
|
|
+ countUpOptions: null,
|
|
|
|
+ showCountUp: false
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ watch: {
|
|
|
|
+ count: {
|
|
|
|
+ handler(newCount) {
|
|
|
|
+ if (newCount > 0) {
|
|
|
|
+ const res = formatBigNumber(newCount)
|
|
|
|
+ this.info.count = res.count * 1
|
|
|
|
+
|
|
|
|
+ this.countUpOptions = {
|
|
|
|
+ useEasing: true,
|
|
|
|
+ useGrouping: true,
|
|
|
|
+ separator: ',',
|
|
|
|
+ decimal: '.',
|
|
|
|
+ prefix: '',
|
|
|
|
+ suffix: res.unit || '',
|
|
|
|
+ decimalPlaces: newCount * 1 > 10000 ? 2 : 0
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.showCountUp = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ immediate: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|