index.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Component<
  2. {
  3. heightStyle: string
  4. },
  5. {
  6. scrollMaxHeight: ComponentPropertyNumberType
  7. active: ComponentPropertyNumberType
  8. borderColor: ComponentPropertyStringType
  9. borderWidth: ComponentPropertyNumberType
  10. },
  11. {
  12. updateChildren(activeIdx: number): void
  13. },
  14. {
  15. children: CustomComponent[]
  16. currentActive: number
  17. }
  18. >({
  19. relations: {
  20. './sidebar-item/index': {
  21. type: 'child',
  22. linked(target: CustomComponent) {
  23. this.children.push(target)
  24. this.updateChildren(this.properties.active)
  25. },
  26. unlinked(target: CustomComponent) {
  27. this.children = this.children.filter((item) => item !== target)
  28. },
  29. },
  30. },
  31. properties: {
  32. scrollMaxHeight: {
  33. type: Number,
  34. observer(val: number) {
  35. this.setData({
  36. heightStyle: val > 0 ? `height: ${val}px;` : '',
  37. })
  38. },
  39. },
  40. active: {
  41. type: Number,
  42. value: 0,
  43. observer(val: number) {
  44. this.updateChildren(val)
  45. },
  46. },
  47. borderColor: {
  48. type: String,
  49. value: '#e73535',
  50. },
  51. borderWidth: {
  52. type: Number,
  53. value: 3,
  54. },
  55. },
  56. lifetimes: {
  57. created() {
  58. this.children = []
  59. },
  60. },
  61. data: {
  62. heightStyle: '',
  63. },
  64. methods: {
  65. updateChildren(activeIdx) {
  66. const { children } = this
  67. if (children && children.length > 0) {
  68. children.forEach((child, idx) => {
  69. child.setActive(idx === activeIdx)
  70. })
  71. }
  72. return Promise.resolve()
  73. },
  74. },
  75. })