mescroll-body.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const uni_modules_mescrollUni_components_mescrollUni_mescrollUni = require("../mescroll-uni/mescroll-uni.js");
  4. const uni_modules_mescrollUni_components_mescrollUni_mescrollUniOption = require("../mescroll-uni/mescroll-uni-option.js");
  5. const uni_modules_mescrollUni_components_mescrollUni_mescrollI18n = require("../mescroll-uni/mescroll-i18n.js");
  6. const uni_modules_mescrollUni_components_mescrollUni_wxs_mixins = require("../mescroll-uni/wxs/mixins.js");
  7. const block0 = (Component2) => {
  8. if (!Component2.wxsCallMethods) {
  9. Component2.wxsCallMethods = [];
  10. }
  11. Component2.wxsCallMethods.push("wxsCall");
  12. };
  13. const MescrollTop = () => "../mescroll-uni/components/mescroll-top.js";
  14. const _sfc_main = {
  15. name: "mescroll-body",
  16. mixins: [uni_modules_mescrollUni_components_mescrollUni_wxs_mixins.WxsMixin],
  17. components: {
  18. MescrollTop
  19. },
  20. props: {
  21. down: Object,
  22. up: Object,
  23. i18n: Object,
  24. top: [String, Number],
  25. topbar: [Boolean, String],
  26. bottom: [String, Number],
  27. safearea: Boolean,
  28. height: [String, Number],
  29. bottombar: {
  30. type: Boolean,
  31. default: true
  32. },
  33. sticky: Boolean
  34. },
  35. data() {
  36. return {
  37. mescroll: { optDown: {}, optUp: {} },
  38. // mescroll实例
  39. downHight: 0,
  40. //下拉刷新: 容器高度
  41. downRate: 0,
  42. // 下拉比率(inOffset: rate<1; outOffset: rate>=1)
  43. downLoadType: 0,
  44. // 下拉刷新状态: 0(loading前), 1(inOffset), 2(outOffset), 3(showLoading), 4(endDownScroll)
  45. upLoadType: 0,
  46. // 上拉加载状态:0(loading前),1(loading中),2(没有更多了,显示END文本提示),3(没有更多了,不显示END文本提示)
  47. isShowEmpty: false,
  48. // 是否显示空布局
  49. isShowToTop: false,
  50. // 是否显示回到顶部按钮
  51. windowHeight: 0,
  52. // 可使用窗口的高度
  53. windowBottom: 0,
  54. // 可使用窗口的底部位置
  55. statusBarHeight: 0
  56. // 状态栏高度
  57. };
  58. },
  59. computed: {
  60. // mescroll最小高度,默认windowHeight,使列表不满屏仍可下拉
  61. minHeight() {
  62. return this.toPx(this.height || "100%") + "px";
  63. },
  64. // 下拉布局往下偏移的距离 (px)
  65. numTop() {
  66. return this.toPx(this.top);
  67. },
  68. padTop() {
  69. return this.numTop + "px";
  70. },
  71. // 上拉布局往上偏移 (px)
  72. numBottom() {
  73. return this.toPx(this.bottom);
  74. },
  75. padBottom() {
  76. return this.numBottom + "px";
  77. },
  78. // 是否为重置下拉的状态
  79. isDownReset() {
  80. return this.downLoadType === 3 || this.downLoadType === 4;
  81. },
  82. // 过渡
  83. transition() {
  84. return this.isDownReset ? "transform 300ms" : "";
  85. },
  86. translateY() {
  87. return this.downHight > 0 ? "translateY(" + this.downHight + "px)" : "";
  88. },
  89. // 是否在加载中
  90. isDownLoading() {
  91. return this.downLoadType === 3;
  92. },
  93. // 旋转的角度
  94. downRotate() {
  95. return "rotate(" + 360 * this.downRate + "deg)";
  96. },
  97. // 文本提示
  98. downText() {
  99. if (!this.mescroll)
  100. return "";
  101. switch (this.downLoadType) {
  102. case 1:
  103. return this.mescroll.optDown.textInOffset;
  104. case 2:
  105. return this.mescroll.optDown.textOutOffset;
  106. case 3:
  107. return this.mescroll.optDown.textLoading;
  108. case 4:
  109. return this.mescroll.isDownEndSuccess ? this.mescroll.optDown.textSuccess : this.mescroll.isDownEndSuccess == false ? this.mescroll.optDown.textErr : this.mescroll.optDown.textInOffset;
  110. default:
  111. return this.mescroll.optDown.textInOffset;
  112. }
  113. }
  114. },
  115. methods: {
  116. //number,rpx,upx,px,% --> px的数值
  117. toPx(num) {
  118. if (typeof num === "string") {
  119. if (num.indexOf("px") !== -1) {
  120. if (num.indexOf("rpx") !== -1) {
  121. num = num.replace("rpx", "");
  122. } else if (num.indexOf("upx") !== -1) {
  123. num = num.replace("upx", "");
  124. } else {
  125. return Number(num.replace("px", ""));
  126. }
  127. } else if (num.indexOf("%") !== -1) {
  128. let rate = Number(num.replace("%", "")) / 100;
  129. return this.windowHeight * rate;
  130. }
  131. }
  132. return num ? common_vendor.index.upx2px(Number(num)) : 0;
  133. },
  134. // 点击空布局的按钮回调
  135. emptyClick() {
  136. this.$emit("emptyclick", this.mescroll);
  137. },
  138. // 点击回到顶部的按钮回调
  139. toTopClick() {
  140. this.mescroll.scrollTo(0, this.mescroll.optUp.toTop.duration);
  141. this.$emit("topclick", this.mescroll);
  142. }
  143. },
  144. // 使用created初始化mescroll对象; 如果用mounted部分css样式编译到H5会失效
  145. created() {
  146. let vm = this;
  147. let diyOption = {
  148. // 下拉刷新的配置
  149. down: {
  150. inOffset() {
  151. vm.downLoadType = 1;
  152. },
  153. outOffset() {
  154. vm.downLoadType = 2;
  155. },
  156. onMoving(mescroll, rate, downHight) {
  157. vm.downHight = downHight;
  158. vm.downRate = rate;
  159. },
  160. showLoading(mescroll, downHight) {
  161. vm.downLoadType = 3;
  162. vm.downHight = downHight;
  163. },
  164. beforeEndDownScroll(mescroll) {
  165. vm.downLoadType = 4;
  166. return mescroll.optDown.beforeEndDelay;
  167. },
  168. endDownScroll() {
  169. vm.downLoadType = 4;
  170. vm.downHight = 0;
  171. if (vm.downResetTimer) {
  172. clearTimeout(vm.downResetTimer);
  173. vm.downResetTimer = null;
  174. }
  175. vm.downResetTimer = setTimeout(() => {
  176. if (vm.downLoadType === 4)
  177. vm.downLoadType = 0;
  178. }, 300);
  179. },
  180. // 派发下拉刷新的回调
  181. callback: function(mescroll) {
  182. vm.$emit("down", mescroll);
  183. }
  184. },
  185. // 上拉加载的配置
  186. up: {
  187. // 显示加载中的回调
  188. showLoading() {
  189. vm.upLoadType = 1;
  190. },
  191. // 显示无更多数据的回调
  192. showNoMore() {
  193. vm.upLoadType = 2;
  194. },
  195. // 隐藏上拉加载的回调
  196. hideUpScroll(mescroll) {
  197. vm.upLoadType = mescroll.optUp.hasNext ? 0 : 3;
  198. },
  199. // 空布局
  200. empty: {
  201. onShow(isShow) {
  202. vm.isShowEmpty = isShow;
  203. }
  204. },
  205. // 回到顶部
  206. toTop: {
  207. onShow(isShow) {
  208. vm.isShowToTop = isShow;
  209. }
  210. },
  211. // 派发上拉加载的回调
  212. callback: function(mescroll) {
  213. vm.$emit("up", mescroll);
  214. }
  215. }
  216. };
  217. let i18nType = uni_modules_mescrollUni_components_mescrollUni_mescrollI18n.mescrollI18n.getType();
  218. let i18nOption = { type: i18nType };
  219. uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend(i18nOption, vm.i18n);
  220. uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend(i18nOption, uni_modules_mescrollUni_components_mescrollUni_mescrollUniOption.GlobalOption.i18n);
  221. uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend(diyOption, i18nOption[i18nType]);
  222. uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend(diyOption, { down: uni_modules_mescrollUni_components_mescrollUni_mescrollUniOption.GlobalOption.down, up: uni_modules_mescrollUni_components_mescrollUni_mescrollUniOption.GlobalOption.up });
  223. let myOption = JSON.parse(JSON.stringify({ down: vm.down, up: vm.up }));
  224. uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend(myOption, diyOption);
  225. vm.mescroll = new uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll(myOption, true);
  226. vm.mescroll.i18n = i18nOption;
  227. vm.$emit("init", vm.mescroll);
  228. const sys = common_vendor.index.getSystemInfoSync();
  229. if (sys.windowHeight)
  230. vm.windowHeight = sys.windowHeight;
  231. if (sys.windowBottom)
  232. vm.windowBottom = sys.windowBottom;
  233. if (sys.statusBarHeight)
  234. vm.statusBarHeight = sys.statusBarHeight;
  235. vm.mescroll.setBodyHeight(sys.windowHeight);
  236. vm.mescroll.resetScrollTo((y, t) => {
  237. if (typeof y === "string") {
  238. setTimeout(() => {
  239. let selector;
  240. if (y.indexOf("#") == -1 && y.indexOf(".") == -1) {
  241. selector = "#" + y;
  242. } else {
  243. selector = y;
  244. }
  245. common_vendor.index.createSelectorQuery().select(selector).boundingClientRect(function(rect) {
  246. if (rect) {
  247. let top = rect.top;
  248. top += vm.mescroll.getScrollTop();
  249. common_vendor.index.pageScrollTo({
  250. scrollTop: top,
  251. duration: t
  252. });
  253. } else {
  254. console.error(selector + " does not exist");
  255. }
  256. }).exec();
  257. }, 30);
  258. } else {
  259. common_vendor.index.pageScrollTo({
  260. scrollTop: y,
  261. duration: t
  262. });
  263. }
  264. });
  265. if (vm.up && vm.up.toTop && vm.up.toTop.safearea != null)
  266. ;
  267. else {
  268. vm.mescroll.optUp.toTop.safearea = vm.safearea;
  269. }
  270. common_vendor.index.$on("setMescrollGlobalOption", (options) => {
  271. if (!options)
  272. return;
  273. let i18nType2 = options.i18n ? options.i18n.type : null;
  274. if (i18nType2 && vm.mescroll.i18n.type != i18nType2) {
  275. vm.mescroll.i18n.type = i18nType2;
  276. uni_modules_mescrollUni_components_mescrollUni_mescrollI18n.mescrollI18n.setType(i18nType2);
  277. uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend(options, vm.mescroll.i18n[i18nType2]);
  278. }
  279. if (options.down) {
  280. let down = uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend({}, options.down);
  281. vm.mescroll.optDown = uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend(down, vm.mescroll.optDown);
  282. }
  283. if (options.up) {
  284. let up = uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend({}, options.up);
  285. vm.mescroll.optUp = uni_modules_mescrollUni_components_mescrollUni_mescrollUni.MeScroll.extend(up, vm.mescroll.optUp);
  286. }
  287. });
  288. },
  289. destroyed() {
  290. common_vendor.index.$off("setMescrollGlobalOption");
  291. }
  292. };
  293. if (!Array) {
  294. const _easycom_mescroll_empty2 = common_vendor.resolveComponent("mescroll-empty");
  295. const _component_mescroll_top = common_vendor.resolveComponent("mescroll-top");
  296. (_easycom_mescroll_empty2 + _component_mescroll_top)();
  297. }
  298. const _easycom_mescroll_empty = () => "../mescroll-empty/mescroll-empty.js";
  299. if (!Math) {
  300. _easycom_mescroll_empty();
  301. }
  302. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  303. return common_vendor.e({
  304. a: $props.topbar && $data.statusBarHeight
  305. }, $props.topbar && $data.statusBarHeight ? {
  306. b: $data.statusBarHeight + "px",
  307. c: $props.topbar
  308. } : {}, {
  309. d: $data.mescroll.optDown.use
  310. }, $data.mescroll.optDown.use ? {
  311. e: $options.isDownLoading ? 1 : "",
  312. f: $data.mescroll.optDown.textColor,
  313. g: $options.downRotate,
  314. h: common_vendor.t($options.downText),
  315. i: $data.mescroll.optDown.bgColor,
  316. j: $data.mescroll.optDown.textColor
  317. } : {}, {
  318. k: $data.isShowEmpty
  319. }, $data.isShowEmpty ? {
  320. l: common_vendor.o($options.emptyClick),
  321. m: common_vendor.p({
  322. option: $data.mescroll.optUp.empty
  323. })
  324. } : {}, {
  325. n: $data.mescroll.optUp.use && !$options.isDownLoading && $data.upLoadType !== 3
  326. }, $data.mescroll.optUp.use && !$options.isDownLoading && $data.upLoadType !== 3 ? common_vendor.e({
  327. o: $data.upLoadType === 1
  328. }, $data.upLoadType === 1 ? {
  329. p: $data.mescroll.optUp.textColor,
  330. q: common_vendor.t($data.mescroll.optUp.textLoading)
  331. } : {}, {
  332. r: $data.upLoadType === 2
  333. }, $data.upLoadType === 2 ? {
  334. s: common_vendor.t($data.mescroll.optUp.textNoMore)
  335. } : {}, {
  336. t: $data.mescroll.optUp.bgColor,
  337. v: $data.mescroll.optUp.textColor
  338. }) : {}, {
  339. w: $options.translateY,
  340. x: $options.transition,
  341. y: _ctx.callProp,
  342. z: $props.safearea
  343. }, $props.safearea ? {} : {}, {
  344. A: common_vendor.o($options.toTopClick),
  345. B: common_vendor.o(($event) => $data.isShowToTop = $event),
  346. C: common_vendor.p({
  347. option: $data.mescroll.optUp.toTop,
  348. modelValue: $data.isShowToTop
  349. }),
  350. D: _ctx.renderBiz.propObserver,
  351. E: _ctx.wxsProp,
  352. F: $props.sticky ? 1 : "",
  353. G: $options.minHeight,
  354. H: $options.padTop,
  355. I: $options.padBottom,
  356. J: _ctx.wxsProp
  357. });
  358. }
  359. if (typeof block0 === "function")
  360. block0(_sfc_main);
  361. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  362. wx.createComponent(Component);