px-popup-bottom.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. props: {
  5. title: {
  6. //标题
  7. type: String,
  8. default: ""
  9. },
  10. fontweight: {
  11. type: [String, Number],
  12. default: "normal"
  13. },
  14. visible: {
  15. //隐藏显示标识
  16. type: Boolean,
  17. default: false
  18. },
  19. maxHeight: {
  20. //内容区域最大高度
  21. type: [String, Number],
  22. default: "75%"
  23. },
  24. radius: {
  25. //顶部圆角
  26. type: [String, Number],
  27. default: "0"
  28. },
  29. animaTime: {
  30. //弹窗动画时间
  31. type: Number,
  32. default: 0.2
  33. },
  34. bottom: {
  35. //离底部距离
  36. type: [String, Number],
  37. default: 0
  38. },
  39. bgColor: {
  40. type: [String],
  41. default: "#ffffff"
  42. },
  43. zindex: {
  44. type: [String, Number],
  45. default: 1e3
  46. },
  47. maskZindex: {
  48. type: [String, Number],
  49. default: 999
  50. },
  51. always: {
  52. //是否每次打开都重新计算内容高度
  53. type: Boolean,
  54. default: false
  55. }
  56. },
  57. data() {
  58. return {
  59. show: false,
  60. height: 0,
  61. PopHeight: 0,
  62. cotMaxHeight: "",
  63. isAnimaStart: false,
  64. rpxRate: "",
  65. cotRadius: 0
  66. // closeIcon: iconClose
  67. };
  68. },
  69. watch: {
  70. visible(newval) {
  71. this.isAnimaStart = true;
  72. setTimeout(() => {
  73. this.isAnimaStart = false;
  74. }, this.animaTime * 1e3);
  75. if (newval && this.height === 0) {
  76. if (this.PopHeight === 0 || this.always) {
  77. this.setContViewHeight();
  78. } else {
  79. this.height = this.PopHeight;
  80. }
  81. this.$emit("open");
  82. } else {
  83. this.height = 0;
  84. }
  85. this.show = newval;
  86. },
  87. maxHeight: {
  88. handler(newval) {
  89. this.cotMaxHeight = this.unitCheck(newval);
  90. },
  91. immediate: true
  92. },
  93. radius: {
  94. handler(newval) {
  95. this.cotRadius = this.unitCheck(newval);
  96. },
  97. immediate: true
  98. }
  99. },
  100. created() {
  101. this.rpxRate = this.getRpxRate();
  102. },
  103. mounted() {
  104. this.$nextTick(() => {
  105. });
  106. },
  107. methods: {
  108. onClose() {
  109. this.$emit("update:visible", false);
  110. this.$emit("close");
  111. },
  112. //触底
  113. onScrollToLower(e) {
  114. this.$emit("reachBottom");
  115. },
  116. getRpxRate() {
  117. let res = common_vendor.index.getWindowInfo();
  118. let width = res.windowWidth;
  119. let rate = 750 / width;
  120. return rate;
  121. },
  122. unitCheck(value) {
  123. const val = String(value);
  124. if (!val.includes("px") && !val.includes("%")) {
  125. return `${val}rpx`;
  126. }
  127. return val;
  128. },
  129. preventTouch(el) {
  130. el.addEventListener("touchmove", function(e) {
  131. e.stopPropagation();
  132. }, {
  133. passive: false
  134. });
  135. },
  136. setBodyOverFlow(val) {
  137. document.body.style.overflow = val;
  138. },
  139. //设置内容区域高度
  140. async setContViewHeight() {
  141. let data = await this.computeHeight();
  142. this.height = data.height + (this.title ? 100 / parseFloat(this.rpxRate) : 0);
  143. this.PopHeight = this.height;
  144. },
  145. //计算内容区域高度
  146. computeHeight() {
  147. return new Promise((resolve) => {
  148. this.$nextTick(() => {
  149. const query = common_vendor.index.createSelectorQuery().in(this);
  150. query.select("#popup_content").boundingClientRect((data) => {
  151. resolve(data);
  152. }).exec();
  153. });
  154. });
  155. }
  156. }
  157. };
  158. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  159. return {
  160. a: $props.maskZindex,
  161. b: $props.bottom + "rpx",
  162. c: $data.show,
  163. d: common_vendor.o((...args) => $options.onClose && $options.onClose(...args)),
  164. e: common_vendor.o(() => {
  165. }),
  166. f: common_vendor.t($props.title),
  167. g: $props.fontweight,
  168. h: common_vendor.o((...args) => $options.onClose && $options.onClose(...args)),
  169. i: $props.title,
  170. j: $data.isAnimaStart ? 1 : "",
  171. k: common_vendor.o((...args) => $options.onScrollToLower && $options.onScrollToLower(...args)),
  172. l: common_vendor.n({
  173. show: $data.show
  174. }),
  175. m: common_vendor.o(() => {
  176. }),
  177. n: common_vendor.o(() => {
  178. }),
  179. o: $props.bgColor,
  180. p: `${$data.height}px`,
  181. q: $data.show ? $data.cotMaxHeight : 0,
  182. r: $data.cotRadius,
  183. s: $data.cotRadius,
  184. t: `all ${$props.animaTime}s ease-in`,
  185. v: $props.bottom + "rpx",
  186. w: $props.zindex,
  187. x: common_vendor.n({
  188. "popup-show": $data.show
  189. }),
  190. y: common_vendor.o(() => {
  191. }),
  192. z: common_vendor.o(() => {
  193. }),
  194. A: $props.zindex
  195. };
  196. }
  197. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-4fac7f82"]]);
  198. wx.createComponent(Component);