u-popup.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. "use strict";
  2. const uni_modules_uviewPlus_components_uPopup_props = require("./props.js");
  3. const uni_modules_uviewPlus_libs_mixin_mpMixin = require("../../libs/mixin/mpMixin.js");
  4. const uni_modules_uviewPlus_libs_mixin_mixin = require("../../libs/mixin/mixin.js");
  5. const uni_modules_uviewPlus_libs_function_index = require("../../libs/function/index.js");
  6. const common_vendor = require("../../../../common/vendor.js");
  7. const _sfc_main = {
  8. name: "u-popup",
  9. mixins: [uni_modules_uviewPlus_libs_mixin_mpMixin.mpMixin, uni_modules_uviewPlus_libs_mixin_mixin.mixin, uni_modules_uviewPlus_components_uPopup_props.props],
  10. data() {
  11. return {
  12. overlayDuration: this.duration + 50
  13. };
  14. },
  15. watch: {
  16. show(newValue, oldValue) {
  17. if (newValue === true) {
  18. const children = this.$children;
  19. this.retryComputedComponentRect(children);
  20. }
  21. }
  22. },
  23. computed: {
  24. transitionStyle() {
  25. const style = {
  26. zIndex: this.zIndex,
  27. position: "fixed",
  28. display: "flex"
  29. };
  30. style[this.mode] = 0;
  31. if (this.mode === "left") {
  32. return uni_modules_uviewPlus_libs_function_index.deepMerge(style, {
  33. bottom: 0,
  34. top: 0
  35. });
  36. } else if (this.mode === "right") {
  37. return uni_modules_uviewPlus_libs_function_index.deepMerge(style, {
  38. bottom: 0,
  39. top: 0
  40. });
  41. } else if (this.mode === "top") {
  42. return uni_modules_uviewPlus_libs_function_index.deepMerge(style, {
  43. left: 0,
  44. right: 0
  45. });
  46. } else if (this.mode === "bottom") {
  47. return uni_modules_uviewPlus_libs_function_index.deepMerge(style, {
  48. left: 0,
  49. right: 0
  50. });
  51. } else if (this.mode === "center") {
  52. return uni_modules_uviewPlus_libs_function_index.deepMerge(style, {
  53. alignItems: "center",
  54. "justify-content": "center",
  55. top: 0,
  56. left: 0,
  57. right: 0,
  58. bottom: 0
  59. });
  60. }
  61. },
  62. contentStyle() {
  63. const style = {};
  64. uni_modules_uviewPlus_libs_function_index.sys();
  65. if (this.mode !== "center") {
  66. style.flex = 1;
  67. }
  68. if (this.bgColor) {
  69. style.backgroundColor = this.bgColor;
  70. }
  71. if (this.round) {
  72. const value = uni_modules_uviewPlus_libs_function_index.addUnit(this.round);
  73. if (this.mode === "top") {
  74. style.borderBottomLeftRadius = value;
  75. style.borderBottomRightRadius = value;
  76. } else if (this.mode === "bottom") {
  77. style.borderTopLeftRadius = value;
  78. style.borderTopRightRadius = value;
  79. } else if (this.mode === "center") {
  80. style.borderRadius = value;
  81. }
  82. }
  83. return uni_modules_uviewPlus_libs_function_index.deepMerge(style, uni_modules_uviewPlus_libs_function_index.addStyle(this.customStyle));
  84. },
  85. position() {
  86. if (this.mode === "center") {
  87. return this.zoom ? "fade-zoom" : "fade";
  88. }
  89. if (this.mode === "left") {
  90. return "slide-left";
  91. }
  92. if (this.mode === "right") {
  93. return "slide-right";
  94. }
  95. if (this.mode === "bottom") {
  96. return "slide-up";
  97. }
  98. if (this.mode === "top") {
  99. return "slide-down";
  100. }
  101. }
  102. },
  103. emits: ["open", "close", "click"],
  104. methods: {
  105. // 点击遮罩
  106. overlayClick() {
  107. if (this.closeOnClickOverlay) {
  108. this.$emit("close");
  109. }
  110. },
  111. close(e) {
  112. this.$emit("close");
  113. },
  114. afterEnter() {
  115. this.$emit("open");
  116. },
  117. clickHandler() {
  118. if (this.mode === "center") {
  119. this.overlayClick();
  120. }
  121. this.$emit("click");
  122. },
  123. retryComputedComponentRect(children) {
  124. const names = [
  125. "u-calendar-month",
  126. "u-album",
  127. "u-collapse-item",
  128. "u-dropdown",
  129. "u-index-item",
  130. "u-index-list",
  131. "u-line-progress",
  132. "u-list-item",
  133. "u-rate",
  134. "u-read-more",
  135. "u-row",
  136. "u-row-notice",
  137. "u-scroll-list",
  138. "u-skeleton",
  139. "u-slider",
  140. "u-steps-item",
  141. "u-sticky",
  142. "u-subsection",
  143. "u-swipe-action-item",
  144. "u-tabbar",
  145. "u-tabs",
  146. "u-tooltip"
  147. ];
  148. for (let i = 0; i < children.length; i++) {
  149. const child = children[i];
  150. const grandChild = child.$children;
  151. if (names.includes(child.$options.name) && typeof (child == null ? void 0 : child.init) === "function") {
  152. uni_modules_uviewPlus_libs_function_index.sleep(50).then(() => {
  153. child.init();
  154. });
  155. }
  156. if (grandChild.length) {
  157. this.retryComputedComponentRect(grandChild);
  158. }
  159. }
  160. }
  161. }
  162. };
  163. if (!Array) {
  164. const _easycom_u_overlay2 = common_vendor.resolveComponent("u-overlay");
  165. const _easycom_u_status_bar2 = common_vendor.resolveComponent("u-status-bar");
  166. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  167. const _easycom_u_safe_bottom2 = common_vendor.resolveComponent("u-safe-bottom");
  168. const _easycom_u_transition2 = common_vendor.resolveComponent("u-transition");
  169. (_easycom_u_overlay2 + _easycom_u_status_bar2 + _easycom_u_icon2 + _easycom_u_safe_bottom2 + _easycom_u_transition2)();
  170. }
  171. const _easycom_u_overlay = () => "../u-overlay/u-overlay.js";
  172. const _easycom_u_status_bar = () => "../u-status-bar/u-status-bar.js";
  173. const _easycom_u_icon = () => "../u-icon/u-icon.js";
  174. const _easycom_u_safe_bottom = () => "../u-safe-bottom/u-safe-bottom.js";
  175. const _easycom_u_transition = () => "../u-transition/u-transition.js";
  176. if (!Math) {
  177. (_easycom_u_overlay + _easycom_u_status_bar + _easycom_u_icon + _easycom_u_safe_bottom + _easycom_u_transition)();
  178. }
  179. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  180. return common_vendor.e({
  181. a: _ctx.overlay
  182. }, _ctx.overlay ? {
  183. b: common_vendor.o($options.overlayClick),
  184. c: common_vendor.p({
  185. show: _ctx.show,
  186. duration: $data.overlayDuration,
  187. customStyle: _ctx.overlayStyle,
  188. opacity: _ctx.overlayOpacity
  189. })
  190. } : {}, {
  191. d: _ctx.safeAreaInsetTop
  192. }, _ctx.safeAreaInsetTop ? {} : {}, {
  193. e: _ctx.closeable
  194. }, _ctx.closeable ? {
  195. f: common_vendor.p({
  196. name: "close",
  197. color: "#909399",
  198. size: "18",
  199. bold: true
  200. }),
  201. g: common_vendor.o((...args) => $options.close && $options.close(...args)),
  202. h: common_vendor.n("u-popup__content__close--" + _ctx.closeIconPos)
  203. } : {}, {
  204. i: _ctx.safeAreaInsetBottom
  205. }, _ctx.safeAreaInsetBottom ? {} : {}, {
  206. j: common_vendor.s($options.contentStyle),
  207. k: common_vendor.o((...args) => _ctx.noop && _ctx.noop(...args)),
  208. l: common_vendor.o($options.afterEnter),
  209. m: common_vendor.o($options.clickHandler),
  210. n: common_vendor.p({
  211. show: _ctx.show,
  212. customStyle: $options.transitionStyle,
  213. mode: $options.position,
  214. duration: _ctx.duration
  215. })
  216. });
  217. }
  218. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-05c24e9b"]]);
  219. wx.createComponent(Component);