index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <uni-shadow-root class="weapp-lib-dropdown-menu-index"><view class="van-dropdown-menu van-dropdown-menu--top-bottom custom-class">
  3. <view v-for="(item,index) in (itemListData)" :key="item.index" :data-index="index" :class="utils.bem('dropdown-menu__item', { disabled: item.disabled })" @click="onTitleTap">
  4. <view :class="(item.titleClass)+' '+(utils.bem('dropdown-menu__title', { active: item.showPopup, down: item.showPopup === (direction === 'down') }))+' title-class'" :style="item.showPopup ? 'color:' + activeColor : ''">
  5. <view class="van-ellipsis">
  6. {{ computed.displayTitle(item) }}
  7. </view>
  8. </view>
  9. </view>
  10. <slot></slot>
  11. </view></uni-shadow-root>
  12. </template>
  13. <wxs src="../wxs/utils.wxs" module="utils"></wxs><wxs src="./index.wxs" module="computed"></wxs>
  14. <script>
  15. global['__wxRoute'] = 'weapp/lib/dropdown-menu/index'
  16. "use strict";
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. var component_1 = require("../common/component");
  19. var relation_1 = require("../common/relation");
  20. var utils_1 = require("../common/utils");
  21. var ARRAY = [];
  22. (0, component_1.VantComponent)({
  23. field: true,
  24. classes: ['title-class'],
  25. relation: (0, relation_1.useChildren)('dropdown-item', function () {
  26. this.updateItemListData();
  27. }),
  28. props: {
  29. activeColor: {
  30. type: String,
  31. observer: 'updateChildrenData',
  32. },
  33. overlay: {
  34. type: Boolean,
  35. value: true,
  36. observer: 'updateChildrenData',
  37. },
  38. zIndex: {
  39. type: Number,
  40. value: 10,
  41. },
  42. duration: {
  43. type: Number,
  44. value: 200,
  45. observer: 'updateChildrenData',
  46. },
  47. direction: {
  48. type: String,
  49. value: 'down',
  50. observer: 'updateChildrenData',
  51. },
  52. safeAreaTabBar: {
  53. type: Boolean,
  54. value: false,
  55. },
  56. closeOnClickOverlay: {
  57. type: Boolean,
  58. value: true,
  59. observer: 'updateChildrenData',
  60. },
  61. closeOnClickOutside: {
  62. type: Boolean,
  63. value: true,
  64. },
  65. },
  66. data: {
  67. itemListData: [],
  68. },
  69. beforeCreate: function () {
  70. var windowHeight = (0, utils_1.getSystemInfoSync)().windowHeight;
  71. this.windowHeight = windowHeight;
  72. ARRAY.push(this);
  73. },
  74. destroyed: function () {
  75. var _this = this;
  76. ARRAY = ARRAY.filter(function (item) { return item !== _this; });
  77. },
  78. methods: {
  79. updateItemListData: function () {
  80. this.setData({
  81. itemListData: this.children.map(function (child) { return child.data; }),
  82. });
  83. },
  84. updateChildrenData: function () {
  85. this.children.forEach(function (child) {
  86. child.updateDataFromParent();
  87. });
  88. },
  89. toggleItem: function (active) {
  90. this.children.forEach(function (item, index) {
  91. var showPopup = item.data.showPopup;
  92. if (index === active) {
  93. item.toggle();
  94. }
  95. else if (showPopup) {
  96. item.toggle(false, { immediate: true });
  97. }
  98. });
  99. },
  100. close: function () {
  101. this.children.forEach(function (child) {
  102. child.toggle(false, { immediate: true });
  103. });
  104. },
  105. getChildWrapperStyle: function () {
  106. var _this = this;
  107. var _a = this.data, zIndex = _a.zIndex, direction = _a.direction;
  108. return (0, utils_1.getRect)(this, '.van-dropdown-menu').then(function (rect) {
  109. var _a = rect.top, top = _a === void 0 ? 0 : _a, _b = rect.bottom, bottom = _b === void 0 ? 0 : _b;
  110. var offset = direction === 'down' ? bottom : _this.windowHeight - top;
  111. var wrapperStyle = "z-index: ".concat(zIndex, ";");
  112. if (direction === 'down') {
  113. wrapperStyle += "top: ".concat((0, utils_1.addUnit)(offset), ";");
  114. }
  115. else {
  116. wrapperStyle += "bottom: ".concat((0, utils_1.addUnit)(offset), ";");
  117. }
  118. return wrapperStyle;
  119. });
  120. },
  121. onTitleTap: function (event) {
  122. var _this = 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 &&
  128. menuItem.data.closeOnClickOutside &&
  129. menuItem !== _this) {
  130. menuItem.close();
  131. }
  132. });
  133. this.toggleItem(index);
  134. }
  135. },
  136. },
  137. });
  138. export default global['__wxComponents']['weapp/lib/dropdown-menu/index']
  139. </script>
  140. <style platform="mp-weixin">
  141. @import '../common/index.css';.van-dropdown-menu{background-color:var(--dropdown-menu-background-color,#fff);box-shadow:var(--dropdown-menu-box-shadow,0 2px 12px hsla(210,1%,40%,.12));display:flex;height:var(--dropdown-menu-height,50px);-webkit-user-select:none;user-select:none}.van-dropdown-menu__item{align-items:center;display:flex;flex:1;justify-content:center;min-width:0}.van-dropdown-menu__item:active{opacity:.7}.van-dropdown-menu__item--disabled:active{opacity:1}.van-dropdown-menu__item--disabled .van-dropdown-menu__title{color:var(--dropdown-menu-title-disabled-text-color,#969799)}.van-dropdown-menu__title{box-sizing:border-box;color:var(--dropdown-menu-title-text-color,#323233);font-size:var(--dropdown-menu-title-font-size,15px);line-height:var(--dropdown-menu-title-line-height,18px);max-width:100%;padding:var(--dropdown-menu-title-padding,0 24px 0 8px);position:relative}.van-dropdown-menu__title:after{border-color:transparent transparent currentcolor currentcolor;border-style:solid;border-width:3px;content:"";margin-top:-5px;opacity:.8;position:absolute;right:11px;top:50%;transform:rotate(-45deg)}.van-dropdown-menu__title--active{color:var(--dropdown-menu-title-active-text-color,#ee0a24)}.van-dropdown-menu__title--down:after{margin-top:-1px;transform:rotate(135deg)}
  142. </style>