index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <uni-shadow-root class="weapp-lib-dropdown-item-index"><view v-if="showWrapper" :class="(utils.bem('dropdown-item', direction))+' custom-class'" :style="wrapperStyle">
  3. <van-popup :show="showPopup" :custom-style="'position: absolute;'+(popupStyle)" overlay-style="position: absolute;" :overlay="overlay" :position="direction === 'down' ? 'top' : 'bottom'" :duration="transition ? duration : 0" :safe-area-tab-bar="safeAreaTabBar" :close-on-click-overlay="closeOnClickOverlay" :rootPortal="rootPortal" @enter="onOpen" @leave="onClose" @close="toggle" @after-enter="onOpened" @after-leave="onClosed">
  4. <van-cell v-for="(item,index) in (options)" :key="item.value" :data-option="item" :class="utils.bem('dropdown-item__option', { active: item.value === value } )" clickable :icon="item.icon" @click.native="onOptionTap">
  5. <view slot="title" class="van-dropdown-item__title item-title-class" :style="item.value === value ? 'color:' + activeColor : ''">
  6. {{ item.text }}
  7. </view>
  8. <van-icon v-if="item.value === value" name="success" class="van-dropdown-item__icon" :color="activeColor"></van-icon>
  9. </van-cell>
  10. <slot></slot>
  11. </van-popup>
  12. </view></uni-shadow-root>
  13. </template>
  14. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  15. <script>
  16. import VanPopup from '../popup/index.vue'
  17. import VanCell from '../cell/index.vue'
  18. import VanIcon from '../icon/index.vue'
  19. global['__wxVueOptions'] = {components:{'van-popup': VanPopup,'van-cell': VanCell,'van-icon': VanIcon}}
  20. global['__wxRoute'] = 'weapp/lib/dropdown-item/index'
  21. "use strict";
  22. Object.defineProperty(exports, "__esModule", { value: true });
  23. var relation_1 = require("../common/relation");
  24. var component_1 = require("../common/component");
  25. (0, component_1.VantComponent)({
  26. classes: ['item-title-class'],
  27. field: true,
  28. relation: (0, relation_1.useParent)('dropdown-menu', function () {
  29. this.updateDataFromParent();
  30. }),
  31. props: {
  32. value: {
  33. type: null,
  34. observer: 'rerender',
  35. },
  36. title: {
  37. type: String,
  38. observer: 'rerender',
  39. },
  40. disabled: Boolean,
  41. titleClass: {
  42. type: String,
  43. observer: 'rerender',
  44. },
  45. options: {
  46. type: Array,
  47. value: [],
  48. observer: 'rerender',
  49. },
  50. popupStyle: String,
  51. useBeforeToggle: {
  52. type: Boolean,
  53. value: false,
  54. },
  55. rootPortal: {
  56. type: Boolean,
  57. value: false,
  58. },
  59. },
  60. data: {
  61. transition: true,
  62. showPopup: false,
  63. showWrapper: false,
  64. displayTitle: '',
  65. safeAreaTabBar: false,
  66. },
  67. methods: {
  68. rerender: function () {
  69. var _this = this;
  70. wx.nextTick(function () {
  71. var _a;
  72. (_a = _this.parent) === null || _a === void 0 ? void 0 : _a.updateItemListData();
  73. });
  74. },
  75. updateDataFromParent: function () {
  76. if (this.parent) {
  77. var _a = this.parent.data, overlay = _a.overlay, duration = _a.duration, activeColor = _a.activeColor, closeOnClickOverlay = _a.closeOnClickOverlay, direction = _a.direction, safeAreaTabBar = _a.safeAreaTabBar;
  78. this.setData({
  79. overlay: overlay,
  80. duration: duration,
  81. activeColor: activeColor,
  82. closeOnClickOverlay: closeOnClickOverlay,
  83. direction: direction,
  84. safeAreaTabBar: safeAreaTabBar,
  85. });
  86. }
  87. },
  88. onOpen: function () {
  89. this.$emit('open');
  90. },
  91. onOpened: function () {
  92. this.$emit('opened');
  93. },
  94. onClose: function () {
  95. this.$emit('close');
  96. },
  97. onClosed: function () {
  98. this.$emit('closed');
  99. this.setData({ showWrapper: false });
  100. },
  101. onOptionTap: function (event) {
  102. var option = event.currentTarget.dataset.option;
  103. var value = option.value;
  104. var shouldEmitChange = this.data.value !== value;
  105. this.setData({ showPopup: false, value: value });
  106. this.$emit('close');
  107. this.rerender();
  108. if (shouldEmitChange) {
  109. this.$emit('change', value);
  110. }
  111. },
  112. toggle: function (show, options) {
  113. var _this = this;
  114. if (options === void 0) { options = {}; }
  115. var showPopup = this.data.showPopup;
  116. if (typeof show !== 'boolean') {
  117. show = !showPopup;
  118. }
  119. if (show === showPopup) {
  120. return;
  121. }
  122. this.onBeforeToggle(show).then(function (status) {
  123. var _a;
  124. if (!status) {
  125. return;
  126. }
  127. _this.setData({
  128. transition: !options.immediate,
  129. showPopup: show,
  130. });
  131. if (show) {
  132. (_a = _this.parent) === null || _a === void 0 ? void 0 : _a.getChildWrapperStyle().then(function (wrapperStyle) {
  133. _this.setData({ wrapperStyle: wrapperStyle, showWrapper: true });
  134. _this.rerender();
  135. });
  136. }
  137. else {
  138. _this.rerender();
  139. }
  140. });
  141. },
  142. onBeforeToggle: function (status) {
  143. var _this = this;
  144. var useBeforeToggle = this.data.useBeforeToggle;
  145. if (!useBeforeToggle) {
  146. return Promise.resolve(true);
  147. }
  148. return new Promise(function (resolve) {
  149. _this.$emit('before-toggle', {
  150. status: status,
  151. callback: function (value) { return resolve(value); },
  152. });
  153. });
  154. },
  155. },
  156. });
  157. export default global['__wxComponents']['weapp/lib/dropdown-item/index']
  158. </script>
  159. <style platform="mp-weixin">
  160. @import '../common/index.css';.van-dropdown-item{left:0;overflow:hidden;position:fixed;right:0}.van-dropdown-item__option{text-align:left}.van-dropdown-item__option--active .van-dropdown-item__icon,.van-dropdown-item__option--active .van-dropdown-item__title{color:var(--dropdown-menu-option-active-color,#ee0a24)}.van-dropdown-item--up{top:0}.van-dropdown-item--down{bottom:0}.van-dropdown-item__icon{display:block;line-height:inherit}
  161. </style>