wd-popup.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. if (!Math) {
  4. (wdOverlay + wdIcon + wdTransition)();
  5. }
  6. const wdIcon = () => "../wd-icon/wd-icon.js";
  7. const wdOverlay = () => "../wd-overlay/wd-overlay.js";
  8. const wdTransition = () => "../wd-transition/wd-transition.js";
  9. const __default__ = {
  10. name: "wd-popup",
  11. options: {
  12. virtualHost: true,
  13. addGlobalClass: true,
  14. styleIsolation: "shared"
  15. }
  16. };
  17. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  18. ...__default__,
  19. props: common_vendor.popupProps,
  20. emits: [
  21. "update:modelValue",
  22. "before-enter",
  23. "enter",
  24. "before-leave",
  25. "leave",
  26. "after-leave",
  27. "after-enter",
  28. "click-modal",
  29. "close"
  30. ],
  31. setup(__props, { emit: __emit }) {
  32. const props = __props;
  33. const emit = __emit;
  34. const transitionName = common_vendor.computed(() => {
  35. if (props.transition) {
  36. return props.transition;
  37. }
  38. if (props.position === "center") {
  39. return ["zoom-in", "fade"];
  40. }
  41. if (props.position === "left") {
  42. return "slide-left";
  43. }
  44. if (props.position === "right") {
  45. return "slide-right";
  46. }
  47. if (props.position === "bottom") {
  48. return "slide-up";
  49. }
  50. if (props.position === "top") {
  51. return "slide-down";
  52. }
  53. return "slide-up";
  54. });
  55. const safeBottom = common_vendor.ref(0);
  56. const style = common_vendor.computed(() => {
  57. return `z-index:${props.zIndex}; padding-bottom: ${safeBottom.value}px;${props.customStyle}`;
  58. });
  59. const rootClass = common_vendor.computed(() => {
  60. return `wd-popup wd-popup--${props.position} ${!props.transition && props.position === "center" ? "is-deep" : ""} ${props.customClass || ""}`;
  61. });
  62. common_vendor.onBeforeMount(() => {
  63. if (props.safeAreaInsetBottom) {
  64. const { safeArea, screenHeight, safeAreaInsets } = common_vendor.index.getSystemInfoSync();
  65. if (safeArea) {
  66. safeBottom.value = screenHeight - (safeArea.bottom || 0);
  67. } else {
  68. safeBottom.value = 0;
  69. }
  70. }
  71. });
  72. function handleClickModal() {
  73. emit("click-modal");
  74. if (props.closeOnClickModal) {
  75. close();
  76. }
  77. }
  78. function close() {
  79. emit("close");
  80. emit("update:modelValue", false);
  81. }
  82. function noop() {
  83. }
  84. return (_ctx, _cache) => {
  85. return common_vendor.e({
  86. a: _ctx.modal
  87. }, _ctx.modal ? {
  88. b: common_vendor.o(handleClickModal),
  89. c: common_vendor.o(noop),
  90. d: common_vendor.p({
  91. show: _ctx.modelValue,
  92. ["z-index"]: _ctx.zIndex,
  93. ["lock-scroll"]: _ctx.lockScroll,
  94. duration: _ctx.duration,
  95. ["custom-style"]: _ctx.modalStyle
  96. })
  97. } : {}, {
  98. e: _ctx.closable
  99. }, _ctx.closable ? {
  100. f: common_vendor.o(close),
  101. g: common_vendor.p({
  102. ["custom-class"]: "wd-popup__close",
  103. name: "add"
  104. })
  105. } : {}, {
  106. h: common_vendor.o(($event) => emit("before-enter")),
  107. i: common_vendor.o(($event) => emit("enter")),
  108. j: common_vendor.o(($event) => emit("after-enter")),
  109. k: common_vendor.o(($event) => emit("before-leave")),
  110. l: common_vendor.o(($event) => emit("leave")),
  111. m: common_vendor.o(($event) => emit("after-leave")),
  112. n: common_vendor.p({
  113. ["lazy-render"]: _ctx.lazyRender,
  114. ["custom-class"]: rootClass.value,
  115. ["custom-style"]: style.value,
  116. duration: _ctx.duration,
  117. show: _ctx.modelValue,
  118. name: transitionName.value,
  119. destroy: _ctx.hideWhenClose
  120. })
  121. });
  122. };
  123. }
  124. });
  125. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-82a7a455"]]);
  126. wx.createComponent(Component);