跳转到内容

Statistic 统计数值 ​

带标签的关键数字,可以配前后缀。

用法 ​

标签在上、数值在下;数值由使用者格式化后放入,组件不做千分位也不做换算

本月新增用户12,480

组件结构 ​

加粗的是必需部件。

data-scope="statistic":root · label · value · prefix · suffix · trend

示例 ​

前后缀 ​

prefix 与 suffix 和数值排在同一行、按基线对齐,比数值小一档

账户余额¥3,240.00
转化率68.4%
较上月12.5%

尺寸 ​

size 改变标签、数值与前后缀的字号,不传 size 即默认档

小86.7%
默认86.7%
大86.7%

颜色 ​

tone 决定数值与前后缀使用哪族颜色,标签始终保持弱前景

brand24.8%
neutral24.8%
success24.8%
warning24.8%
danger24.8%
info24.8%

等宽数字 ​

数值使用等宽数字排版,反复更换数值时字宽不变,后面的单位不会左右移动

今日成交额1,111.11元

涨跌 ​

trend 写为 trend 部件的 data-direction,箭头由皮肤绘制;与 tone 正交:下跌也可以是正向语气

本月新增用户12,480人同比 12.4%
订单退货率1.8%同比 0.6%
平均响应时长240ms与上周持平

设计指引 ​

何时使用 ​

  • 仪表盘、概览页上的核心指标。

何时不用 ​

  • 多个指标需要按维度对照时,使用表格。
  • 表达完成比例时,使用进度条。

特性 ​

  • 标签、值、前缀、后缀各占一段。
  • 数字使用等宽字形,位数变化时不会左右晃动。
  • trend 给出涨跌方向,箭头由皮肤绘制;它与 tone 正交,下跌也可以是正向语气。

组合 ​

最佳实践 ​

  • 单位写进后缀而不是混入数字,数字才能对齐。
  • 给出对比基准(同比、环比),单独一个数字无法判断好坏。

反模式 ​

  • 一屏内十几个同等大小的指标,没有重点。
  • 显示精确到分的金额却不提供货币符号。

API 参考 ​

产物 ​

层值
自定义元素<xh-statistic>
Vue 组件XhStatisticLabel XhStatisticPrefix XhStatisticRoot XhStatisticSuffix XhStatisticTrend XhStatisticValue
状态机无,connect 直接由 props 算属性
皮肤@xihan-ui/styles/statistic.css

Props ​

属性类型必填说明
sizeSize尺寸:sm / md / lg,只写为 root 的 data-size。
toneTone语气:brand / neutral / success / warning / danger / info,只写为 root 的 data-tone。
trendStatisticTrend涨跌:up / down / flat,写为 trend 部件的 data-direction,皮肤据此绘制兜底箭头。 与 tone 正交,方向与颜色互不联动:下跌也可以是正面信息(差错率、退货率)。

connect API ​

getXxxProps() 返回对应部件的宿主属性。

成员类型说明
trendStatisticTrend当前涨跌方向;未提供时为 undefined。
getRootProps() => T['element']
getLabelProps() => T['element']
getValueProps() => T['element']
getPrefixProps() => T['element']
getSuffixProps() => T['element']
getTrendProps() => T['element']

无障碍 ​

键盘 ​

规格出处:W3C APG

无键盘交互(不接收焦点,或焦点行为完全由原生元素提供)。

样式参考 ​

皮肤 ​

@xihan-ui/styles/statistic.css 使用 [data-scope="statistic"][data-part="root"] 部件选择器,位于 xihan.components 层。覆盖样式使用 xihan.overrides。

数据属性 ​

由 connect 生成;条件不成立时不输出无值属性。

部件属性值
rootdata-sizeprops.size
rootdata-toneprops.tone
trenddata-directionprops.trend

CSS 变量 ​

本组件公开覆盖槽由独立皮肤的实际消费位生成;默认来源、作用部件和状态均与 CSS 同源。

变量部件CSS 属性状态默认来源说明
--xh-statistic-affix-fgprefix
suffix
colordefault--xh-_tone-fgstatistic 的 prefix、suffix 部件 color 覆盖槽。
--xh-statistic-affix-font-sizeprefix
suffix
font-sizedefault--xh-_statistic-affix-sizestatistic 的 prefix、suffix 部件 font-size 覆盖槽。
--xh-statistic-fgrootcolordefault--xh-fg-defaultstatistic 的 root 部件 color 覆盖槽。
--xh-statistic-gaprootcolumn-gapdefault--xh-space-0statistic 的 root 部件 column-gap 覆盖槽。
--xh-statistic-icon-sizeroot--xh-icon-sizedefault--xh-_statistic-icon-sizestatistic 的 root 部件 --xh-icon-size 覆盖槽。
--xh-statistic-label-fglabelcolordefault--xh-fg-mutedstatistic 的 label 部件 color 覆盖槽。
--xh-statistic-label-font-sizelabelfont-sizedefault--xh-_statistic-label-sizestatistic 的 label 部件 font-size 覆盖槽。
--xh-statistic-row-gaprootrow-gapdefault--xh-_statistic-row-gapstatistic 的 root 部件 row-gap 覆盖槽。
--xh-statistic-trend-fgtrendcolordefault--xh-_tone-fgstatistic 的 trend 部件 color 覆盖槽。
--xh-statistic-trend-font-sizetrendfont-sizedefault--xh-_statistic-affix-sizestatistic 的 trend 部件 font-size 覆盖槽。
--xh-statistic-trend-gaptrendgapdefault--xh-space-0_5statistic 的 trend 部件 gap 覆盖槽。
--xh-statistic-trend-offsettrendmargin-inline-startdefault--xh-space-2statistic 的 trend 部件 margin-inline-start 覆盖槽。
--xh-statistic-value-fgvaluecolordefault--xh-_tone-fgstatistic 的 value 部件 color 覆盖槽。
--xh-statistic-value-font-sizevaluefont-sizedefault--xh-_statistic-value-sizestatistic 的 value 部件 font-size 覆盖槽。

动效 ​

本组件皮肤不含过渡与关键帧,也没有脚本驱动的动效:状态一变,外观立即到位。

RTL ​

皮肤用逻辑属性排布(inline-start 一族),dir="rtl" 下自动镜像。

Released under The MIT License