1.0.2 • Published 1 month ago

@tanzhenxing/zx-statistic v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

zx-statistic 统计数值组件

显示统计数据和倒计时的组件。

基础用法

<template>
  <zx-statistic title="日活跃用户" :value="268500" />
  
  <zx-statistic :value="138">
    <template #title>
      <view style="display: inline-flex; align-items: center">
        男女比例
      </view>
    </template>
    <template #suffix>/100</template>
  </zx-statistic>
</template>

倒计时用法

<template>
  <zx-statistic title="开始抢购" :value="value" is-countdown />
  
  <zx-statistic
    title="剩余VIP时间"
    format="HH:mm:ss"
    :value="value1"
    is-countdown
  />
  
  <zx-statistic format="DD [days] HH:mm:ss" :value="value2" is-countdown>
    <template #title>
      <view style="display: inline-flex; align-items: center">
        距离下个月还有
      </view>
    </template>
  </zx-statistic>
</template>

<script setup>
import { ref } from 'vue';

// 当前时间加上7小时
const value = ref(Date.now() + 1000 * 60 * 60 * 7);
// 当前时间加上2天
const value1 = ref(Date.now() + 1000 * 60 * 60 * 24 * 2);
// 下个月的第一天
const value2 = ref(new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1).getTime());
</script>

统计卡片样式

<template>
  <view class="statistic-card">
    <zx-statistic :value="98500" title="日活跃用户" />
    <view class="statistic-footer">
      <view class="footer-item">
        <text>较昨日</text>
        <text class="green">
          24% ↑
        </text>
      </view>
    </view>
  </view>
</template>

<style>
.statistic-card {
  height: 100%;
  padding: 20px;
  border-radius: 4px;
  background-color: #fff;
}

.statistic-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: #606266;
  margin-top: 16px;
}

.statistic-footer .footer-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.green {
  color: #67C23A;
}
</style>

zx-statistic 属性

属性说明类型默认值
value数字内容或目标时间Number/Date/String/Object0
decimal-separator设置小数点符号String.
formatter自定义数字格式化Function
group-separator设置千分位标识符String,
precision数字精度Number0
prefix设置数字的前缀String
suffix设置数字的后缀String
title数字标题String
value-style数字样式String/Object
is-countdown是否为倒计时模式Booleanfalse
format倒计时格式化StringHH:mm:ss

zx-statistic 插槽

插槽名说明
prefix数字区之前
suffix数字区之后
title数字标题

zx-statistic 事件(倒计时模式)

事件名说明回调参数
change时间差改变事件剩余时间(毫秒)
finish倒计时结束事件