index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. safeAreaTabBar: {
  38. type: Boolean,
  39. value: false,
  40. },
  41. closeOnClickOverlay: {
  42. type: Boolean,
  43. value: true,
  44. observer: 'updateChildrenData',
  45. },
  46. closeOnClickOutside: {
  47. type: Boolean,
  48. value: true,
  49. },
  50. },
  51. data: {
  52. itemListData: [],
  53. },
  54. beforeCreate: function () {
  55. var windowHeight = (0, utils_1.getSystemInfoSync)().windowHeight;
  56. this.windowHeight = windowHeight;
  57. ARRAY.push(this);
  58. },
  59. destroyed: function () {
  60. var _this = this;
  61. ARRAY = ARRAY.filter(function (item) { return item !== _this; });
  62. },
  63. methods: {
  64. updateItemListData: function () {
  65. this.setData({
  66. itemListData: this.children.map(function (child) { return child.data; }),
  67. });
  68. },
  69. updateChildrenData: function () {
  70. this.children.forEach(function (child) {
  71. child.updateDataFromParent();
  72. });
  73. },
  74. toggleItem: function (active) {
  75. this.children.forEach(function (item, index) {
  76. var showPopup = item.data.showPopup;
  77. if (index === active) {
  78. item.toggle();
  79. }
  80. else if (showPopup) {
  81. item.toggle(false, { immediate: true });
  82. }
  83. });
  84. },
  85. close: function () {
  86. this.children.forEach(function (child) {
  87. child.toggle(false, { immediate: true });
  88. });
  89. },
  90. getChildWrapperStyle: function () {
  91. var _this = this;
  92. var _a = this.data, zIndex = _a.zIndex, direction = _a.direction;
  93. return (0, utils_1.getRect)(this, '.van-dropdown-menu').then(function (rect) {
  94. var _a = rect.top, top = _a === void 0 ? 0 : _a, _b = rect.bottom, bottom = _b === void 0 ? 0 : _b;
  95. var offset = direction === 'down' ? bottom : _this.windowHeight - top;
  96. var wrapperStyle = "z-index: ".concat(zIndex, ";");
  97. if (direction === 'down') {
  98. wrapperStyle += "top: ".concat((0, utils_1.addUnit)(offset), ";");
  99. }
  100. else {
  101. wrapperStyle += "bottom: ".concat((0, utils_1.addUnit)(offset), ";");
  102. }
  103. return wrapperStyle;
  104. });
  105. },
  106. onTitleTap: function (event) {
  107. var _this = this;
  108. var index = event.currentTarget.dataset.index;
  109. var child = this.children[index];
  110. if (!child.data.disabled) {
  111. ARRAY.forEach(function (menuItem) {
  112. if (menuItem &&
  113. menuItem.data.closeOnClickOutside &&
  114. menuItem !== _this) {
  115. menuItem.close();
  116. }
  117. });
  118. this.toggleItem(index);
  119. }
  120. },
  121. },
  122. });