index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. relations: {
  5. '../timeline-item/index': {
  6. type: 'child',
  7. observer() {
  8. this.debounce(this.updateIsLastElement)
  9. },
  10. },
  11. },
  12. properties: {
  13. prefixCls: {
  14. type: String,
  15. value: 'wux-timeline',
  16. },
  17. pending: {
  18. type: Boolean,
  19. value: false,
  20. },
  21. position: {
  22. type: String,
  23. value: 'left',
  24. },
  25. },
  26. methods: {
  27. updateIsLastElement() {
  28. const elements = this.getRelationNodes('../timeline-item/index')
  29. if (elements.length > 0) {
  30. const lastIndex = elements.length - 1
  31. const { pending, position } = this.data
  32. elements.forEach((element, index) => {
  33. const isLast = pending ? index === Math.max(0, lastIndex - 1) : index === lastIndex
  34. const isPending = pending && index === lastIndex
  35. element.updateIsLastElement({
  36. index,
  37. isLast,
  38. isPending,
  39. pending,
  40. position,
  41. })
  42. })
  43. }
  44. },
  45. },
  46. })