index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. var relation_1 = require("../common/relation");
  5. var utils_1 = require("../common/utils");
  6. var ARRAY = [];
  7. (0, component_1.VantComponent)({
  8. field: true,
  9. classes: ['title-class'],
  10. relation: (0, relation_1.useChildren)('dropdown-item', function () {
  11. this.updateItemListData();
  12. }),
  13. props: {
  14. activeColor: {
  15. type: String,
  16. observer: 'updateChildrenData',
  17. },
  18. overlay: {
  19. type: Boolean,
  20. value: true,
  21. observer: 'updateChildrenData',
  22. },
  23. zIndex: {
  24. type: Number,
  25. value: 10,
  26. },
  27. duration: {
  28. type: Number,
  29. value: 200,
  30. observer: 'updateChildrenData',
  31. },
  32. direction: {
  33. type: String,
  34. value: 'down',
  35. observer: 'updateChildrenData',
  36. },
  37. closeOnClickOverlay: {
  38. type: Boolean,
  39. value: true,
  40. observer: 'updateChildrenData',
  41. },
  42. closeOnClickOutside: {
  43. type: Boolean,
  44. value: true,
  45. },
  46. },
  47. data: {
  48. itemListData: [],
  49. },
  50. beforeCreate: function () {
  51. var windowHeight = (0, utils_1.getSystemInfoSync)().windowHeight;
  52. this.windowHeight = windowHeight;
  53. ARRAY.push(this);
  54. },
  55. destroyed: function () {
  56. var _this = this;
  57. ARRAY = ARRAY.filter(function (item) { return item !== _this; });
  58. },
  59. methods: {
  60. updateItemListData: function () {
  61. this.setData({
  62. itemListData: this.children.map(function (child) { return child.data; }),
  63. });
  64. },
  65. updateChildrenData: function () {
  66. this.children.forEach(function (child) {
  67. child.updateDataFromParent();
  68. });
  69. },
  70. toggleItem: function (active) {
  71. this.children.forEach(function (item, index) {
  72. var showPopup = item.data.showPopup;
  73. if (index === active) {
  74. item.toggle();
  75. }
  76. else if (showPopup) {
  77. item.toggle(false, { immediate: true });
  78. }
  79. });
  80. },
  81. close: function () {
  82. this.children.forEach(function (child) {
  83. child.toggle(false, { immediate: true });
  84. });
  85. },
  86. getChildWrapperStyle: function () {
  87. var _this = this;
  88. var _a = this.data, zIndex = _a.zIndex, direction = _a.direction;
  89. return (0, utils_1.getRect)(this, '.van-dropdown-menu').then(function (rect) {
  90. var _a = rect.top, top = _a === void 0 ? 0 : _a, _b = rect.bottom, bottom = _b === void 0 ? 0 : _b;
  91. var offset = direction === 'down' ? bottom : _this.windowHeight - top;
  92. var wrapperStyle = "z-index: ".concat(zIndex, ";");
  93. if (direction === 'down') {
  94. wrapperStyle += "top: ".concat((0, utils_1.addUnit)(offset), ";");
  95. }
  96. else {
  97. wrapperStyle += "bottom: ".concat((0, utils_1.addUnit)(offset), ";");
  98. }
  99. return wrapperStyle;
  100. });
  101. },
  102. onTitleTap: function (event) {
  103. var _this = this;
  104. var index = event.currentTarget.dataset.index;
  105. var child = this.children[index];
  106. if (!child.data.disabled) {
  107. ARRAY.forEach(function (menuItem) {
  108. if (menuItem &&
  109. menuItem.data.closeOnClickOutside &&
  110. menuItem !== _this) {
  111. menuItem.close();
  112. }
  113. });
  114. this.toggleItem(index);
  115. }
  116. },
  117. },
  118. });