u-time-line-item.vue 2.1 KB

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