index.js 3.6 KB

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