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