z-timeline.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="z-timeline flex-n">
  3. <view class="day_info" v-if="showDay" :style="{'margin-top':daytop+'px',color:datecolor}">
  4. <view class="day" v-if="date">{{date.dd||''}}</view>
  5. <view class="xingqi" v-if="date">周{{date.xx||''}}</view>
  6. </view>
  7. <view class="z-timeline-line" :style="{height:height+'px',top:top+'px',left:left+'px'}"></view>
  8. <view id='timeline' class="flex-1">
  9. <slot></slot>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'z-timeline',
  16. props: {
  17. align: {
  18. type: String,
  19. default: 'center'
  20. },
  21. showDay:Boolean,
  22. date:Object,
  23. datecolor:{
  24. type: String,
  25. default: '#0075FF'
  26. }
  27. },
  28. data() {
  29. return {
  30. height: 0,
  31. top: 0,
  32. left: 0,
  33. daytop: 0,
  34. }
  35. },
  36. mounted() {
  37. uni.$emit('timeline_align', this.align);
  38. var dayheight = 0;
  39. const query = uni.createSelectorQuery().in(this);
  40. if(this.showDay)
  41. query.select('.day_info .day').boundingClientRect(data => {
  42. this.left = data.width;
  43. dayheight = data.height;
  44. })
  45. query.select('.z-time-item .dot').boundingClientRect(data => {
  46. this.left += data.width;
  47. })
  48. query.selectAll('.z-time-item .content').boundingClientRect(data => {
  49. var height = 0;
  50. if (data.length > 0)
  51. if (this.align == 'center') {
  52. this.top = data[0].height / 2;
  53. this.daytop = this.top - dayheight;
  54. } else {
  55. this.top = 0;
  56. }
  57. if (data.length > 1) {
  58. for (var i = 0, len = data.length; i < len; i++) {
  59. height += data[i].height;
  60. }
  61. if (this.align == 'center') {
  62. this.height = height - (data[0].height + data[data.length - 1].height) / 2;
  63. } else {
  64. this.height = height - data[data.length - 1].height;
  65. }
  66. }
  67. }).exec();
  68. console.log(dayheight,this.height)
  69. },
  70. }
  71. </script>
  72. <style scoped lang="scss">
  73. .day_info {
  74. text-align: center;
  75. font-size: 18rpx;
  76. height: fit-content;
  77. }
  78. .z-timeline {
  79. position: relative;
  80. .z-timeline-line {
  81. position: absolute;
  82. border-left: 1px solid #777777;
  83. z-index: 1;
  84. }
  85. }
  86. </style>