1.0.2 • Published 2 months ago

@tanzhenxing/zx-timeline-item v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

zx-timeline-item 时间轴节点组件

介绍

zx-timeline-item 是时间轴的节点组件,需要配合 zx-timeline 容器组件一起使用。支持自定义节点颜色、尺寸、图标、时间戳位置等,适用于展示时间流信息,如时间进度、操作记录等。

引入方式

<script setup>
import ZxTimeline from '@/components/zx-timeline/zx-timeline.vue';
import ZxTimelineItem from '@/components/zx-timeline-item/zx-timeline-item.vue';
</script>

<template>
  <ZxTimeline>
    <ZxTimelineItem timestamp="2023-01-01">事件内容</ZxTimelineItem>
  </ZxTimeline>
</template>

基本用法

<template>
  <zx-timeline>
    <zx-timeline-item
      v-for="(item, idx) in list"
      :key="idx"
      :timestamp="item.timestamp"
    >
      {{ item.content }}
    </zx-timeline-item>
  </zx-timeline>
</template>

<script setup>
import ZxTimeline from '@/components/zx-timeline/zx-timeline.vue';
import ZxTimelineItem from '@/components/zx-timeline-item/zx-timeline-item.vue';

const list = [
  { content: '事件一', timestamp: '2023-01-01' },
  { content: '事件二', timestamp: '2023-01-02' },
  { content: '事件三', timestamp: '2023-01-03' },
];
</script>

属性说明

属性名说明类型默认值
timestamp时间戳string''
hideTimestamp隐藏时间戳booleanfalse
center垂直居中booleanfalse
placement时间戳位置string'bottom'可选值:'top'/'bottom'
type节点类型string''可选值:'primary'/'success'/'warning'/'danger'/'info'
color节点颜色string''自定义颜色值,如 '#0bbd87'
size节点尺寸string'normal'可选值:'normal'/'large'
icon自定义图标string''传入 icon class 或 unicode
hollow是否空心点booleanfalse

插槽

  • 默认插槽:节点内容
  • dot:自定义节点图标内容

进阶用法

自定义节点样式

<zx-timeline>
  <zx-timeline-item
    type="primary"
    size="large"
    icon="iconfont icon-star"
    timestamp="2023-01-01 10:00"
  >自定义图标</zx-timeline-item>
  <zx-timeline-item color="#0bbd87" timestamp="2023-01-02">自定义颜色</zx-timeline-item>
  <zx-timeline-item size="large" timestamp="2023-01-03">自定义尺寸</zx-timeline-item>
  <zx-timeline-item hollow type="primary" timestamp="2023-01-04">空心节点</zx-timeline-item>
  <zx-timeline-item timestamp="2023-01-05">默认节点</zx-timeline-item>
</zx-timeline>

自定义时间戳位置

<zx-timeline>
  <zx-timeline-item timestamp="2023/01/01" placement="top">
    <view>内容在下方,时间戳在上方</view>
  </zx-timeline-item>
</zx-timeline>

使用 dot 插槽自定义节点

<zx-timeline>
  <zx-timeline-item timestamp="2023-01-01">
    <template #dot>
      <image src="/static/star.png" style="width:24rpx;height:24rpx;" />
    </template>
    自定义图片节点
  </zx-timeline-item>
</zx-timeline>

注意事项

  • 组件样式采用 rpx 单位,适配多端。
  • 图标可用 iconfont 或自定义图片。
  • 必须在 zx-timeline 容器内使用。
  • 兼容 uni-app H5、小程序、App 平台。