index.js 3.8 KB

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