移动端H5 - 手撸一个时间线 timeline

最近做移动端开发,用的vant2组件库,有个页面有个类似时间线组件的形式,但是瞄了一下vant2里面没有类似的组件,算了,自己手撸吧,也懒得找其他的插件,找到了也懒得改,阿西吧……

先看下 ‘结果’
在这里插入图片描述

屁话不多说,丢代码:

<template>
  <!-- 就诊记录 模块 -->
  <div class="visit-records">
    <div v-for="(item) in visitRecords" :key="item.id" class="record-item">
      <div :class="{'top-line': true, 'type1': item.type === 1, 'type2': item.type === 2, 'type3': item.type === 3}">
        <div
          :class="{'tag': true}"
        >
          <!-- 1 门诊; 2 住院; 3 急诊 -->
          {{ ['门诊', '住院', '急诊'][item.type - 1] }}
        </div>
        <div class="date">{{ item.date }}</div>
      </div>
      <div class="card" @click="toVisitRecords(item)">
        <div class="one-line">
          <div class="doctor">
            <span>医生:</span>
            <span>{{ item.doctor }}</span>
          </div>
          <div class="dept"> {{ item.department }} </div>
        </div>
        <div class="two-line">
          <span>诊断:</span>
          <span>{{ item.diagnose }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { testVisitRecordsData } from './testData'
export default {
  name: 'VisitRecords',
  components: {},
  props: {},
  data() {
    return {
      visitRecords: []
    }
  },
  computed: {},
  watch: {},
  created() {
    this.visitRecords = JSON.parse(JSON.stringify(testVisitRecordsData))
  },
  mounted() {},
  methods: {
    toVisitRecords(item) {
      this.$toast(item.doctor + ':别碰我!')
    }
  }
}
</script>
<style lang='less' scoped>
.visit-records {
  padding-left: 32px;
  padding-right: 32px;
  padding-top: 28px;
  height: calc(100% - 108px);
  margin-bottom: 20px;
  overflow-y: auto;
}
.record-item {
  position: relative;
  &:not(:last-child):after {
    content: '';
    position: absolute;
    left: 10px;
    top: 30px;
    height: calc(100% + 18px);
    border-left: 1px solid #ccc;
  }
  .top-line {
    position: relative;
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
    height: 40px;
    padding-left: 40px;
    font-size: 24px;
    &::after {
      content: '';
      position: absolute;
      width: 20px;
      height: 20px;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      border-radius: 50%;
      background: #3FA40E;
    }
    .tag {
      width: 80px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      border-radius: 8px;
      color: #fff;
      background: #3FA40E;
    }
    .date {
      height: 40px;
      line-height: 40px;
      margin-left: 20px;
      color: #424E67;
    }
  }
  .type2 {
    .tag {
      background: #3B8CFF;
    }
    &::after {
      background: #3B8CFF;
    }
  }
  .type3 {
    .tag {
      background: #FF9A02;
    }
    &::after {
      background: #FF9A02;
    }
  }

  .card {
    padding: 24px 40px;
    border-radius: 8px;
    background-color: #fff;
    color: #424E67;
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 28px;
    margin-left: 40px;
    margin-top: 20px;
    .one-line {
      display: flex;
      flex-wrap: nowrap;
      justify-content: space-between;
      margin-bottom: 20px;
    }
    .doctor, .two-line {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
  }
</style>

上面引入的测试数据: testVisitRecordsData 如下,


export const testVisitRecordsData = [
  {
    id: 'tyinjk',
    type: 3, // 1 门诊; 2 住院; 3 急诊
    date: '2022-02-07 10:28',
    doctor: '张三',
    department: '脑科',
    diagnose: '脑内出血'
  },
  {
    id: 'fcyvghubinjl',
    type: 2, // 1 门诊; 2 住院; 3 急诊
    date: '2022-01-20 12:30',
    doctor: '李四',
    department: '内科',
    diagnose: '肠胃炎症'
  },
  {
    id: 'trcyuvbino',
    type: 3, // 1 门诊; 2 住院; 3 急诊
    date: '2021-12-29 14:30',
    doctor: '王五',
    department: '骨科',
    diagnose: '膝关节骨折'
  },
  {
    id: 'zsrdxtfcyguhijkl',
    type: 1, // 1 门诊; 2 住院; 3 急诊
    date: '2021-12-19 15:40',
    doctor: '赵六',
    department: '眼科',
    diagnose: '间歇性失明'
  },
  {
    id: 'tysinjk',
    type: 3, // 1 门诊; 2 住院; 3 急诊
    date: '2022-02-07 10:28',
    doctor: '张三',
    department: '脑科',
    diagnose: '脑内出血'
  },
  {
    id: 'fcyvdghubinjl',
    type: 2, // 1 门诊; 2 住院; 3 急诊
    date: '2022-01-20 12:30',
    doctor: '李四',
    department: '内科',
    diagnose: '肠胃炎症'
  },
  {
    id: 'trcyucvbino',
    type: 3, // 1 门诊; 2 住院; 3 急诊
    date: '2021-12-29 14:30',
    doctor: '王五',
    department: '骨科',
    diagnose: '膝关节骨折'
  },
  {
    id: 'zsrdxtrfcyguhijkl',
    type: 1, // 1 门诊; 2 住院; 3 急诊
    date: '2021-12-19 15:40',
    doctor: '赵六',
    department: '眼科',
    diagnose: '间歇性失明'
  }
]


好的,以下是使用Element Plus实现时间线左右布局且居中的示例代码: ```html <template> <div class="timeline-container"> <el-timeline align="alternate"> <el-timeline-item timestamp="2021-10-01 12:00:00" placement="top" style="margin-right: auto;" > <h4>Event 1</h4> <p>Description of Event 1.</p> </el-timeline-item> <el-timeline-item timestamp="2021-10-02 12:00:00" placement="bottom" style="margin-left: auto;" > <h4>Event 2</h4> <p>Description of Event 2.</p> </el-timeline-item> <el-timeline-item timestamp="2021-10-03 12:00:00" placement="top" style="margin-right: auto;" > <h4>Event 3</h4> <p>Description of Event 3.</p> </el-timeline-item> <el-timeline-item timestamp="2021-10-04 12:00:00" placement="bottom" style="margin-left: auto;" > <h4>Event 4</h4> <p>Description of Event 4.</p> </el-timeline-item> </el-timeline> </div> </template> <style> .timeline-container { display: flex; justify-content: center; align-items: center; height: 100vh; } </style> ``` 解释一下上述代码: 1. `el-timeline` 是 Element Plus 中的时间线组件,`align="alternate"` 属性表示左右布局,`el-timeline-item` 表示一个时间线项。 2. `timestamp` 属性表示时间戳,`placement` 属性表示时间线项在时间线上的位置,`style` 属性中的 `margin-right: auto;` 和 `margin-left: auto;` 分别表示使得时间线项居中对齐。 3. `timeline-container` 类是一个容器,通过 `display: flex; justify-content: center; align-items: center;` 属性使得时间线居中显示。 希望这个答案能够帮到你!
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

#老程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值