su-timeline-item.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view class="u-time-axis-item">
  3. <slot name="content" />
  4. <view class="u-time-axis-node" :style="[nodeStyle]">
  5. <slot name="node"><view class="u-dot"></view></slot>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. /**
  11. * timeLineItem 时间轴Item
  12. * @description 时间轴组件一般用于物流信息展示,各种跟时间相关的记录等场景。(搭配u-time-line使用)
  13. * @tutorial https://www.uviewui.com/components/timeLine.html
  14. * @property {String} bg-color 左边节点的背景颜色,一般通过slot内容自定义背景颜色即可(默认#ffffff)
  15. * @property {String Number} node-top 节点左边图标绝对定位的top值,单位rpx
  16. * @example <u-time-line-item node-top="2">...</u-time-line-item>
  17. */
  18. export default {
  19. name: 'u-time-line-item',
  20. props: {
  21. // 节点的背景颜色
  22. bgColor: {
  23. type: String,
  24. default: '#ffffff',
  25. },
  26. // 节点左边图标绝对定位的top值
  27. nodeTop: {
  28. type: [String, Number],
  29. default: '',
  30. },
  31. },
  32. data() {
  33. return {};
  34. },
  35. computed: {
  36. nodeStyle() {
  37. let style = {
  38. backgroundColor: this.bgColor,
  39. };
  40. if (this.nodeTop != '') style.top = this.nodeTop + 'rpx';
  41. return style;
  42. },
  43. },
  44. };
  45. </script>
  46. <style lang="scss" scoped>
  47. .u-time-axis-item {
  48. display: flex;
  49. flex-direction: column;
  50. width: 100%;
  51. position: relative;
  52. margin-bottom: 32rpx;
  53. }
  54. .u-time-axis-node {
  55. position: absolute;
  56. top: 12rpx;
  57. left: -40rpx;
  58. transform-origin: 0;
  59. transform: translateX(-50%);
  60. display: flex;
  61. align-items: center;
  62. justify-content: center;
  63. z-index: 1;
  64. font-size: 24rpx;
  65. }
  66. .u-dot {
  67. height: 16rpx;
  68. width: 16rpx;
  69. border-radius: 100rpx;
  70. background: #ddd;
  71. }
  72. </style>