index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var component_1 = require('../common/component');
  4. component_1.VantComponent({
  5. classes: ['title-class', 'content-class'],
  6. relation: {
  7. name: 'collapse',
  8. type: 'ancestor',
  9. current: 'collapse-item',
  10. },
  11. props: {
  12. name: null,
  13. title: null,
  14. value: null,
  15. icon: String,
  16. label: String,
  17. disabled: Boolean,
  18. clickable: Boolean,
  19. border: {
  20. type: Boolean,
  21. value: true,
  22. },
  23. isLink: {
  24. type: Boolean,
  25. value: true,
  26. },
  27. },
  28. data: {
  29. expanded: false,
  30. },
  31. created: function () {
  32. this.animation = wx.createAnimation({
  33. duration: 0,
  34. timingFunction: 'ease-in-out',
  35. });
  36. },
  37. mounted: function () {
  38. this.updateExpanded();
  39. this.inited = true;
  40. },
  41. methods: {
  42. updateExpanded: function () {
  43. if (!this.parent) {
  44. return Promise.resolve();
  45. }
  46. var _a = this.parent.data,
  47. value = _a.value,
  48. accordion = _a.accordion;
  49. var _b = this.parent.children,
  50. children = _b === void 0 ? [] : _b;
  51. var name = this.data.name;
  52. var index = children.indexOf(this);
  53. var currentName = name == null ? index : name;
  54. var expanded = accordion
  55. ? value === currentName
  56. : (value || []).some(function (name) {
  57. return name === currentName;
  58. });
  59. if (expanded !== this.data.expanded) {
  60. this.updateStyle(expanded);
  61. }
  62. this.setData({ index: index, expanded: expanded });
  63. },
  64. updateStyle: function (expanded) {
  65. var _this = this;
  66. var inited = this.inited;
  67. this.getRect('.van-collapse-item__content')
  68. .then(function (rect) {
  69. return rect.height;
  70. })
  71. .then(function (height) {
  72. var animation = _this.animation;
  73. if (expanded) {
  74. animation
  75. .height(height)
  76. .top(1)
  77. .step({
  78. duration: inited ? 300 : 1,
  79. })
  80. .height('auto')
  81. .step();
  82. _this.setData({
  83. animation: animation.export(),
  84. });
  85. return;
  86. }
  87. animation.height(height).top(0).step({ duration: 1 }).height(0).step({
  88. duration: 300,
  89. });
  90. _this.setData({
  91. animation: animation.export(),
  92. });
  93. });
  94. },
  95. onClick: function () {
  96. if (this.data.disabled) {
  97. return;
  98. }
  99. var _a = this.data,
  100. name = _a.name,
  101. expanded = _a.expanded;
  102. var index = this.parent.children.indexOf(this);
  103. var currentName = name == null ? index : name;
  104. this.parent.switch(currentName, !expanded);
  105. },
  106. },
  107. });