index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var relation_1 = require("../common/relation");
  4. var component_1 = require("../common/component");
  5. (0, component_1.VantComponent)({
  6. classes: ['item-title-class'],
  7. field: true,
  8. relation: (0, relation_1.useParent)('dropdown-menu', function () {
  9. this.updateDataFromParent();
  10. }),
  11. props: {
  12. value: {
  13. type: null,
  14. observer: 'rerender',
  15. },
  16. title: {
  17. type: String,
  18. observer: 'rerender',
  19. },
  20. disabled: Boolean,
  21. titleClass: {
  22. type: String,
  23. observer: 'rerender',
  24. },
  25. options: {
  26. type: Array,
  27. value: [],
  28. observer: 'rerender',
  29. },
  30. popupStyle: String,
  31. useBeforeToggle: {
  32. type: Boolean,
  33. value: false,
  34. },
  35. rootPortal: {
  36. type: Boolean,
  37. value: false,
  38. },
  39. },
  40. data: {
  41. transition: true,
  42. showPopup: false,
  43. showWrapper: false,
  44. displayTitle: '',
  45. safeAreaTabBar: false,
  46. },
  47. methods: {
  48. rerender: function () {
  49. var _this = this;
  50. wx.nextTick(function () {
  51. var _a;
  52. (_a = _this.parent) === null || _a === void 0 ? void 0 : _a.updateItemListData();
  53. });
  54. },
  55. updateDataFromParent: function () {
  56. if (this.parent) {
  57. var _a = this.parent.data, overlay = _a.overlay, duration = _a.duration, activeColor = _a.activeColor, closeOnClickOverlay = _a.closeOnClickOverlay, direction = _a.direction, safeAreaTabBar = _a.safeAreaTabBar;
  58. this.setData({
  59. overlay: overlay,
  60. duration: duration,
  61. activeColor: activeColor,
  62. closeOnClickOverlay: closeOnClickOverlay,
  63. direction: direction,
  64. safeAreaTabBar: safeAreaTabBar,
  65. });
  66. }
  67. },
  68. onOpen: function () {
  69. this.$emit('open');
  70. },
  71. onOpened: function () {
  72. this.$emit('opened');
  73. },
  74. onClose: function () {
  75. this.$emit('close');
  76. },
  77. onClosed: function () {
  78. this.$emit('closed');
  79. this.setData({ showWrapper: false });
  80. },
  81. onOptionTap: function (event) {
  82. var option = event.currentTarget.dataset.option;
  83. var value = option.value;
  84. var shouldEmitChange = this.data.value !== value;
  85. this.setData({ showPopup: false, value: value });
  86. this.$emit('close');
  87. this.rerender();
  88. if (shouldEmitChange) {
  89. this.$emit('change', value);
  90. }
  91. },
  92. toggle: function (show, options) {
  93. var _this = this;
  94. if (options === void 0) { options = {}; }
  95. var showPopup = this.data.showPopup;
  96. if (typeof show !== 'boolean') {
  97. show = !showPopup;
  98. }
  99. if (show === showPopup) {
  100. return;
  101. }
  102. this.onBeforeToggle(show).then(function (status) {
  103. var _a;
  104. if (!status) {
  105. return;
  106. }
  107. _this.setData({
  108. transition: !options.immediate,
  109. showPopup: show,
  110. });
  111. if (show) {
  112. (_a = _this.parent) === null || _a === void 0 ? void 0 : _a.getChildWrapperStyle().then(function (wrapperStyle) {
  113. _this.setData({ wrapperStyle: wrapperStyle, showWrapper: true });
  114. _this.rerender();
  115. });
  116. }
  117. else {
  118. _this.rerender();
  119. }
  120. });
  121. },
  122. onBeforeToggle: function (status) {
  123. var _this = this;
  124. var useBeforeToggle = this.data.useBeforeToggle;
  125. if (!useBeforeToggle) {
  126. return Promise.resolve(true);
  127. }
  128. return new Promise(function (resolve) {
  129. _this.$emit('before-toggle', {
  130. status: status,
  131. callback: function (value) { return resolve(value); },
  132. });
  133. });
  134. },
  135. },
  136. });