FxStatistic 统计组件
展示统计数值与倒计时。含 FxStatistic(统计数字)与 FxCountdown(倒计时)两个组件。不依赖任何 UI 框架,样式走 @fx/styles token。
FxStatistic / FxCountdown 属于 @fx/components。
基础用法
突出一个或一组数字(统计值、金额、排名等),可在数字前后与标题处加图标、单位等元素;总交易数一列用 requestAnimationFrame 做了线性过渡(文档站无 @vueuse/core,用原生 rAF 实现)。
倒计时
FxCountdown 是薄包装 FxStatistic 的倒计时组件,到达目标时间触发 finish,每帧触发 change。value 设置目标时间(时间戳毫秒或 Dayjs),默认 format="HH:mm:ss";format 支持 Y / M / D / H / m / s / S token,[ ] 包裹的内容视为转义文本不参与替换。
TIP
格式范围建议在天(DD)及以上。月 / 年按近似值(30 天 / 365 天)计算,跨度大时会有精度偏差。
卡片用法
卡片式统计展示,可自由组合:标题加 tooltip 提示、底部加环比与箭头图标。
Statistic API
Attributes
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| value | 数值内容 | number | Dayjs | 0 |
| title | 标题 | string | — |
| prefix | 前缀(与 prefix slot 互斥) | string | — |
| suffix | 后缀(与 suffix slot 互斥) | string | — |
| decimal-separator | 小数点分隔符 | string | '.' |
| group-separator | 千分位分隔符 | string | ',' |
| precision | 数值精度(小数位数) | number | 0 |
| formatter | 自定义数值呈现(优先级最高) | (...args: any[]) => string | number | — |
| value-style | 数值样式 | StyleValue | — |
Slots
| 名称 | 说明 |
|---|---|
| title | 自定义标题 |
| prefix | 自定义前缀 |
| suffix | 自定义后缀 |
Exposes
| 名称 | 说明 | 类型 |
|---|---|---|
| displayValue | 当前显示值 | ComputedRef<string | number> |
Countdown API
Attributes
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| value | 目标时间(时间戳毫秒或 Dayjs) | number | Dayjs | 0 |
| format | 格式化(Y/M/D/H/m/s/S,转义用 [ ]) | string | 'HH:mm:ss' |
| prefix | 前缀 | string | — |
| suffix | 后缀 | string | — |
| title | 标题 | string | — |
| value-style | 数值样式 | StyleValue | — |
Events
| 名称 | 说明 | 类型 |
|---|---|---|
| change | 每帧触发,参数为剩余毫秒 | (value: number) => void |
| finish | 倒计时归零时触发 | () => void |
Slots
| 名称 | 说明(透传 FxStatistic) |
|---|---|
| title | 自定义标题 |
| prefix | 自定义前缀 |
| suffix | 自定义后缀 |
Exposes
| 名称 | 说明 | 类型 |
|---|---|---|
| displayValue | 当前显示值(格式化字符串) | ComputedRef<string> |
实现说明
- Statistic 数值规则:
formatter优先 → 非数字或NaN原样返回 → 数字按precision补零/截断、groupSeparator三位分隔、decimalSeparator拼接小数。 - Countdown 薄包装:内部渲染
<FxStatistic>,formatter固定为按format渲染剩余毫秒;驱动方式用浏览器原生requestAnimationFrame,每帧计算timestamp - Date.now(),到 0 停止并触发finish。 - format token:
Y/M为近似值(月按 30 天、年按 365 天);S为毫秒,SSS显示三位毫秒。 - 样式 token:标题
--color-text-secondary+--fw-normal+ 14px;数值--color-text-primary+--fw-normal+ 20px,prefix/suffix 各 4px 间距,统一走@fx/stylestoken 不引用第三方框架变量。
